@w5s/eslint-config 3.0.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,189 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ export const errors = () => ({
4
+ // Enforce “for” loop update clause moving the counter in the right direction
5
+ // https://eslint.org/docs/rules/for-direction
6
+ 'for-direction': 'error',
7
+
8
+ // Enforces that a return statement is present in property getters
9
+ // https://eslint.org/docs/rules/getter-return
10
+ 'getter-return': ['error', { allowImplicit: true }],
11
+
12
+ // disallow using an async function as a Promise executor
13
+ // https://eslint.org/docs/rules/no-async-promise-executor
14
+ 'no-async-promise-executor': 'error',
15
+
16
+ // Disallow await inside of loops
17
+ // https://eslint.org/docs/rules/no-await-in-loop
18
+ 'no-await-in-loop': 'error',
19
+
20
+ // Disallow comparisons to negative zero
21
+ // https://eslint.org/docs/rules/no-compare-neg-zero
22
+ 'no-compare-neg-zero': 'error',
23
+
24
+ // disallow assignment in conditional expressions
25
+ 'no-cond-assign': ['error', 'always'],
26
+
27
+ // disallow use of console
28
+ 'no-console': 'warn',
29
+
30
+ // Disallows expressions where the operation doesn't affect the value
31
+ // https://eslint.org/docs/rules/no-constant-binary-expression
32
+ // TODO: semver-major, enable
33
+ 'no-constant-binary-expression': 'off',
34
+
35
+ // disallow use of constant expressions in conditions
36
+ 'no-constant-condition': 'warn',
37
+
38
+ // disallow control characters in regular expressions
39
+ 'no-control-regex': 'error',
40
+
41
+ // disallow use of debugger
42
+ 'no-debugger': 'error',
43
+
44
+ // disallow duplicate arguments in functions
45
+ 'no-dupe-args': 'error',
46
+
47
+ // Disallow duplicate conditions in if-else-if chains
48
+ // https://eslint.org/docs/rules/no-dupe-else-if
49
+ 'no-dupe-else-if': 'error',
50
+
51
+ // disallow duplicate keys when creating object literals
52
+ 'no-dupe-keys': 'error',
53
+
54
+ // disallow a duplicate case label.
55
+ 'no-duplicate-case': 'error',
56
+
57
+ // disallow empty statements
58
+ 'no-empty': 'error',
59
+
60
+ // disallow the use of empty character classes in regular expressions
61
+ 'no-empty-character-class': 'error',
62
+
63
+ // disallow assigning to the exception in a catch block
64
+ 'no-ex-assign': 'error',
65
+
66
+ // disallow double-negation boolean casts in a boolean context
67
+ // https://eslint.org/docs/rules/no-extra-boolean-cast
68
+ 'no-extra-boolean-cast': 'error',
69
+
70
+ // disallow unnecessary parentheses
71
+ // https://eslint.org/docs/rules/no-extra-parens
72
+ 'no-extra-parens': ['off', 'all', {
73
+ conditionalAssign: true,
74
+ nestedBinaryExpressions: false,
75
+ returnAssign: false,
76
+ ignoreJSX: 'all', // delegate to eslint-plugin-react
77
+ enforceForArrowConditionals: false,
78
+ }],
79
+
80
+ // disallow unnecessary semicolons
81
+ 'no-extra-semi': 'error',
82
+
83
+ // disallow overwriting functions written as function declarations
84
+ 'no-func-assign': 'error',
85
+
86
+ // https://eslint.org/docs/rules/no-import-assign
87
+ 'no-import-assign': 'error',
88
+
89
+ // disallow function or variable declarations in nested blocks
90
+ 'no-inner-declarations': 'error',
91
+
92
+ // disallow invalid regular expression strings in the RegExp constructor
93
+ 'no-invalid-regexp': 'error',
94
+
95
+ // disallow irregular whitespace outside of strings and comments
96
+ 'no-irregular-whitespace': 'error',
97
+
98
+ // Disallow Number Literals That Lose Precision
99
+ // https://eslint.org/docs/rules/no-loss-of-precision
100
+ 'no-loss-of-precision': 'error',
101
+
102
+ // Disallow characters which are made with multiple code points in character class syntax
103
+ // https://eslint.org/docs/rules/no-misleading-character-class
104
+ 'no-misleading-character-class': 'error',
105
+
106
+ // disallow the use of object properties of the global object (Math and JSON) as functions
107
+ 'no-obj-calls': 'error',
108
+
109
+ // Disallow new operators with global non-constructor functions
110
+ // https://eslint.org/docs/latest/rules/no-new-native-nonconstructor
111
+ // TODO: semver-major, enable
112
+ 'no-new-native-nonconstructor': 'off',
113
+
114
+ // Disallow returning values from Promise executor functions
115
+ // https://eslint.org/docs/rules/no-promise-executor-return
116
+ 'no-promise-executor-return': 'error',
117
+
118
+ // disallow use of Object.prototypes builtins directly
119
+ // https://eslint.org/docs/rules/no-prototype-builtins
120
+ 'no-prototype-builtins': 'error',
121
+
122
+ // disallow multiple spaces in a regular expression literal
123
+ 'no-regex-spaces': 'error',
124
+
125
+ // Disallow returning values from setters
126
+ // https://eslint.org/docs/rules/no-setter-return
127
+ 'no-setter-return': 'error',
128
+
129
+ // disallow sparse arrays
130
+ 'no-sparse-arrays': 'error',
131
+
132
+ // Disallow template literal placeholder syntax in regular strings
133
+ // https://eslint.org/docs/rules/no-template-curly-in-string
134
+ 'no-template-curly-in-string': 'error',
135
+
136
+ // Avoid code that looks like two expressions but is actually one
137
+ // https://eslint.org/docs/rules/no-unexpected-multiline
138
+ 'no-unexpected-multiline': 'error',
139
+
140
+ // disallow unreachable statements after a return, throw, continue, or break statement
141
+ 'no-unreachable': 'error',
142
+
143
+ // Disallow loops with a body that allows only one iteration
144
+ // https://eslint.org/docs/rules/no-unreachable-loop
145
+ 'no-unreachable-loop': ['error', {
146
+ ignore: [], // WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement
147
+ }],
148
+
149
+ // disallow return/throw/break/continue inside finally blocks
150
+ // https://eslint.org/docs/rules/no-unsafe-finally
151
+ 'no-unsafe-finally': 'error',
152
+
153
+ // disallow negating the left operand of relational operators
154
+ // https://eslint.org/docs/rules/no-unsafe-negation
155
+ 'no-unsafe-negation': 'error',
156
+
157
+ // disallow use of optional chaining in contexts where the undefined value is not allowed
158
+ // https://eslint.org/docs/rules/no-unsafe-optional-chaining
159
+ 'no-unsafe-optional-chaining': ['error', { disallowArithmeticOperators: true }],
160
+
161
+ // Disallow Unused Private Class Members
162
+ // https://eslint.org/docs/rules/no-unused-private-class-members
163
+ // TODO: enable once eslint 7 is dropped (which is semver-major)
164
+ 'no-unused-private-class-members': 'off',
165
+
166
+ // Disallow useless backreferences in regular expressions
167
+ // https://eslint.org/docs/rules/no-useless-backreference
168
+ 'no-useless-backreference': 'error',
169
+
170
+ // disallow negation of the left operand of an in expression
171
+ // deprecated in favor of no-unsafe-negation
172
+ 'no-negated-in-lhs': 'off',
173
+
174
+ // Disallow assignments that can lead to race conditions due to usage of await or yield
175
+ // https://eslint.org/docs/rules/require-atomic-updates
176
+ // note: not enabled because it is very buggy
177
+ 'require-atomic-updates': 'off',
178
+
179
+ // disallow comparisons with the value NaN
180
+ 'use-isnan': 'error',
181
+
182
+ // ensure JSDoc comments are valid
183
+ // https://eslint.org/docs/rules/valid-jsdoc
184
+ 'valid-jsdoc': 'off',
185
+
186
+ // ensure that the results of typeof are compared against a valid string
187
+ // https://eslint.org/docs/rules/valid-typeof
188
+ 'valid-typeof': ['error', { requireStringLiterals: true }],
189
+ } satisfies Linter.RulesRecord);
@@ -0,0 +1,173 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ export const es6 = () => ({
4
+ // enforces no braces where they can be omitted
5
+ // https://eslint.org/docs/rules/arrow-body-style
6
+ // TODO: enable requireReturnForObjectLiteral?
7
+ 'arrow-body-style': ['error', 'as-needed', {
8
+ requireReturnForObjectLiteral: false,
9
+ }],
10
+
11
+ // require parens in arrow function arguments
12
+ // https://eslint.org/docs/rules/arrow-parens
13
+ 'arrow-parens': ['error', 'always'],
14
+
15
+ // require space before/after arrow function's arrow
16
+ // https://eslint.org/docs/rules/arrow-spacing
17
+ 'arrow-spacing': ['error', { before: true, after: true }],
18
+
19
+ // verify super() callings in constructors
20
+ 'constructor-super': 'error',
21
+
22
+ // enforce the spacing around the * in generator functions
23
+ // https://eslint.org/docs/rules/generator-star-spacing
24
+ 'generator-star-spacing': ['error', { before: false, after: true }],
25
+
26
+ // disallow modifying variables of class declarations
27
+ // https://eslint.org/docs/rules/no-class-assign
28
+ 'no-class-assign': 'error',
29
+
30
+ // disallow arrow functions where they could be confused with comparisons
31
+ // https://eslint.org/docs/rules/no-confusing-arrow
32
+ 'no-confusing-arrow': ['error', {
33
+ allowParens: true,
34
+ }],
35
+
36
+ // disallow modifying variables that are declared using const
37
+ 'no-const-assign': 'error',
38
+
39
+ // disallow duplicate class members
40
+ // https://eslint.org/docs/rules/no-dupe-class-members
41
+ 'no-dupe-class-members': 'error',
42
+
43
+ // disallow importing from the same path more than once
44
+ // https://eslint.org/docs/rules/no-duplicate-imports
45
+ // replaced by https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
46
+ 'no-duplicate-imports': 'off',
47
+
48
+ // disallow symbol constructor
49
+ // https://eslint.org/docs/rules/no-new-symbol
50
+ 'no-new-symbol': 'error',
51
+
52
+ // Disallow specified names in exports
53
+ // https://eslint.org/docs/rules/no-restricted-exports
54
+ 'no-restricted-exports': ['error', {
55
+ restrictedNamedExports: [
56
+ 'default', // use `export default` to provide a default export
57
+ 'then', // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions
58
+ ],
59
+ }],
60
+
61
+ // disallow specific imports
62
+ // https://eslint.org/docs/rules/no-restricted-imports
63
+ 'no-restricted-imports': ['off', {
64
+ paths: [],
65
+ patterns: [],
66
+ }],
67
+
68
+ // disallow to use this/super before super() calling in constructors.
69
+ // https://eslint.org/docs/rules/no-this-before-super
70
+ 'no-this-before-super': 'error',
71
+
72
+ // disallow useless computed property keys
73
+ // https://eslint.org/docs/rules/no-useless-computed-key
74
+ 'no-useless-computed-key': 'error',
75
+
76
+ // disallow unnecessary constructor
77
+ // https://eslint.org/docs/rules/no-useless-constructor
78
+ 'no-useless-constructor': 'error',
79
+
80
+ // disallow renaming import, export, and destructured assignments to the same name
81
+ // https://eslint.org/docs/rules/no-useless-rename
82
+ 'no-useless-rename': ['error', {
83
+ ignoreDestructuring: false,
84
+ ignoreImport: false,
85
+ ignoreExport: false,
86
+ }],
87
+
88
+ // require let or const instead of var
89
+ 'no-var': 'error',
90
+
91
+ // require method and property shorthand syntax for object literals
92
+ // https://eslint.org/docs/rules/object-shorthand
93
+ 'object-shorthand': ['error', 'always', {
94
+ ignoreConstructors: false,
95
+ avoidQuotes: true,
96
+ }],
97
+
98
+ // suggest using arrow functions as callbacks
99
+ 'prefer-arrow-callback': ['error', {
100
+ allowNamedFunctions: false,
101
+ allowUnboundThis: true,
102
+ }],
103
+
104
+ // suggest using of const declaration for variables that are never modified after declared
105
+ 'prefer-const': ['error', {
106
+ destructuring: 'any',
107
+ ignoreReadBeforeAssign: true,
108
+ }],
109
+
110
+ // Prefer destructuring from arrays and objects
111
+ // https://eslint.org/docs/rules/prefer-destructuring
112
+ 'prefer-destructuring': ['error', {
113
+ VariableDeclarator: {
114
+ array: false,
115
+ object: true,
116
+ },
117
+ AssignmentExpression: {
118
+ array: true,
119
+ object: false,
120
+ },
121
+ }, {
122
+ enforceForRenamedProperties: false,
123
+ }],
124
+
125
+ // disallow parseInt() in favor of binary, octal, and hexadecimal literals
126
+ // https://eslint.org/docs/rules/prefer-numeric-literals
127
+ 'prefer-numeric-literals': 'error',
128
+
129
+ // suggest using Reflect methods where applicable
130
+ // https://eslint.org/docs/rules/prefer-reflect
131
+ 'prefer-reflect': 'off',
132
+
133
+ // use rest parameters instead of arguments
134
+ // https://eslint.org/docs/rules/prefer-rest-params
135
+ 'prefer-rest-params': 'error',
136
+
137
+ // suggest using the spread syntax instead of .apply()
138
+ // https://eslint.org/docs/rules/prefer-spread
139
+ 'prefer-spread': 'error',
140
+
141
+ // suggest using template literals instead of string concatenation
142
+ // https://eslint.org/docs/rules/prefer-template
143
+ 'prefer-template': 'error',
144
+
145
+ // disallow generator functions that do not have yield
146
+ // https://eslint.org/docs/rules/require-yield
147
+ 'require-yield': 'error',
148
+
149
+ // enforce spacing between object rest-spread
150
+ // https://eslint.org/docs/rules/rest-spread-spacing
151
+ 'rest-spread-spacing': ['error', 'never'],
152
+
153
+ // import sorting
154
+ // https://eslint.org/docs/rules/sort-imports
155
+ 'sort-imports': ['off', {
156
+ ignoreCase: false,
157
+ ignoreDeclarationSort: false,
158
+ ignoreMemberSort: false,
159
+ memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
160
+ }],
161
+
162
+ // require a Symbol description
163
+ // https://eslint.org/docs/rules/symbol-description
164
+ 'symbol-description': 'error',
165
+
166
+ // enforce usage of spacing in template strings
167
+ // https://eslint.org/docs/rules/template-curly-spacing
168
+ 'template-curly-spacing': 'error',
169
+
170
+ // enforce spacing around the * in yield* expressions
171
+ // https://eslint.org/docs/rules/yield-star-spacing
172
+ 'yield-star-spacing': ['error', 'after'],
173
+ } satisfies Linter.RulesRecord);
@@ -0,0 +1,28 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ export const overrides = () => ({
4
+ // Too many errors in components
5
+ 'class-methods-use-this': 'off',
6
+ // Annoying because it is not always wanted
7
+ 'default-case': 'off',
8
+ // We do not want console.* in production. Disable this rule on a per line basis if needed
9
+ 'no-console': 'error',
10
+ // Often useful in jsx
11
+ 'no-nested-ternary': 'off',
12
+ // Too strict, for pure code prefer the functional plugin
13
+ 'no-param-reassign': ['error', { props: false }],
14
+ // Allow for-of syntax
15
+ // 'no-restricted-syntax': baseConfig.rules['no-restricted-syntax'].filter(
16
+ // // @ts-ignore No typing available
17
+ // ({ selector }) => selector !== 'ForOfStatement',
18
+ // ),
19
+ // underscore is often used (mongodb, etc)
20
+ 'no-underscore-dangle': 'off',
21
+ // Ignore underscore case arguments
22
+ 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
23
+ // Allow in some cases https://github.com/airbnb/javascript/issues/1089#issuecomment-1024351821
24
+ 'no-use-before-define': ['error', 'nofunc'],
25
+ // Allow statements, to be compatible with '@typescript-eslint/no-floating-promises' fix
26
+ 'no-void': ['error', { allowAsStatement: true }],
27
+ 'unicode-bom': ['error', 'never'],
28
+ } satisfies Linter.RulesRecord);
@@ -0,0 +1,6 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ export const strict = () => ({
4
+ // babel inserts `'use strict';` for us
5
+ strict: ['error', 'never'],
6
+ } satisfies Linter.RulesRecord);
@@ -0,0 +1,58 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ export const variables = () => ({
4
+ // enforce or disallow variable initializations at definition
5
+ 'init-declarations': 'off',
6
+
7
+ // disallow the catch clause parameter name being the same as a variable in the outer scope
8
+ 'no-catch-shadow': 'off',
9
+
10
+ // disallow deletion of variables
11
+ 'no-delete-var': 'error',
12
+
13
+ // disallow labels that share a name with a variable
14
+ // https://eslint.org/docs/rules/no-label-var
15
+ 'no-label-var': 'error',
16
+
17
+ // disallow specific globals
18
+ 'no-restricted-globals': [
19
+ 'error',
20
+ {
21
+ name: 'isFinite',
22
+ message:
23
+ 'Use Number.isFinite instead https://github.com/airbnb/javascript#standard-library--isfinite',
24
+ },
25
+ {
26
+ name: 'isNaN',
27
+ message:
28
+ 'Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan',
29
+ },
30
+ // ...confusingBrowserGlobals.map((g) => ({
31
+ // name: g,
32
+ // message: `Use window.${g} instead. https://github.com/facebook/create-react-app/blob/HEAD/packages/confusing-browser-globals/README.md`,
33
+ // })),
34
+ ],
35
+
36
+ // disallow declaration of variables already declared in the outer scope
37
+ 'no-shadow': 'error',
38
+
39
+ // disallow shadowing of names such as arguments
40
+ 'no-shadow-restricted-names': 'error',
41
+
42
+ // disallow use of undeclared variables unless mentioned in a /*global */ block
43
+ 'no-undef': 'error',
44
+
45
+ // disallow use of undefined when initializing variables
46
+ 'no-undef-init': 'error',
47
+
48
+ // disallow use of undefined variable
49
+ // https://eslint.org/docs/rules/no-undefined
50
+ // TODO: enable?
51
+ 'no-undefined': 'off',
52
+
53
+ // disallow declaration of variables that are not used in the code
54
+ 'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],
55
+
56
+ // disallow use of variables before they are defined
57
+ 'no-use-before-define': ['error', { functions: true, classes: true, variables: true }],
58
+ } satisfies Linter.RulesRecord);
@@ -0,0 +1,17 @@
1
+ import { bestPractices } from './esRules/bestPractices.js';
2
+ import { errors } from './esRules/errors.js';
3
+ import { es6 } from './esRules/es6.js';
4
+ import { overrides } from './esRules/overrides.js';
5
+ import { strict } from './esRules/strict.js';
6
+ import { variables } from './esRules/variables.js';
7
+
8
+ export const esRules = () => ({
9
+ ...bestPractices(),
10
+ ...errors(),
11
+ ...es6(),
12
+ ...strict(),
13
+ ...variables(),
14
+
15
+ // Must be last
16
+ ...overrides(),
17
+ });
@@ -1,4 +1,3 @@
1
- /* eslint-disable unicorn/no-abusive-eslint-disable */
2
1
  /* eslint-disable */
3
2
  /* prettier-ignore */
4
3
  import type { Linter } from 'eslint'
@@ -1,4 +1,3 @@
1
- /* eslint-disable unicorn/no-abusive-eslint-disable */
2
1
  /* eslint-disable */
3
2
  /* prettier-ignore */
4
3
  import type { Linter } from 'eslint'
@@ -1,4 +1,3 @@
1
- /* eslint-disable unicorn/no-abusive-eslint-disable */
2
1
  /* eslint-disable */
3
2
  /* prettier-ignore */
4
3
  import type { Linter } from 'eslint'
@@ -1,4 +1,3 @@
1
- /* eslint-disable unicorn/no-abusive-eslint-disable */
2
1
  /* eslint-disable */
3
2
  /* prettier-ignore */
4
3
  import type { Linter } from 'eslint'