Skip to content

Commit

Permalink
feat: Turn off the prettier/prettier rule if found
Browse files Browse the repository at this point in the history
We already run prettier, so there's no need for eslint-plugin-prettier to run.
  • Loading branch information
zimme committed Jan 18, 2018
1 parent b3d02da commit 17f30b4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,29 @@ test("eslint max-len.tabWidth value should be used for tabWidth when tabs are us
});
});

test("Turn off prettier/prettier rule if found, but still infer options from it", () => {
const { eslint, prettier } = getOptionsForFormatting({
rules: {
"prettier/prettier": [
2,
{
trailingComma: "all"
}
]
}
});

expect(eslint).toMatchObject({
rules: {
"prettier/prettier": ["off"]
}
});

expect(prettier).toMatchObject({
trailingComma: "all"
});
});

test("eslint config has only necessary properties", () => {
const { eslint } = getOptionsForFormatting({
globals: ["window:false"],
Expand Down
12 changes: 11 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,22 @@ function getOptionsForFormatting(
prettierOptions = {},
fallbackPrettierOptions = {}
) {
const eslint = getRelevantESLintConfig(eslintConfig);
let eslint = getRelevantESLintConfig(eslintConfig);
const prettier = getPrettierOptionsFromESLintRules(
eslintConfig,
prettierOptions,
fallbackPrettierOptions
);

// Disable "prettier/prettier", we don't need to run prettier twice
eslint = {
...eslint,
rules: {
...eslint.rules,
"prettier/prettier": ["off"]
}
};

return { eslint, prettier };
}

Expand Down

0 comments on commit 17f30b4

Please sign in to comment.