Skip to content

Commit bff5cb8

Browse files
authored
Merge pull request #259 from patricklx/patch-2
2 parents c9e0f97 + 620d1d0 commit bff5cb8

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ 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+
## Configuration
52+
53+
Prettier can be configured via [standard prettier config files](https://prettier.io/docs/en/configuration.html).
54+
5155
## Tips
5256

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

lib/rules/prettier.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ export default class Prettier extends Rule {
2121
this.filePath = options.filePath;
2222
}
2323

24+
getPrettierOptions() {
25+
let filepath = this.filePath;
26+
27+
if (!prettier) {
28+
// Prettier is expensive to load, so only load it if needed.
29+
prettier = require("prettier");
30+
}
31+
32+
const prettierRcOptions = prettier.resolveConfig.sync(filepath, {
33+
editorconfig: true,
34+
});
35+
36+
return Object.assign({}, { parser: "glimmer" }, prettierRcOptions, {
37+
filepath,
38+
});
39+
}
40+
2441
visitor() {
2542
return {
2643
Program: {
@@ -36,35 +53,20 @@ export default class Prettier extends Rule {
3653
}
3754

3855
const source = this.sourceForNode(node);
39-
let filepath = this.filePath;
40-
41-
if (!prettier) {
42-
// Prettier is expensive to load, so only load it if needed.
43-
prettier = require("prettier");
44-
}
45-
46-
const prettierRcOptions = prettier.resolveConfig.sync(filepath, {
47-
editorconfig: true,
48-
});
56+
const prettierOptions = this.getPrettierOptions();
4957

50-
const prettierFileInfo = prettier.getFileInfo.sync(filepath, {
51-
ignorePath: ".prettierignore",
52-
});
58+
const prettierFileInfo = prettier.getFileInfo.sync(
59+
prettierOptions.filepath,
60+
{
61+
ignorePath: ".prettierignore",
62+
}
63+
);
5364

5465
// Skip if file is ignored using a .prettierignore file
5566
if (prettierFileInfo.ignored) {
5667
return;
5768
}
5869

59-
const prettierOptions = Object.assign(
60-
{},
61-
{ parser: "glimmer" },
62-
prettierRcOptions,
63-
{
64-
filepath,
65-
}
66-
);
67-
6870
let prettierSource;
6971
try {
7072
prettierSource = prettier.format(source, prettierOptions);

0 commit comments

Comments
 (0)