@commercetools-frontend/eslint-config-mc-app 21.2.1 → 21.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @commercetools-frontend/eslint-config-mc-app
2
2
 
3
+ ## 21.3.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2526](https://github.com/commercetools/merchant-center-application-kit/pull/2526) [`e336802f`](https://github.com/commercetools/merchant-center-application-kit/commit/e336802f173f7e919604b3edc922ba096a2b85e5) Thanks [@emmenko](https://github.com/emmenko)! - Merge `eslint-config-react-app` into our `@commercetools-frontend/eslint-config-mc-app`. This should avoid any ESLint error related to merging different configs.
8
+
9
+ * [#2520](https://github.com/commercetools/merchant-center-application-kit/pull/2520) [`6f3a2083`](https://github.com/commercetools/merchant-center-application-kit/commit/6f3a2083efac387e9a2994fbaaeb18914e739aa8) Thanks [@renovate](https://github.com/apps/renovate)! - Upgrade dependencies
10
+
11
+ - [#2521](https://github.com/commercetools/merchant-center-application-kit/pull/2521) [`913459f3`](https://github.com/commercetools/merchant-center-application-kit/commit/913459f3eb2b2faafba06b585e7c02776002888b) Thanks [@emmenko](https://github.com/emmenko)! - Define the `BABEL_ENV` variable in the ESLint config, to ensure VSCode is able to parse the Babel config.
12
+
13
+ * [#2528](https://github.com/commercetools/merchant-center-application-kit/pull/2528) [`9235a721`](https://github.com/commercetools/merchant-center-application-kit/commit/9235a721df2be2ca5753994cd11312d577d0b293) Thanks [@renovate](https://github.com/apps/renovate)! - Update dependencies
14
+
15
+ * Updated dependencies [[`6f3a2083`](https://github.com/commercetools/merchant-center-application-kit/commit/6f3a2083efac387e9a2994fbaaeb18914e739aa8)]:
16
+ - @commercetools-frontend/babel-preset-mc-app@21.3.0
17
+
3
18
  ## 21.2.1
4
19
 
5
20
  ### Patch Changes
@@ -0,0 +1,293 @@
1
+ /**
2
+ * This file contains rules copied from other libraries, to make it easier to differentiate with
3
+ * our own rules and to better maintain them.
4
+ */
5
+
6
+ // The ESLint browser environment defines all browser globals as valid,
7
+ // even though most people don't know some of them exist (e.g. `name` or `status`).
8
+ // This is dangerous as it hides accidentally undefined variables.
9
+ // We deny the globals that we deem potentially confusing.
10
+ // To use them, explicitly reference them, e.g. `window.name` or `window.status`.
11
+ const restrictedGlobals = require('confusing-browser-globals');
12
+
13
+ const { statusCode } = require('./eslint');
14
+
15
+ // NOTE: When adding rules here, you need to make sure they are compatible with
16
+ // `typescript-eslint`, as some rules such as `no-array-constructor` aren't compatible.
17
+ // https://github.com/facebook/create-react-app/blob/main/packages/eslint-config-react-app/index.js
18
+ const craRules = {
19
+ base: {
20
+ // http://eslint.org/docs/rules/
21
+ 'array-callback-return': statusCode.warn,
22
+ 'default-case': [statusCode.warn, { commentPattern: '^no default$' }],
23
+ 'dot-location': [statusCode.warn, 'property'],
24
+ eqeqeq: [statusCode.warn, 'smart'],
25
+ 'new-parens': statusCode.warn,
26
+ 'no-array-constructor': statusCode.warn,
27
+ 'no-caller': statusCode.warn,
28
+ 'no-cond-assign': [statusCode.warn, 'except-parens'],
29
+ 'no-const-assign': statusCode.warn,
30
+ 'no-control-regex': statusCode.warn,
31
+ 'no-delete-var': statusCode.warn,
32
+ 'no-dupe-args': statusCode.warn,
33
+ 'no-dupe-class-members': statusCode.warn,
34
+ 'no-dupe-keys': statusCode.warn,
35
+ 'no-duplicate-case': statusCode.warn,
36
+ 'no-empty-character-class': statusCode.warn,
37
+ 'no-empty-pattern': statusCode.warn,
38
+ 'no-eval': statusCode.warn,
39
+ 'no-ex-assign': statusCode.warn,
40
+ 'no-extend-native': statusCode.warn,
41
+ 'no-extra-bind': statusCode.warn,
42
+ 'no-extra-label': statusCode.warn,
43
+ 'no-fallthrough': statusCode.warn,
44
+ 'no-func-assign': statusCode.warn,
45
+ 'no-implied-eval': statusCode.warn,
46
+ 'no-invalid-regexp': statusCode.warn,
47
+ 'no-iterator': statusCode.warn,
48
+ 'no-label-var': statusCode.warn,
49
+ 'no-labels': [statusCode.warn, { allowLoop: true, allowSwitch: false }],
50
+ 'no-lone-blocks': statusCode.warn,
51
+ 'no-loop-func': statusCode.warn,
52
+ 'no-mixed-operators': [
53
+ statusCode.warn,
54
+ {
55
+ groups: [
56
+ ['&', '|', '^', '~', '<<', '>>', '>>>'],
57
+ ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
58
+ ['&&', '||'],
59
+ ['in', 'instanceof'],
60
+ ],
61
+ allowSamePrecedence: false,
62
+ },
63
+ ],
64
+ 'no-multi-str': statusCode.warn,
65
+ 'no-global-assign': statusCode.warn,
66
+ 'no-unsafe-negation': statusCode.warn,
67
+ 'no-new-func': statusCode.warn,
68
+ 'no-new-object': statusCode.warn,
69
+ 'no-new-symbol': statusCode.warn,
70
+ 'no-new-wrappers': statusCode.warn,
71
+ 'no-obj-calls': statusCode.warn,
72
+ 'no-octal': statusCode.warn,
73
+ 'no-octal-escape': statusCode.warn,
74
+ 'no-redeclare': statusCode.warn,
75
+ 'no-regex-spaces': statusCode.warn,
76
+ 'no-restricted-syntax': [statusCode.warn, 'WithStatement'],
77
+ 'no-script-url': statusCode.warn,
78
+ 'no-self-assign': statusCode.warn,
79
+ 'no-self-compare': statusCode.warn,
80
+ 'no-sequences': statusCode.warn,
81
+ 'no-shadow-restricted-names': statusCode.warn,
82
+ 'no-sparse-arrays': statusCode.warn,
83
+ 'no-template-curly-in-string': statusCode.warn,
84
+ 'no-this-before-super': statusCode.warn,
85
+ 'no-throw-literal': statusCode.warn,
86
+ 'no-undef': statusCode.error,
87
+ 'no-restricted-globals': [statusCode.error].concat(restrictedGlobals),
88
+ 'no-unreachable': statusCode.warn,
89
+ 'no-unused-expressions': [
90
+ statusCode.error,
91
+ {
92
+ allowShortCircuit: true,
93
+ allowTernary: true,
94
+ allowTaggedTemplates: true,
95
+ },
96
+ ],
97
+ 'no-unused-labels': statusCode.warn,
98
+ 'no-unused-vars': [
99
+ statusCode.warn,
100
+ {
101
+ args: 'none',
102
+ ignoreRestSiblings: true,
103
+ },
104
+ ],
105
+ 'no-use-before-define': [
106
+ statusCode.warn,
107
+ {
108
+ functions: false,
109
+ classes: false,
110
+ variables: false,
111
+ },
112
+ ],
113
+ 'no-useless-computed-key': statusCode.warn,
114
+ 'no-useless-concat': statusCode.warn,
115
+ 'no-useless-constructor': statusCode.warn,
116
+ 'no-useless-escape': statusCode.warn,
117
+ 'no-useless-rename': [
118
+ statusCode.warn,
119
+ {
120
+ ignoreDestructuring: false,
121
+ ignoreImport: false,
122
+ ignoreExport: false,
123
+ },
124
+ ],
125
+ 'no-with': statusCode.warn,
126
+ 'no-whitespace-before-property': statusCode.warn,
127
+ 'react-hooks/exhaustive-deps': statusCode.warn,
128
+ 'require-yield': statusCode.warn,
129
+ 'rest-spread-spacing': [statusCode.warn, 'never'],
130
+ strict: [statusCode.warn, 'never'],
131
+ 'unicode-bom': [statusCode.warn, 'never'],
132
+ 'use-isnan': statusCode.warn,
133
+ 'valid-typeof': statusCode.warn,
134
+ 'no-restricted-properties': [
135
+ statusCode.error,
136
+ {
137
+ object: 'require',
138
+ property: 'ensure',
139
+ message:
140
+ 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting',
141
+ },
142
+ {
143
+ object: 'System',
144
+ property: 'import',
145
+ message:
146
+ 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting',
147
+ },
148
+ ],
149
+ 'getter-return': statusCode.warn,
150
+
151
+ // https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules
152
+ 'import/first': statusCode.error,
153
+ 'import/no-amd': statusCode.error,
154
+ 'import/no-anonymous-default-export': statusCode.warn,
155
+ 'import/no-webpack-loader-syntax': statusCode.error,
156
+
157
+ // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
158
+ 'react/forbid-foreign-prop-types': [
159
+ statusCode.warn,
160
+ { allowInPropTypes: true },
161
+ ],
162
+ 'react/jsx-no-comment-textnodes': statusCode.warn,
163
+ 'react/jsx-no-duplicate-props': statusCode.warn,
164
+ 'react/jsx-no-target-blank': statusCode.warn,
165
+ 'react/jsx-no-undef': statusCode.error,
166
+ 'react/jsx-pascal-case': [
167
+ statusCode.warn,
168
+ {
169
+ allowAllCaps: true,
170
+ ignore: [],
171
+ },
172
+ ],
173
+ 'react/no-danger-with-children': statusCode.warn,
174
+ // Disabled because of undesirable warnings
175
+ // See https://github.com/facebook/create-react-app/issues/5204 for
176
+ // blockers until its re-enabled
177
+ // 'react/no-deprecated': statusCode.warn,
178
+ 'react/no-direct-mutation-state': statusCode.warn,
179
+ 'react/no-is-mounted': statusCode.warn,
180
+ 'react/no-typos': statusCode.error,
181
+ 'react/require-render-return': statusCode.error,
182
+ 'react/style-prop-object': statusCode.warn,
183
+
184
+ // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules
185
+ 'jsx-a11y/alt-text': statusCode.warn,
186
+ 'jsx-a11y/anchor-has-content': statusCode.warn,
187
+ 'jsx-a11y/anchor-is-valid': [
188
+ statusCode.warn,
189
+ {
190
+ aspects: ['noHref', 'invalidHref'],
191
+ },
192
+ ],
193
+ 'jsx-a11y/aria-activedescendant-has-tabindex': statusCode.warn,
194
+ 'jsx-a11y/aria-props': statusCode.warn,
195
+ 'jsx-a11y/aria-proptypes': statusCode.warn,
196
+ 'jsx-a11y/aria-role': [statusCode.warn, { ignoreNonDOM: true }],
197
+ 'jsx-a11y/aria-unsupported-elements': statusCode.warn,
198
+ 'jsx-a11y/heading-has-content': statusCode.warn,
199
+ 'jsx-a11y/iframe-has-title': statusCode.warn,
200
+ 'jsx-a11y/img-redundant-alt': statusCode.warn,
201
+ 'jsx-a11y/no-access-key': statusCode.warn,
202
+ 'jsx-a11y/no-distracting-elements': statusCode.warn,
203
+ 'jsx-a11y/no-redundant-roles': statusCode.warn,
204
+ 'jsx-a11y/role-has-required-aria-props': statusCode.warn,
205
+ 'jsx-a11y/role-supports-aria-props': statusCode.warn,
206
+ 'jsx-a11y/scope': statusCode.warn,
207
+
208
+ // https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks
209
+ 'react-hooks/rules-of-hooks': statusCode.error,
210
+ },
211
+
212
+ typescript: {
213
+ // TypeScript's `noFallthroughCasesInSwitch` option is more robust (#6906)
214
+ 'default-case': statusCode.off,
215
+ // 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/291)
216
+ 'no-dupe-class-members': statusCode.off,
217
+ // 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/477)
218
+ 'no-undef': statusCode.off,
219
+
220
+ // Add TypeScript specific rules (and turn off ESLint equivalents)
221
+ '@typescript-eslint/consistent-type-assertions': statusCode.warn,
222
+ 'no-array-constructor': statusCode.off,
223
+ '@typescript-eslint/no-array-constructor': statusCode.warn,
224
+ 'no-redeclare': statusCode.off,
225
+ '@typescript-eslint/no-redeclare': statusCode.warn,
226
+ 'no-use-before-define': statusCode.off,
227
+ '@typescript-eslint/no-use-before-define': [
228
+ statusCode.warn,
229
+ {
230
+ functions: false,
231
+ classes: false,
232
+ variables: false,
233
+ typedefs: false,
234
+ },
235
+ ],
236
+ 'no-unused-expressions': statusCode.off,
237
+ '@typescript-eslint/no-unused-expressions': [
238
+ statusCode.error,
239
+ {
240
+ allowShortCircuit: true,
241
+ allowTernary: true,
242
+ allowTaggedTemplates: true,
243
+ },
244
+ ],
245
+ 'no-unused-vars': statusCode.off,
246
+ '@typescript-eslint/no-unused-vars': [
247
+ statusCode.warn,
248
+ {
249
+ args: 'none',
250
+ ignoreRestSiblings: true,
251
+ },
252
+ ],
253
+ 'no-useless-constructor': statusCode.off,
254
+ '@typescript-eslint/no-useless-constructor': statusCode.warn,
255
+ },
256
+
257
+ jest: {
258
+ // https://github.com/jest-community/eslint-plugin-jest
259
+ 'jest/no-conditional-expect': statusCode.error,
260
+ 'jest/no-identical-title': statusCode.error,
261
+ 'jest/no-interpolation-in-snapshots': statusCode.error,
262
+ 'jest/no-jasmine-globals': statusCode.error,
263
+ 'jest/no-jest-import': statusCode.error,
264
+ 'jest/no-mocks-import': statusCode.error,
265
+ 'jest/valid-describe-callback': statusCode.error,
266
+ 'jest/valid-expect': statusCode.error,
267
+ 'jest/valid-expect-in-promise': statusCode.error,
268
+ 'jest/valid-title': statusCode.warn,
269
+
270
+ // https://github.com/testing-library/eslint-plugin-testing-library
271
+ 'testing-library/await-async-query': statusCode.error,
272
+ 'testing-library/await-async-utils': statusCode.error,
273
+ 'testing-library/no-await-sync-query': statusCode.error,
274
+ 'testing-library/no-container': statusCode.error,
275
+ 'testing-library/no-debugging-utils': statusCode.error,
276
+ 'testing-library/no-dom-import': [statusCode.error, 'react'],
277
+ 'testing-library/no-node-access': statusCode.error,
278
+ 'testing-library/no-promise-in-fire-event': statusCode.error,
279
+ 'testing-library/no-render-in-setup': statusCode.error,
280
+ 'testing-library/no-unnecessary-act': statusCode.error,
281
+ 'testing-library/no-wait-for-empty-callback': statusCode.error,
282
+ 'testing-library/no-wait-for-multiple-assertions': statusCode.error,
283
+ 'testing-library/no-wait-for-side-effects': statusCode.error,
284
+ 'testing-library/no-wait-for-snapshot': statusCode.error,
285
+ 'testing-library/prefer-find-by': statusCode.error,
286
+ 'testing-library/prefer-presence-queries': statusCode.error,
287
+ 'testing-library/prefer-query-by-disappearance': statusCode.error,
288
+ 'testing-library/prefer-screen-queries': statusCode.error,
289
+ 'testing-library/render-result-naming-convention': statusCode.error,
290
+ },
291
+ };
292
+
293
+ exports.craRules = craRules;
package/index.js CHANGED
@@ -1,14 +1,23 @@
1
+ process.env.BABEL_ENV = 'production';
2
+
1
3
  // This is a workaround for https://github.com/eslint/eslint/issues/3458
2
4
  require('@rushstack/eslint-patch/modern-module-resolution');
3
5
 
4
6
  const { statusCode, allSupportedExtensions } = require('./helpers/eslint');
5
7
  const hasJsxRuntime = require('./helpers/has-jsx-runtime');
8
+ const { craRules } = require('./helpers/rules-presets');
6
9
 
7
10
  /**
8
11
  * @type {import("eslint").Linter.Config}
9
12
  */
10
13
  module.exports = {
14
+ root: true,
15
+
16
+ parser: '@babel/eslint-parser',
17
+
11
18
  parserOptions: {
19
+ sourceType: 'module',
20
+ requireConfigFile: false,
12
21
  babelOptions: {
13
22
  presets: [
14
23
  require.resolve(
@@ -17,13 +26,19 @@ module.exports = {
17
26
  ],
18
27
  },
19
28
  },
29
+
30
+ env: {
31
+ browser: true,
32
+ commonjs: true,
33
+ es6: true,
34
+ jest: true,
35
+ node: true,
36
+ },
37
+
20
38
  extends: [
21
- // https://github.com/facebook/create-react-app/tree/master/packages/eslint-config-react-app
22
- 'react-app',
23
- 'react-app/jest',
24
39
  // https://github.com/cypress-io/eslint-plugin-cypress
25
40
  'plugin:cypress/recommended',
26
- // https://github.com/benmosher/eslint-plugin-import
41
+ // https://github.com/import-js/eslint-plugin-import
27
42
  'plugin:import/errors',
28
43
  'plugin:import/warnings',
29
44
  'plugin:import/typescript',
@@ -37,13 +52,37 @@ module.exports = {
37
52
  // NOTE: this should go last.
38
53
  'prettier',
39
54
  ],
55
+
40
56
  plugins: [
57
+ // https://github.com/import-js/eslint-plugin-import
58
+ 'import',
59
+ // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y
60
+ 'jsx-a11y',
61
+ // https://github.com/yannickcr/eslint-plugin-react
62
+ 'react',
63
+ // https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks
64
+ 'react-hooks',
65
+ // https://github.com/testing-library/eslint-plugin-testing-library
66
+ 'testing-library',
67
+ // https://github.com/jest-community/eslint-plugin-jest
68
+ 'jest',
41
69
  // https://github.com/testing-library/eslint-plugin-jest-dom
42
70
  'jest-dom',
43
71
  // https://github.com/prettier/prettier-eslint
44
72
  'prettier',
45
73
  ],
74
+
75
+ settings: {
76
+ 'import/resolver': {
77
+ node: {
78
+ extensions: allSupportedExtensions,
79
+ },
80
+ },
81
+ },
82
+
46
83
  rules: {
84
+ ...craRules.base,
85
+
47
86
  // NOTE: The regular rule does not support do-expressions. The equivalent rule of babel does.
48
87
  'no-unused-expressions': statusCode.off,
49
88
 
@@ -93,24 +132,36 @@ module.exports = {
93
132
  'react/react-in-jsx-scope': statusCode.off,
94
133
  }),
95
134
  },
96
- settings: {
97
- 'import/resolver': {
98
- node: {
99
- extensions: allSupportedExtensions,
100
- },
101
- },
102
- },
135
+
103
136
  overrides: [
104
137
  {
105
138
  files: ['*.{spec,test}.*'],
139
+ env: {
140
+ 'jest/globals': true,
141
+ },
106
142
  rules: {
107
143
  'react/display-name': statusCode.off,
144
+
145
+ ...craRules.jest,
108
146
  },
109
147
  },
110
148
  {
111
149
  files: ['**/*.ts?(x)'],
150
+ parser: '@typescript-eslint/parser',
151
+ parserOptions: {
152
+ ecmaVersion: 2018,
153
+ sourceType: 'module',
154
+ ecmaFeatures: {
155
+ jsx: true,
156
+ },
157
+ // typescript-eslint specific options
158
+ warnOnUnsupportedTypeScriptVersion: true,
159
+ },
160
+ plugins: ['@typescript-eslint'],
112
161
  extends: ['prettier'],
113
162
  rules: {
163
+ ...craRules.typescript,
164
+
114
165
  // TypeScript
115
166
  '@typescript-eslint/ban-types': statusCode.off,
116
167
  '@typescript-eslint/naming-convention': statusCode.off,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/eslint-config-mc-app",
3
- "version": "21.2.1",
3
+ "version": "21.3.0",
4
4
  "description": "ESLint config used by a Custom Application.",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {
@@ -15,29 +15,30 @@
15
15
  "access": "public"
16
16
  },
17
17
  "dependencies": {
18
- "@commercetools-frontend/babel-preset-mc-app": "^21.0.0",
19
- "@rushstack/eslint-patch": "^1.1.0",
20
- "@typescript-eslint/eslint-plugin": "^5.10.0",
21
- "@typescript-eslint/parser": "^5.10.0",
22
- "eslint-config-prettier": "^8.3.0",
23
- "eslint-config-react-app": "^7.0.0",
24
- "eslint-import-resolver-typescript": "^2.5.0",
18
+ "@babel/core": "^7.17.8",
19
+ "@babel/eslint-parser": "^7.17.0",
20
+ "@commercetools-frontend/babel-preset-mc-app": "^21.3.0",
21
+ "@rushstack/eslint-patch": "^1.1.1",
22
+ "@typescript-eslint/eslint-plugin": "^5.17.0",
23
+ "@typescript-eslint/parser": "^5.17.0",
24
+ "confusing-browser-globals": "^1.0.11",
25
+ "eslint-config-prettier": "^8.5.0",
26
+ "eslint-import-resolver-typescript": "^2.7.0",
25
27
  "eslint-plugin-cypress": "^2.12.1",
26
- "eslint-plugin-flowtype": "^8.0.3",
27
28
  "eslint-plugin-import": "^2.25.4",
28
29
  "eslint-plugin-jest": "^25.7.0",
29
30
  "eslint-plugin-jest-dom": "^4.0.1",
30
31
  "eslint-plugin-jsx-a11y": "^6.5.1",
31
32
  "eslint-plugin-prettier": "^4.0.0",
32
- "eslint-plugin-react": "^7.28.0",
33
- "eslint-plugin-react-hooks": "^4.3.0",
34
- "eslint-plugin-testing-library": "^5.0.4"
33
+ "eslint-plugin-react": "^7.29.4",
34
+ "eslint-plugin-react-hooks": "^4.4.0",
35
+ "eslint-plugin-testing-library": "^5.1.0"
35
36
  },
36
37
  "peerDependencies": {
37
38
  "eslint": "8.x"
38
39
  },
39
40
  "devDependencies": {
40
- "eslint": "8.11.0"
41
+ "eslint": "8.12.0"
41
42
  },
42
43
  "engines": {
43
44
  "node": ">=14"