@foray1010/eslint-config 10.5.1 → 11.0.1

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
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [11.0.1](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@11.0.0...@foray1010/eslint-config@11.0.1) (2023-08-13)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **deps:** update dependency eslint-plugin-testing-library to v6 ([2f9ae02](https://github.com/foray1010/common-presets/commit/2f9ae029f9032b8380dcccb3fb68f1d3f91bcce6))
11
+
12
+ ## [11.0.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@10.5.1...@foray1010/eslint-config@11.0.0) (2023-08-10)
13
+
14
+ ### ⚠ BREAKING CHANGES
15
+
16
+ - **deps:** update prettier to v3
17
+ - **deps:** require eslint ^8.38.0
18
+
19
+ ### Features
20
+
21
+ - **deps:** update eslint-config-prettier to v9 ([5be09d4](https://github.com/foray1010/common-presets/commit/5be09d47bea41e79ea2887391ae80baa6b38eb8c))
22
+ - **deps:** update ts and functional eslint plugin to v6 ([5d7b765](https://github.com/foray1010/common-presets/commit/5d7b7659c9e5b0a8603d3c57b06103741fb1fd0b))
23
+
24
+ ### Bug Fixes
25
+
26
+ - **deps:** update dependency @eslint-community/eslint-plugin-eslint-comments to v4 ([#683](https://github.com/foray1010/common-presets/issues/683)) ([c50b32a](https://github.com/foray1010/common-presets/commit/c50b32a87158a519ffad8f430827410df0fa46d7))
27
+ - **deps:** update dependency eslint-plugin-jest-dom to v5 ([#651](https://github.com/foray1010/common-presets/issues/651)) ([a8882a9](https://github.com/foray1010/common-presets/commit/a8882a9b4fdb2b34fd233d50e835eab05dba05ec))
28
+ - **deps:** update dependency eslint-plugin-n to v16 ([85aace0](https://github.com/foray1010/common-presets/commit/85aace07945ffa1edaa163340063719220226467))
29
+ - **deps:** update dependency eslint-plugin-unicorn to v47 ([2f6effe](https://github.com/foray1010/common-presets/commit/2f6effea8f83c31632bf37c49778019e835a09cb))
30
+ - **deps:** update eslint-plugin-unicorn to v48 ([d930822](https://github.com/foray1010/common-presets/commit/d9308225b864eaf7d6304c83966e288f688186a7))
31
+ - **deps:** update prettier to v3 ([4724464](https://github.com/foray1010/common-presets/commit/4724464c1c272df3eb686b168d836a9a696c11a2))
32
+
6
33
  ## [10.5.1](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@10.5.0...@foray1010/eslint-config@10.5.1) (2023-04-22)
7
34
 
8
35
  ### Bug Fixes
package/bases/base.mjs CHANGED
@@ -14,16 +14,21 @@ import {
14
14
  typeScriptTestFileGlobs,
15
15
  } from '../constants.mjs'
16
16
 
17
- /** @returns {Promise<readonly import('eslint').Linter.FlatConfig[]>} */
17
+ /** @typedef {import('../types/internal.d.ts').EslintConfig} EslintConfig */
18
+
19
+ /** @returns {Promise<EslintConfig>} */
18
20
  async function generateTypeScriptConfig() {
19
21
  // typescript plugins are depended on `typescript` package
20
22
  if (!hasDep('typescript')) return []
21
23
 
24
+ /* eslint-disable import/no-unresolved */
22
25
  const eslintPluginTypescriptEslint = (
23
26
  await import('@typescript-eslint/eslint-plugin')
24
27
  ).default
25
- const typescriptEslintParser = (await import('@typescript-eslint/parser'))
26
- .default
28
+ const typescriptEslintParser =
29
+ // @ts-expect-error
30
+ (await import('@typescript-eslint/parser')).default
31
+ /* eslint-enable import/no-unresolved */
27
32
  const eslintPluginDeprecation = (await import('eslint-plugin-deprecation'))
28
33
  .default
29
34
  const eslintPluginFunctional = (await import('eslint-plugin-functional'))
@@ -49,7 +54,6 @@ async function generateTypeScriptConfig() {
49
54
  },
50
55
  },
51
56
  plugins: {
52
- // @ts-expect-error
53
57
  '@typescript-eslint': eslintPluginTypescriptEslint,
54
58
  // @ts-expect-error
55
59
  deprecation: eslintPluginDeprecation,
@@ -116,8 +120,6 @@ async function generateTypeScriptConfig() {
116
120
  '@typescript-eslint/no-duplicate-enum-values': 'error',
117
121
  // need empty function for react context default value
118
122
  '@typescript-eslint/no-empty-function': 'off',
119
- // encourage to check error type before use in catch clauses
120
- '@typescript-eslint/no-implicit-any-catch': 'error',
121
123
  // when using typescript 5.0 with verbatimModuleSyntax flag on, compiler will not remove import statements with only inline type imports which lead to side effects
122
124
  '@typescript-eslint/no-import-type-side-effects': 'error',
123
125
  // enforce correct usage of `void` type
@@ -232,7 +234,6 @@ async function generateTypeScriptConfig() {
232
234
  {
233
235
  files: typeScriptTestFileGlobs,
234
236
  plugins: {
235
- // @ts-expect-error
236
237
  '@typescript-eslint': eslintPluginTypescriptEslint,
237
238
  jest: eslintPluginJest,
238
239
  },
@@ -252,7 +253,7 @@ async function generateTypeScriptConfig() {
252
253
  ]
253
254
  }
254
255
 
255
- /** @type {import('eslint').Linter.FlatConfig} */
256
+ /** @type {EslintConfig[number]} */
256
257
  const cjsConfig = {
257
258
  languageOptions: {
258
259
  globals: globals.commonjs,
@@ -264,7 +265,7 @@ const cjsConfig = {
264
265
  },
265
266
  }
266
267
 
267
- /** @type {import('eslint').Linter.FlatConfig} */
268
+ /** @type {EslintConfig[number]} */
268
269
  const esmConfig = {
269
270
  languageOptions: {
270
271
  sourceType: 'module',
@@ -280,7 +281,7 @@ const esmConfig = {
280
281
  },
281
282
  }
282
283
 
283
- /** @type {readonly import('eslint').Linter.FlatConfig[]} */
284
+ /** @type {EslintConfig} */
284
285
  const baseConfig = [
285
286
  js.configs.recommended,
286
287
  {
@@ -409,18 +410,12 @@ const baseConfig = [
409
410
  // use with `unicorn/throw-new-error`
410
411
  // disallow builtins to be created without `new` operator, to be consistent with es6 class syntax
411
412
  'unicorn/new-for-builtins': 'error',
412
- // `at()` is simpler to use in array and string
413
- 'unicorn/prefer-at': 'error',
414
- // EventTarget works on both node.js and browsers, but EventEmitter only works on node.js
415
- 'unicorn/prefer-event-target': 'error',
416
413
  // some legacy projects still use commonjs
417
414
  'unicorn/prefer-module': 'off',
418
415
  // `querySelector` is slower than `getElementById`
419
416
  'unicorn/prefer-query-selector': 'off',
420
417
  // `Array.from(iterable)` is more readable than `[...iterable]`
421
418
  'unicorn/prefer-spread': 'off',
422
- // it is cleaner than `.replace(//g)`
423
- 'unicorn/prefer-string-replace-all': 'error',
424
419
  // sometimes it is less readable using ternary expressions
425
420
  'unicorn/prefer-ternary': 'off',
426
421
  // webpack support on `top level await` is still experimental, and some legacy projects still use commonjs
package/bases/browser.mjs CHANGED
@@ -1,13 +1,36 @@
1
+ // @ts-expect-error
2
+ import { hasDep } from '@foray1010/common-presets-utils'
1
3
  import restrictedGlobals from 'confusing-browser-globals'
2
4
  import eslintPluginCompat from 'eslint-plugin-compat'
3
5
  import eslintPluginImport from 'eslint-plugin-import'
4
- import eslintPluginJestDom from 'eslint-plugin-jest-dom'
5
6
  import eslintPluginTestingLibrary from 'eslint-plugin-testing-library'
6
7
  import globals from 'globals'
7
8
 
8
9
  import { testFileGlobs } from '../constants.mjs'
9
10
 
10
- /** @type {import('eslint').Linter.FlatConfig[]} */
11
+ /** @typedef {import('../types/internal.d.ts').EslintConfig} EslintConfig */
12
+
13
+ /** @returns {Promise<EslintConfig>} */
14
+ async function generateJestDomConfig() {
15
+ // `eslint-plugin-jest-dom` depends on `@testing-library/dom` package
16
+ if (!hasDep('@testing-library/dom')) return []
17
+
18
+ const eslintPluginJestDom = (await import('eslint-plugin-jest-dom')).default
19
+
20
+ return [
21
+ {
22
+ files: testFileGlobs,
23
+ plugins: {
24
+ 'jest-dom': eslintPluginJestDom,
25
+ },
26
+ rules: {
27
+ ...eslintPluginJestDom.configs['recommended']?.rules,
28
+ },
29
+ },
30
+ ]
31
+ }
32
+
33
+ /** @type {EslintConfig} */
11
34
  const browserConfig = [
12
35
  {
13
36
  languageOptions: {
@@ -30,14 +53,13 @@ const browserConfig = [
30
53
  'no-restricted-globals': ['error', ...restrictedGlobals],
31
54
  },
32
55
  },
56
+ ...(await generateJestDomConfig()),
33
57
  {
34
58
  files: testFileGlobs,
35
59
  plugins: {
36
- 'jest-dom': eslintPluginJestDom,
37
60
  'testing-library': eslintPluginTestingLibrary,
38
61
  },
39
62
  rules: {
40
- ...eslintPluginJestDom.configs['recommended']?.rules,
41
63
  ...eslintPluginTestingLibrary.configs['dom']?.rules,
42
64
  // allow to use nodejs modules in tests
43
65
  'import/no-nodejs-modules': 'off',
package/bases/ignores.mjs CHANGED
@@ -1,4 +1,6 @@
1
- /** @type {readonly import('eslint').Linter.FlatConfig[]} */
1
+ /** @typedef {import('../types/internal.d.ts').EslintConfig} EslintConfig */
2
+
3
+ /** @type {EslintConfig} */
2
4
  const ignoresConfig = [
3
5
  {
4
6
  // replace `.eslintignore`
package/bases/node.mjs CHANGED
@@ -2,7 +2,9 @@
2
2
  import { isESM } from '@foray1010/common-presets-utils'
3
3
  import eslintPluginN from 'eslint-plugin-n'
4
4
 
5
- /** @type {import('eslint').Linter.FlatConfig} */
5
+ /** @typedef {import('../types/internal.d.ts').EslintConfig} EslintConfig */
6
+
7
+ /** @type {EslintConfig[number]} */
6
8
  const cjsConfig = {
7
9
  languageOptions: {
8
10
  globals: {
@@ -14,7 +16,7 @@ const cjsConfig = {
14
16
  },
15
17
  }
16
18
 
17
- /** @type {import('eslint').Linter.FlatConfig[]} */
19
+ /** @type {EslintConfig} */
18
20
  const nodeConfig = [
19
21
  {
20
22
  plugins: {
@@ -1,7 +1,9 @@
1
1
  import eslintConfigPrettier from 'eslint-config-prettier'
2
2
  import eslintPluginPrettier from 'eslint-plugin-prettier'
3
3
 
4
- /** @type {import('eslint').Linter.FlatConfig[]} */
4
+ /** @typedef {import('../types/internal.d.ts').EslintConfig} EslintConfig */
5
+
6
+ /** @type {EslintConfig} */
5
7
  const prettierConfig = [
6
8
  // should be placed at the end to override other configs
7
9
  {
package/bases/react.mjs CHANGED
@@ -4,7 +4,9 @@ import eslintPluginTestingLibrary from 'eslint-plugin-testing-library'
4
4
 
5
5
  import { testFileGlobs } from '../constants.mjs'
6
6
 
7
- /** @type {import('eslint').Linter.FlatConfig[]} */
7
+ /** @typedef {import('../types/internal.d.ts').EslintConfig} EslintConfig */
8
+
9
+ /** @type {EslintConfig} */
8
10
  const reactConfig = [
9
11
  {
10
12
  languageOptions: {
@@ -80,14 +82,10 @@ const reactConfig = [
80
82
  eventModules: ['fire-event'],
81
83
  },
82
84
  ],
83
- // global flag /g holds state and might cause false-positives while querying for elements
84
- 'testing-library/no-global-regexp-flag-in-query': 'error',
85
85
  // explicitly assert the element to prevent reader missed the test cases
86
86
  'testing-library/prefer-explicit-assert': 'error',
87
87
  // prefer @testing-library/user-event over fireEvent
88
88
  'testing-library/prefer-user-event': 'error',
89
- // as `wait` is deprecated
90
- 'testing-library/prefer-wait-for': 'error',
91
89
  },
92
90
  },
93
91
  ]
package/index.mjs CHANGED
@@ -6,21 +6,23 @@ import reactConfig from './bases/react.mjs'
6
6
 
7
7
  export * from './utils/applyConfig.mjs'
8
8
 
9
- /** @type {readonly import('eslint').Linter.FlatConfig[]} */
9
+ /** @typedef {import('./types/internal.d.ts').EslintConfig} EslintConfig */
10
+
11
+ /** @type {EslintConfig} */
10
12
  export const eslintBrowserConfig = [
11
13
  ...baseConfig,
12
14
  ...browserConfig,
13
15
  ...prettierConfig,
14
16
  ]
15
17
 
16
- /** @type {readonly import('eslint').Linter.FlatConfig[]} */
18
+ /** @type {EslintConfig} */
17
19
  export const eslintNodeConfig = [
18
20
  ...baseConfig,
19
21
  ...nodeConfig,
20
22
  ...prettierConfig,
21
23
  ]
22
24
 
23
- /** @type {readonly import('eslint').Linter.FlatConfig[]} */
25
+ /** @type {EslintConfig} */
24
26
  export const eslintReactConfig = [
25
27
  ...baseConfig,
26
28
  ...browserConfig,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@foray1010/eslint-config",
4
- "version": "10.5.1",
4
+ "version": "11.0.1",
5
5
  "homepage": "https://github.com/foray1010/common-presets/tree/master/packages/eslint-config#readme",
6
6
  "bugs": "https://github.com/foray1010/common-presets/issues",
7
7
  "repository": {
@@ -20,40 +20,43 @@
20
20
  "type:check": "tsc"
21
21
  },
22
22
  "dependencies": {
23
- "@eslint-community/eslint-plugin-eslint-comments": "^3.2.1",
24
- "@eslint/js": "^8.36.0",
25
- "@foray1010/common-presets-utils": "^7.0.2",
26
- "@typescript-eslint/eslint-plugin": "^5.56.0",
27
- "@typescript-eslint/parser": "^5.56.0",
23
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.0.0",
24
+ "@eslint/js": "^8.44.0",
25
+ "@foray1010/common-presets-utils": "^7.0.3",
26
+ "@typescript-eslint/eslint-plugin": "^6.2.1",
27
+ "@typescript-eslint/parser": "^6.2.1",
28
28
  "confusing-browser-globals": "^1.0.10",
29
- "eslint-config-prettier": "^8.8.0",
29
+ "eslint-config-prettier": "^9.0.0",
30
30
  "eslint-import-resolver-typescript": "^3.5.2",
31
31
  "eslint-plugin-compat": "^4.1.2",
32
32
  "eslint-plugin-deprecation": "^1.4.0",
33
- "eslint-plugin-functional": "^5.0.8",
33
+ "eslint-plugin-functional": "^6.0.0",
34
34
  "eslint-plugin-import": "^2.22.1",
35
35
  "eslint-plugin-jest": "^27.1.3",
36
- "eslint-plugin-jest-dom": "^4.0.0",
37
- "eslint-plugin-jsdoc": "^43.0.7",
38
- "eslint-plugin-n": "^15.3.0",
39
- "eslint-plugin-prettier": "^4.0.0",
36
+ "eslint-plugin-jest-dom": "^5.0.0",
37
+ "eslint-plugin-n": "^16.0.0",
38
+ "eslint-plugin-prettier": "^5.0.0",
40
39
  "eslint-plugin-react": "^7.32.2",
41
40
  "eslint-plugin-react-hooks": "^4.2.0",
42
41
  "eslint-plugin-simple-import-sort": "^10.0.0",
43
- "eslint-plugin-testing-library": "^5.10.2",
44
- "eslint-plugin-unicorn": "^46.0.0",
42
+ "eslint-plugin-testing-library": "^6.0.0",
43
+ "eslint-plugin-unicorn": "^48.0.0",
45
44
  "globals": "^13.19.0"
46
45
  },
47
46
  "devDependencies": {
48
47
  "@types/confusing-browser-globals": "1.0.0",
49
- "@types/eslint": "8.37.0"
48
+ "@types/eslint": "8.44.2"
50
49
  },
51
50
  "peerDependencies": {
52
- "eslint": "^8.36.0",
53
- "prettier": "^2.0.0",
51
+ "@testing-library/dom": "^9.0.0",
52
+ "eslint": "^8.38.0",
53
+ "prettier": "^3.0.0",
54
54
  "typescript": "^5.0.2"
55
55
  },
56
56
  "peerDependenciesMeta": {
57
+ "@testing-library/dom": {
58
+ "optional": true
59
+ },
57
60
  "typescript": {
58
61
  "optional": true
59
62
  }
@@ -64,5 +67,5 @@
64
67
  "publishConfig": {
65
68
  "access": "public"
66
69
  },
67
- "gitHead": "0bfecd900cd5d2e0b72ad9c3191c821f5708b51e"
70
+ "gitHead": "6510be6a4ab9f4b36745c7f5c5d2e995a2ab7770"
68
71
  }
@@ -2,23 +2,25 @@ import path from 'node:path'
2
2
 
3
3
  import { supportedFilesGlob } from '../constants.mjs'
4
4
 
5
+ /** @typedef {import('../types/internal.d.ts').EslintConfig} EslintConfig */
6
+
5
7
  /**
6
8
  * Extend the flat configs with default files and ignores
7
9
  * @param {{
8
10
  * readonly filePrefixes: string | string[],
9
- * readonly ignores?: string | string[] | undefined
11
+ * readonly ignores?: string[] | undefined
10
12
  * }} options
11
- * @param {readonly import('eslint').Linter.FlatConfig[]} flatConfigs
12
- * @returns {readonly import('eslint').Linter.FlatConfig[]}
13
+ * @param {EslintConfig} eslintConfig
14
+ * @returns {EslintConfig}
13
15
  */
14
- export function applyConfig(options, flatConfigs) {
16
+ export function applyConfig(options, eslintConfig) {
15
17
  const filePrefixes = [options.filePrefixes].flat()
16
18
  if (filePrefixes.length === 0) {
17
19
  throw new TypeError('filePrefixes must not be empty')
18
20
  }
19
21
 
20
22
  // Do not allow string such as "eslint:recommended" because it cannot be overridden by files/ignores
21
- for (const config of flatConfigs) {
23
+ for (const config of eslintConfig) {
22
24
  if (typeof config === 'string') {
23
25
  throw new TypeError(
24
26
  `Cannot extend ${config} with files/ignores, use \`@eslint/js\` instead`,
@@ -30,7 +32,7 @@ export function applyConfig(options, flatConfigs) {
30
32
  }
31
33
  }
32
34
 
33
- return flatConfigs.map((config) => {
35
+ return eslintConfig.map((config) => {
34
36
  const files = generateCombinations(filePrefixes, config.files)
35
37
  return {
36
38
  ...config,
@@ -42,18 +44,26 @@ export function applyConfig(options, flatConfigs) {
42
44
 
43
45
  /**
44
46
  * @param {string[]} prefixes
45
- * @param {string | string[] | undefined} originalGlobs
46
- * @returns {string | string[] | undefined}
47
+ * @param {EslintConfig[number]['files']} originalGlobs
48
+ * @returns {string[] | undefined}
47
49
  */
48
50
  function generateCombinations(prefixes, originalGlobs) {
49
51
  if (!originalGlobs || originalGlobs.length === 0) {
50
52
  return prefixes.map((prefix) => path.join(prefix, supportedFilesGlob))
51
53
  }
52
54
 
53
- const originalGlobList = [originalGlobs].flat()
55
+ const verifiedOriginalGlobs = originalGlobs.filter(
56
+ /** @returns {originalGlob is string} */
57
+ (originalGlob) => typeof originalGlob === 'string',
58
+ )
59
+ if (originalGlobs.length !== verifiedOriginalGlobs.length) {
60
+ throw new TypeError(
61
+ `Do not support using non-string value in files/ignores`,
62
+ )
63
+ }
54
64
 
55
65
  return prefixes.flatMap((prefix) => {
56
- return originalGlobList.flatMap((originalGlob) => {
66
+ return verifiedOriginalGlobs.flatMap((originalGlob) => {
57
67
  const signRegexp = /^!/
58
68
  const sign = originalGlob.match(signRegexp)?.[0] ?? ''
59
69
  return sign + path.join(prefix, originalGlob.replace(signRegexp, ''))