Skip to content

Commit 1437581

Browse files
committed
allow inline prettier config
1 parent a4c36bd commit 1437581

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ module.exports = {
4848

4949
The recommended set will apply [these rules](https://github.com/ember-template-lint/ember-template-lint-plugin-prettier/blob/v1.1.0-beta.0/lib/config/recommended.js).
5050

51+
## Configure Prettier Options
52+
53+
Prettier can be configured via [standard prettier config files](https://prettier.io/docs/en/configuration.html), or rule config options.
54+
The configuration from the rule will be merged with the rc file config, overriding existing options.
55+
e.g
56+
57+
```js
58+
module.exports = {
59+
plugins: ["ember-template-lint-plugin-prettier"],
60+
61+
extends: ["recommended", "ember-template-lint-plugin-prettier:recommended"],
62+
63+
rules: {
64+
"prettier": { singleQuote: true }
65+
}
66+
};
67+
```
68+
5169
## Tips
5270

5371
You may want to define these two scripts in your package.json:

lib/rules/prettier.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export default class Prettier extends Rule {
1919
constructor(options) {
2020
super(options);
2121
this.filePath = options.filePath;
22+
let config = options.config;
23+
if (Array.isArray(config)) {
24+
config = config[0];
25+
}
26+
this.prettierConfig = typeof config !== "object" ? {} : config;
2227
}
2328

2429
visitor() {
@@ -60,6 +65,7 @@ export default class Prettier extends Rule {
6065
{},
6166
{ parser: "glimmer" },
6267
prettierRcOptions,
68+
this.prettierConfig,
6369
{
6470
filepath,
6571
}

test/unit/rules/lint-prettier-test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ generateRuleTests({
88
groupingMethod: describe,
99
testMethod: it,
1010
plugins: [plugin],
11+
config: true,
1112

1213
good: [
1314
``,
@@ -27,7 +28,6 @@ test
2728

2829
bad: [
2930
{
30-
config: true,
3131
template: "{{#my-component}}{{/my-component}}\n",
3232
fixedTemplate: "{{#my-component}}{{/my-component}}",
3333
result: {
@@ -41,15 +41,17 @@ test
4141
},
4242
},
4343
{
44-
config: true,
44+
config: {
45+
singleQuote: true,
46+
},
4547
template: `<div data-foo
4648
data-bar="lol"
4749
some-other-thing={{haha-morethaneightychars}}>
4850
</div>`,
49-
fixedTemplate: `<div data-foo data-bar="lol" some-other-thing={{haha-morethaneightychars}}>
51+
fixedTemplate: `<div data-foo data-bar='lol' some-other-thing={{haha-morethaneightychars}}>
5052
</div>`,
5153
result: {
52-
message: 'Replace `⏎·data-bar="lol"⏎·····` with `·data-bar="lol"`',
54+
message: "Replace `⏎·data-bar=\"lol\"⏎·····` with `·data-bar='lol'`",
5355
line: 1,
5456
column: 13,
5557
endLine: 3,
@@ -62,7 +64,6 @@ test
6264
},
6365
},
6466
{
65-
config: true,
6667
template: "test\n",
6768
fixedTemplate: "test",
6869
result: {
@@ -76,7 +77,6 @@ test
7677
},
7778
},
7879
{
79-
config: true,
8080
template: `{{#my-component}}
8181
8282
test
@@ -98,7 +98,6 @@ test
9898
},
9999
},
100100
{
101-
config: true,
102101
template: `{{#my-component class="class1 class2"}}
103102
test
104103

0 commit comments

Comments
 (0)