Skip to content

Commit 5b0cc19

Browse files
authored
move prettier options to function
1 parent 0522f01 commit 5b0cc19

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

lib/rules/prettier.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,28 @@ 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];
22+
}
23+
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");
2530
}
26-
this.prettierConfig = typeof config !== "object" ? {} : config;
31+
32+
const prettierRcOptions = prettier.resolveConfig.sync(filepath, {
33+
editorconfig: true,
34+
});
35+
36+
return Object.assign(
37+
{},
38+
{ parser: "glimmer" },
39+
prettierRcOptions,
40+
{
41+
filepath,
42+
}
43+
);
2744
}
2845

2946
visitor() {
@@ -40,37 +57,19 @@ export default class Prettier extends Rule {
4057
prettier.clearConfigCache();
4158
}
4259

43-
const source = this.sourceForNode(node);
44-
let filepath = this.filePath;
45-
46-
if (!prettier) {
47-
// Prettier is expensive to load, so only load it if needed.
48-
prettier = require("prettier");
60+
const source = this.sourceForNode(node);
61+
62+
// Skip if file is ignored using a .prettierignore file
63+
if (prettierFileInfo.ignored) {
64+
return;
4965
}
5066

51-
const prettierRcOptions = prettier.resolveConfig.sync(filepath, {
52-
editorconfig: true,
53-
});
67+
const prettierOptions = this.getPrettierOptions();
5468

5569
const prettierFileInfo = prettier.getFileInfo.sync(filepath, {
5670
ignorePath: ".prettierignore",
5771
});
5872

59-
// Skip if file is ignored using a .prettierignore file
60-
if (prettierFileInfo.ignored) {
61-
return;
62-
}
63-
64-
const prettierOptions = Object.assign(
65-
{},
66-
{ parser: "glimmer" },
67-
prettierRcOptions,
68-
this.prettierConfig,
69-
{
70-
filepath,
71-
}
72-
);
73-
7473
let prettierSource;
7574
try {
7675
prettierSource = prettier.format(source, prettierOptions);

0 commit comments

Comments
 (0)