-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
recommended.js
76 lines (69 loc) · 2.34 KB
/
recommended.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* External dependencies
*/
const { cosmiconfigSync } = require( 'cosmiconfig' );
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const { isPackageInstalled } = require( '../utils' );
const config = {
extends: [ require.resolve( './recommended-with-formatting.js' ) ],
};
if ( isPackageInstalled( 'prettier' ) ) {
config.extends.push( 'plugin:prettier/recommended' );
const { config: localPrettierConfig } =
cosmiconfigSync( 'prettier' ).search() || {};
const defaultPrettierConfig = require( '@wordpress/prettier-config' );
const prettierConfig = { ...defaultPrettierConfig, ...localPrettierConfig };
config.rules = {
'prettier/prettier': [ 'error', prettierConfig ],
// Prettier _disables_ this rule, but we want it!
// See https://github.com/prettier/eslint-config-prettier?tab=readme-ov-file#curly
// > This rule requires certain options.
// > …
// > If you like this rule, it can be used just fine with Prettier as long as you don’t use the "multi-line" or "multi-or-nest" option.
curly: [ 'error', 'all' ],
};
}
if ( isPackageInstalled( 'typescript' ) ) {
config.settings = {
'import/resolver': {
node: {
extensions: [ '.js', '.jsx', '.ts', '.tsx' ],
},
},
};
config.extends.push( 'plugin:@typescript-eslint/eslint-recommended' );
config.ignorePatterns = [ '**/*.d.ts' ];
config.plugins = [ '@typescript-eslint' ];
config.overrides = [
{
files: [ '**/*.ts', '**/*.tsx' ],
parser: '@typescript-eslint/parser',
rules: {
'no-duplicate-imports': 'off',
'import/no-duplicates': 'error',
// Don't require redundant JSDoc types in TypeScript files.
'jsdoc/require-param-type': 'off',
'jsdoc/require-returns-type': 'off',
// Use eslint for unused variable and parameter detection.
// This overlaps with TypeScript noUnusedLocals and noUnusedParameters settings.
// TypeScript may only run on a subset of files. Prefer eslint which is more
// likely to run on the entire codebase.
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ ignoreRestSiblings: true },
],
// no-shadow doesn't work correctly in TS, so let's use a TS-dedicated version instead.
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/method-signature-style': 'error',
},
},
];
}
module.exports = config;