@kununu/eslint-config 2.1.0 → 2.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.
Files changed (2) hide show
  1. package/index.js +225 -153
  2. package/package.json +8 -3
package/index.js CHANGED
@@ -1,6 +1,172 @@
1
+ // we need to have the baseRules to have the same on the typescript override
2
+ // because it has extends the eslint does not take into consideration the ones from the base
3
+ const baseRules = {
4
+ 'import/no-extraneous-dependencies': ['error', {
5
+ devDependencies: [
6
+ '**/*.test.js',
7
+ '**/*.test.jsx',
8
+ '**/*.spec.js',
9
+ '**/*.spec.jsx',
10
+ '*/test-*/*.js',
11
+ '*/test-*/*.jsx',
12
+ 'config/**/*.js',
13
+ 'next.config.js',
14
+ 'jestsetup.js',
15
+ 'mockBff/*'
16
+ ],
17
+ }],
18
+ 'max-len': 'off', // Sometimes longer lines are more readable (Airbnb rule change)
19
+ 'no-param-reassign': ['error', {props: false}],
20
+ 'no-prototype-builtins': 'off', // Objects aren't created that don't extend from Object.prototype (Airbnb rule change)
21
+ 'object-curly-spacing': 'off', // Disabled in favor of @babel/object-curly-spacing in order to avoid false positives with ECMAScript modules (Airbnb rule change)
22
+ 'space-before-function-paren': ['error', {
23
+ anonymous: 'always', // const foo = function () {}
24
+ named: 'always', // function foo () {} (Airbnb rule change)
25
+ asyncArrow: 'always', // const foo = async (a) => await a
26
+ }],
27
+
28
+ // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
29
+ 'react/no-direct-mutation-state': 'error', // Use .setState() always (Airbnb rule change)
30
+
31
+ // https://github.com/babel/babel/tree/main/eslint/babel-eslint-plugin#rules
32
+ '@babel/object-curly-spacing': 'error', // No spaces in single-line objects to make nested objects like {a: {b: 'c'}} look more sane (Airbnb rule change)
33
+
34
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/
35
+ 'import/order': ['error', { // Make import sort order an error (Airbnb rule change)
36
+ 'newlines-between': 'always',
37
+ groups: [
38
+ 'builtin', // import fs from 'fs';
39
+ 'external', // import chalk from 'chalk';
40
+ 'internal', // import foo from 'src/foo';
41
+ 'parent', // import qux from '../qux';
42
+ 'sibling', // import bar from './bar';
43
+ 'index', // import main from './';
44
+ ],
45
+ }],
46
+
47
+ 'import/no-useless-path-segments': ['error', {
48
+ 'noUselessIndex': true,
49
+ }],
50
+
51
+ // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md#rule-details
52
+ // allow `Link` to have `to` and not the mandatory `href`
53
+ 'jsx-a11y/anchor-is-valid': ['error', {
54
+ components: ['Link'],
55
+ specialLink: ['to'],
56
+ }],
57
+
58
+ // https://eslint.org/docs/rules/operator-linebreak
59
+ 'operator-linebreak': ['error', 'after'],
60
+
61
+ // https://eslint.org/docs/rules/no-confusing-arrow
62
+ // turn off to prevent conflict with
63
+ // https://eslint.org/docs/rules/arrow-body-style
64
+ 'no-confusing-arrow': 'off',
65
+
66
+ // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md
67
+ // 'label' tags need 'htmlFor' prop, but nesting is not required
68
+ 'jsx-a11y/label-has-for': ['error', {
69
+ 'required': 'id',
70
+ }],
71
+
72
+ // https://eslint.org/docs/rules/padding-line-between-statements
73
+ // enforce empty lines after variable declarations
74
+ 'padding-line-between-statements': ['error', {
75
+ 'blankLine': 'always', 'prev': ['const', 'let', 'var'], 'next': '*',
76
+ }, {
77
+ 'blankLine': 'any', 'prev': ['const', 'let', 'var'], 'next': ['const', 'let', 'var'],
78
+ }],
79
+
80
+ // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
81
+ // jsx props should be on separate lines each
82
+ 'react/jsx-max-props-per-line': ['error', {'maximum': 1}],
83
+
84
+ // https://www.npmjs.com/package/eslint-plugin-react-hooks
85
+ // enforces the rules of react-hooks (call at top level and only from functional components; checks dependencies)
86
+ 'react-hooks/rules-of-hooks': 'error',
87
+ 'react-hooks/exhaustive-deps': 'warn',
88
+
89
+ // https://eslint.org/docs/rules/no-underscore-dangle
90
+ // no underscores at either the beginning or end of an identifier
91
+ 'no-underscore-dangle': ['error', {'allow': ['__NEXT_DATA__', '__NEXT_REDUX_STORE__']}],
92
+
93
+ 'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 1 }],
94
+
95
+ // https://eslint.org/docs/rules/eol-last
96
+ // require newline at the end of files
97
+ 'eol-last': ['error', 'always'],
98
+
99
+ // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-default-props.md
100
+ // enforce defaultProps declarations alphabetical sorting
101
+ 'react/jsx-sort-default-props': ['error', {
102
+ 'ignoreCase': true
103
+ }],
104
+
105
+ // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
106
+ // enforce props alphabetical sorting
107
+ 'react/jsx-sort-props': ['error', {
108
+ 'ignoreCase': true
109
+ }],
110
+
111
+ // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md
112
+ // enforce propTypes declarations alphabetical sorting
113
+ 'react/sort-prop-types': ['error', {
114
+ 'ignoreCase': true
115
+ }],
116
+
117
+ // https://eslint.org/docs/rules/sort-keys
118
+ // require object keys to be sorted
119
+ 'sort-keys': ['error', 'asc', {'caseSensitive': false, 'natural': false}],
120
+
121
+ // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/static-property-placement.md
122
+ // enforces where React component static properties should be positioned
123
+ 'react/static-property-placement': ['error', 'property assignment'],
124
+
125
+ // https://eslint.org/docs/rules/indent
126
+ // enforces a consistent 2 spaces indentation style
127
+ 'indent': ['error', 2, {
128
+ 'SwitchCase': 1
129
+ }],
130
+
131
+ // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/state-in-constructor.md
132
+ // enforces the state initialization style to be either in a constructor or with a class property
133
+ 'react/state-in-constructor': 'off',
134
+
135
+ // https://eslint.org/docs/rules/arrow-parens
136
+ // enforces no braces where they can be omitted
137
+ 'arrow-parens': ['error', 'as-needed'],
138
+
139
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
140
+ 'import/extensions': ['error', 'ignorePackages', {
141
+ 'js': 'never',
142
+ 'jsx': 'never',
143
+ 'ts': 'never',
144
+ 'tsx': 'never',
145
+ 'scss': 'ignorePackages',
146
+ 'json': 'always'
147
+ }],
148
+
149
+ // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md
150
+ // disallow spread on html tags directly but allows it on React components
151
+ 'react/jsx-props-no-spreading': ['error', {
152
+ 'html': 'enforce',
153
+ 'custom': 'ignore',
154
+ }],
155
+
156
+ // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
157
+ 'react/function-component-definition': 'off',
158
+ 'prefer-promise-reject-errors': 'off',
159
+ 'react-hooks/exhaustive-deps': 'off',
160
+ 'no-restricted-exports' : 'off',
161
+
162
+ 'testing-library/prefer-screen-queries': 'off',
163
+ 'testing-library/render-result-naming-convention': 'off',
164
+ };
165
+
1
166
  module.exports = {
2
167
  extends: [
3
168
  'airbnb', // Many strict rules for ECMAScript and React
169
+ 'airbnb/hooks',
4
170
  'plugin:jest-dom/recommended',
5
171
  'plugin:testing-library/react'
6
172
  ],
@@ -15,170 +181,76 @@ module.exports = {
15
181
  env: {
16
182
  browser: true,
17
183
  jest: true,
184
+ node: true,
185
+ es6: true,
18
186
  },
19
187
 
20
188
  settings: {
21
189
  'import/resolver': {
22
- node: { paths: (process.env.NODE_PATH || "").split(":").filter(String) } // If ENV['NODE_PATH'] was provided we want to use it with eslint too
190
+ node: { paths: (process.env.NODE_PATH || '').split(':').filter(String) } // If ENV['NODE_PATH'] was provided we want to use it with eslint too
23
191
  }
24
192
  },
25
193
 
26
- rules: {
27
- 'import/no-extraneous-dependencies': ['error', {
28
- devDependencies: [
29
- '**/*.test.js',
30
- '**/*.test.jsx',
31
- '**/*.spec.js',
32
- '**/*.spec.jsx',
33
- '*/test-*/*.js',
34
- '*/test-*/*.jsx',
35
- ],
36
- }],
37
- 'max-len': 'off', // Sometimes longer lines are more readable (Airbnb rule change)
38
- 'no-param-reassign': ['error', {props: false}],
39
- 'no-prototype-builtins': 'off', // Objects aren't created that don't extend from Object.prototype (Airbnb rule change)
40
- 'object-curly-spacing': 'off', // Disabled in favor of @babel/object-curly-spacing in order to avoid false positives with ECMAScript modules (Airbnb rule change)
41
- 'space-before-function-paren': ['error', {
42
- anonymous: 'always', // const foo = function () {}
43
- named: 'always', // function foo () {} (Airbnb rule change)
44
- asyncArrow: 'always', // const foo = async (a) => await a
45
- }],
46
-
47
- // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
48
- 'react/no-direct-mutation-state': 'error', // Use .setState() always (Airbnb rule change)
49
-
50
- // https://github.com/babel/babel/tree/main/eslint/babel-eslint-plugin#rules
51
- '@babel/object-curly-spacing': 'error', // No spaces in single-line objects to make nested objects like {a: {b: 'c'}} look more sane (Airbnb rule change)
52
-
53
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/
54
- 'import/order': ['error', { // Make import sort order an error (Airbnb rule change)
55
- 'newlines-between': 'always',
56
- groups: [
57
- 'builtin', // import fs from 'fs';
58
- 'external', // import chalk from 'chalk';
59
- 'internal', // import foo from 'src/foo';
60
- 'parent', // import qux from '../qux';
61
- 'sibling', // import bar from './bar';
62
- 'index', // import main from './';
63
- ],
64
- }],
65
-
66
- 'import/no-useless-path-segments': ['error', {
67
- 'noUselessIndex': true,
68
- }],
69
-
70
- // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md#rule-details
71
- // allow `Link` to have `to` and not the mandatory `href`
72
- 'jsx-a11y/anchor-is-valid': ['error', {
73
- components: ['Link'],
74
- specialLink: ['to'],
75
- }],
76
-
77
- // https://eslint.org/docs/rules/operator-linebreak
78
- 'operator-linebreak': ['error', 'after'],
79
-
80
- // https://eslint.org/docs/rules/no-confusing-arrow
81
- // turn off to prevent conflict with
82
- // https://eslint.org/docs/rules/arrow-body-style
83
- 'no-confusing-arrow': 'off',
84
-
85
- // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md
86
- // 'label' tags need 'htmlFor' prop, but nesting is not required
87
- 'jsx-a11y/label-has-for': ['error', {
88
- 'required': 'id',
89
- }],
90
-
91
- // https://eslint.org/docs/rules/padding-line-between-statements
92
- // enforce empty lines after variable declarations
93
- 'padding-line-between-statements': ['error', {
94
- 'blankLine': 'always', 'prev': ['const', 'let', 'var'], 'next': '*',
95
- }, {
96
- 'blankLine': 'any', 'prev': ['const', 'let', 'var'], 'next': ['const', 'let', 'var'],
97
- }],
98
-
99
- // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
100
- // jsx props should be on separate lines each
101
- 'react/jsx-max-props-per-line': ['error', {'maximum': 1}],
102
-
103
- // https://www.npmjs.com/package/eslint-plugin-react-hooks
104
- // enforces the rules of react-hooks (call at top level and only from functional components; checks dependencies)
105
- 'react-hooks/rules-of-hooks': 'error',
106
- 'react-hooks/exhaustive-deps': 'warn',
107
-
108
- // https://eslint.org/docs/rules/no-underscore-dangle
109
- // no underscores at either the beginning or end of an identifier
110
- 'no-underscore-dangle': ['error', {'allow': ['__NEXT_DATA__', '__NEXT_REDUX_STORE__']}],
111
-
112
- 'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 1 }],
113
-
114
- // https://eslint.org/docs/rules/eol-last
115
- // require newline at the end of files
116
- 'eol-last': ['error', 'always'],
117
-
118
- // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-default-props.md
119
- // enforce defaultProps declarations alphabetical sorting
120
- 'react/jsx-sort-default-props': ['error', {
121
- 'ignoreCase': true
122
- }],
123
-
124
- // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
125
- // enforce props alphabetical sorting
126
- 'react/jsx-sort-props': ['error', {
127
- 'ignoreCase': true
128
- }],
129
-
130
- // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md
131
- // enforce propTypes declarations alphabetical sorting
132
- 'react/sort-prop-types': ['error', {
133
- 'ignoreCase': true
134
- }],
135
-
136
- // https://eslint.org/docs/rules/sort-keys
137
- // require object keys to be sorted
138
- 'sort-keys': ['error', 'asc', {'caseSensitive': false, 'natural': false}],
139
-
140
- // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/static-property-placement.md
141
- // enforces where React component static properties should be positioned
142
- 'react/static-property-placement': ['error', 'property assignment'],
143
-
144
- // https://eslint.org/docs/rules/indent
145
- // enforces a consistent 2 spaces indentation style
146
- 'indent': ['error', 2, {
147
- 'SwitchCase': 1
148
- }],
149
-
150
- // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/state-in-constructor.md
151
- // enforces the state initialization style to be either in a constructor or with a class property
152
- 'react/state-in-constructor': 'off',
153
-
154
- // https://eslint.org/docs/rules/arrow-parens
155
- // enforces no braces where they can be omitted
156
- 'arrow-parens': ['error', 'as-needed'],
157
-
158
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
159
- 'import/extensions': ['error', 'ignorePackages', {
160
- 'js': 'never',
161
- 'jsx': 'never',
162
- 'scss': 'ignorePackages'
163
- }],
164
-
165
- // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md
166
- // disallow spread on html tags directly but allows it on React components
167
- 'react/jsx-props-no-spreading': ['error', {
168
- 'html': 'enforce',
169
- 'custom': 'ignore',
170
- }],
171
-
172
- 'react/function-component-definition': 0,
173
- 'testing-library/prefer-screen-queries': 0,
174
- 'testing-library/render-result-naming-convention': 0
175
- },
194
+ rules: baseRules,
176
195
 
177
196
  overrides: [{
178
- files: ['*.spec.js', '*.test.js', '*spec.jsx'],
197
+ files: [
198
+ '**/*.ts',
199
+ '**/*.tsx',
200
+ ],
201
+ extends: [
202
+ 'airbnb', // Many strict rules for ECMAScript and React
203
+ 'airbnb-typescript',
204
+ 'airbnb/hooks',
205
+ 'plugin:jest-dom/recommended',
206
+ 'plugin:testing-library/react',
207
+ ],
208
+ parser: '@typescript-eslint/parser',
209
+ plugins: [
210
+ 'react-hooks',
211
+ '@typescript-eslint',
212
+ ],
213
+ rules: {
214
+ ...baseRules,
215
+ 'no-undef': 'off',
216
+ 'indent': 'off',
217
+ '@typescript-eslint/indent': ['error', 2],
218
+ '@typescript-eslint/object-curly-spacing': ['error', 'never'],
219
+ '@typescript-eslint/space-before-function-paren': ['error', 'always'],
220
+ '@typescript-eslint/no-var-requires': 'off',
221
+ '@typescript-eslint/no-explicit-any': 'off',
222
+ '@typescript-eslint/no-use-before-define': ['error'],
223
+ 'react/require-default-props': 'off',
224
+ 'react/prop-types': 'off',
225
+ 'react/jsx-filename-extension': [
226
+ 2,
227
+ {'extensions': ['.jsx', '.tsx']}
228
+ ],
229
+ 'import/no-extraneous-dependencies': ['error', {
230
+ devDependencies: [
231
+ '**/*.test.ts',
232
+ '**/*.test.tsx',
233
+ '**/*.spec.ts',
234
+ '**/*.spec.tsx',
235
+ '*/test-*/*.ts',
236
+ '*/test-*/*.tsx',
237
+ ],
238
+ }],
239
+ }
240
+ }, {
241
+ files: ['*.spec.js', '*.spec.ts', '*.spec.jsx', '*.spec.tsx'],
179
242
  rules: {
180
243
  'global-require': 'off',
181
244
  'jsx-a11y/anchor-is-valid': 'off',
245
+ },
246
+ },
247
+ {
248
+ files: [
249
+ '**/reducers/**/*.js',
250
+ '**/reducers/**/*.ts'
251
+ ],
252
+ rules: {
253
+ 'default-param-last' : 'off'
182
254
  }
183
- }]
255
+ }],
184
256
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kununu/eslint-config",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "kununu's ESLint config",
5
5
  "main": "index.js",
6
6
  "repository": "kununu/javascript",
@@ -9,7 +9,8 @@
9
9
  "eslintconfig",
10
10
  "config",
11
11
  "kununu",
12
- "javascript"
12
+ "javascript",
13
+ "typescript"
13
14
  ],
14
15
  "author": "kununu",
15
16
  "license": "MIT",
@@ -21,14 +22,18 @@
21
22
  "@babel/core": "7.16.0",
22
23
  "@babel/eslint-parser": "7.16.3",
23
24
  "@babel/eslint-plugin": "7.14.5",
25
+ "@typescript-eslint/eslint-plugin": "5.5.0",
26
+ "@typescript-eslint/parser": "5.5.0",
24
27
  "eslint": "8.3.0",
25
28
  "eslint-config-airbnb": "19.0.1",
29
+ "eslint-config-airbnb-typescript": "16.0.0",
26
30
  "eslint-import-resolver-alias": "1.1.2",
27
31
  "eslint-plugin-import": "2.25.3",
28
32
  "eslint-plugin-jest-dom": "3.9.2",
29
33
  "eslint-plugin-jsx-a11y": "6.5.1",
30
34
  "eslint-plugin-react": "7.27.1",
31
35
  "eslint-plugin-react-hooks": "4.3.0",
32
- "eslint-plugin-testing-library": "5.0.0"
36
+ "eslint-plugin-testing-library": "5.0.0",
37
+ "typescript": "4.5.2"
33
38
  }
34
39
  }