Skip to content

Commit 9fbdb97

Browse files
authoredFeb 13, 2020
Use new eslint-config-prettier override (#422)
1 parent c2bb1bf commit 9fbdb97

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
 

Diff for: ‎lib/options-manager.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ const ENGINE_RULES = {
8989
}
9090
};
9191

92+
const PRETTIER_CONFIG_OVERRIDE = {
93+
'@typescript-eslint/eslint-plugin': 'prettier/@typescript-eslint',
94+
'eslint-plugin-babel': 'prettier/babel',
95+
'eslint-plugin-flowtype': 'prettier/flowtype',
96+
'eslint-plugin-react': 'prettier/react',
97+
'eslint-plugin-standard': 'prettier/standard',
98+
'eslint-plugin-vue': 'prettier/vue'
99+
};
100+
92101
// Keep the same behaviour in mergeWith as deepAssign
93102
const mergeFn = (previousValue, value) => {
94103
if (Array.isArray(previousValue) && Array.isArray(value)) {
@@ -281,23 +290,20 @@ const buildConfig = options => {
281290

282291
// If the user sets the `prettier` options then add the `prettier` plugin and config
283292
if (options.prettier) {
284-
// Disable formatting rules conflicting with Prettier
285-
config.rules['unicorn/number-literal-case'] = 'off';
286-
// Can be re-enabled when https://github.com/prettier/prettier/issues/4157 is fixed
287-
config.rules['unicorn/no-nested-ternary'] = 'off';
288293
// The prettier plugin uses Prettier to format the code with `--fix`
289294
config.plugins = config.plugins.concat('prettier');
290295
// The prettier config overrides ESLint stylistic rules that are handled by Prettier
291296
config.baseConfig.extends = config.baseConfig.extends.concat('prettier');
297+
config.baseConfig.extends = config.baseConfig.extends.concat('prettier/unicorn');
292298
// The `prettier/prettier` rule reports errors if the code is not formatted in accordance to Prettier
293299
config.rules['prettier/prettier'] = [
294300
'error', mergeWithPrettierConfig(options, prettier.resolveConfig.sync(options.cwd || process.cwd()) || {})
295301
];
296302
// If the user has the React, Flowtype, or Standard plugin, add the corresponding Prettier rule overrides
297303
// See https://github.com/prettier/eslint-config-prettier for the list of plugins overrrides
298-
for (const override of ['react', 'flowtype', 'standard']) {
299-
if (options.cwd && resolveFrom.silent(options.cwd, `eslint-plugin-${override}`)) {
300-
config.baseConfig.extends = config.baseConfig.extends.concat(`prettier/${override}`);
304+
for (const [plugin, prettierConfig] of Object.entries(PRETTIER_CONFIG_OVERRIDE)) {
305+
if (options.cwd && resolveFrom.silent(options.cwd, plugin)) {
306+
config.baseConfig.extends = config.baseConfig.extends.concat(prettierConfig);
301307
}
302308
}
303309
}

Diff for: ‎test/options-manager.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ test('buildConfig: prettier: true', t => {
9191
trailingComma: 'none'
9292
}]);
9393
// eslint-prettier-config must always be last
94-
t.deepEqual(config.baseConfig.extends.slice(-1), ['prettier']);
94+
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'prettier/unicorn');
95+
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 2], 'prettier');
9596
// Indent rule is not enabled
9697
t.is(config.rules.indent, undefined);
9798
// Semi rule is not enabled

0 commit comments

Comments
 (0)