@foray1010/eslint-config 10.0.0 → 10.0.2

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,19 @@
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
+ ## [10.0.2](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@10.0.1...@foray1010/eslint-config@10.0.2) (2023-03-23)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **eslint-config:** disable some eslint-plugin-import rules due to not support flat config ([3a84a7d](https://github.com/foray1010/common-presets/commit/3a84a7d10e0bdd8b81ce115ad509e46eee2330c5))
11
+
12
+ ## [10.0.1](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@10.0.0...@foray1010/eslint-config@10.0.1) (2023-03-23)
13
+
14
+ ### Bug Fixes
15
+
16
+ - **eslint-config:** fix wrong assumption, `files` only does not filter ([661d0c6](https://github.com/foray1010/common-presets/commit/661d0c6bd05f688c8f6956fb26844e597c851dc4))
17
+ - **eslint-config:** should not use ignores in config, and allow user defined ignores ([05b0ca0](https://github.com/foray1010/common-presets/commit/05b0ca09a76ed677c903b654cef3eeef7773610e))
18
+
6
19
  ## [10.0.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@9.2.0...@foray1010/eslint-config@10.0.0) (2023-03-23)
7
20
 
8
21
  ### ⚠ BREAKING CHANGES
package/README.md CHANGED
@@ -26,16 +26,11 @@ Z for looser rules
26
26
 
27
27
  ```js
28
28
  import {
29
- eslintFilesConfig,
30
29
  eslintIgnoresConfig,
31
30
  eslintNodeConfig,
32
31
  } from '@foray1010/eslint-config'
33
32
 
34
- const config = [
35
- ...eslintIgnoresConfig,
36
- ...eslintFilesConfig,
37
- ...eslintNodeConfig,
38
- ]
33
+ const config = [...eslintIgnoresConfig, ...eslintNodeConfig]
39
34
  export default config
40
35
  ```
41
36
 
@@ -43,16 +38,11 @@ Z for looser rules
43
38
 
44
39
  ```js
45
40
  import {
46
- eslintFilesConfig,
47
41
  eslintIgnoresConfig,
48
42
  eslintBrowserConfig,
49
43
  } from '@foray1010/eslint-config'
50
44
 
51
- const config = [
52
- ...eslintIgnoresConfig,
53
- ...eslintFilesConfig,
54
- ...eslintBrowserConfig,
55
- ]
45
+ const config = [...eslintIgnoresConfig, ...eslintBrowserConfig]
56
46
  export default config
57
47
  ```
58
48
 
@@ -60,16 +50,11 @@ Z for looser rules
60
50
 
61
51
  ```js
62
52
  import {
63
- eslintFilesConfig,
64
53
  eslintIgnoresConfig,
65
54
  eslintReactConfig,
66
55
  } from '@foray1010/eslint-config'
67
56
 
68
- const config = [
69
- ...eslintIgnoresConfig,
70
- ...eslintFilesConfig,
71
- ...eslintReactConfig,
72
- ]
57
+ const config = [...eslintIgnoresConfig, ...eslintReactConfig]
73
58
  export default config
74
59
  ```
75
60
 
@@ -78,7 +63,6 @@ Z for looser rules
78
63
  ```js
79
64
  import {
80
65
  applyConfig,
81
- eslintFilesConfig,
82
66
  eslintIgnoresConfig,
83
67
  eslintNodeConfig,
84
68
  eslintReactConfig,
@@ -86,10 +70,10 @@ Z for looser rules
86
70
 
87
71
  const config = [
88
72
  ...eslintIgnoresConfig,
89
- ...eslintFilesConfig,
90
73
  ...applyConfig(
91
74
  {
92
- ignorePrefixes: ['src'],
75
+ filePrefixes: '.',
76
+ ignores: ['src/**'],
93
77
  },
94
78
  eslintNodeConfig,
95
79
  ),
package/bases/base.mjs CHANGED
@@ -12,7 +12,11 @@ import eslintPluginSimpleImportSort from 'eslint-plugin-simple-import-sort'
12
12
  import eslintPluginUnicorn from 'eslint-plugin-unicorn'
13
13
  import globals from 'globals'
14
14
 
15
- import { testFileGlobs, typeScriptFileGlobs } from '../constants.mjs'
15
+ import {
16
+ testFileGlobs,
17
+ typeScriptFileGlobs,
18
+ typeScriptTestFileGlobs,
19
+ } from '../constants.mjs'
16
20
 
17
21
  /** @type {import('eslint').Linter.FlatConfig} */
18
22
  const cjsConfig = {
@@ -139,6 +143,10 @@ const baseConfig = [
139
143
  noUselessIndex: false,
140
144
  },
141
145
  ],
146
+ // turn off these rules as they do not support flat config: https://github.com/import-js/eslint-plugin-import/issues/2556
147
+ 'import/namespace': 'off',
148
+ 'import/no-named-as-default': 'off',
149
+ 'import/no-named-as-default-member': 'off',
142
150
  // prefer explicitly convert type for readability
143
151
  'no-implicit-coercion': 'error',
144
152
  // make sure private class members are in-use
@@ -354,8 +362,7 @@ const baseConfig = [
354
362
  },
355
363
  },
356
364
  {
357
- files: typeScriptFileGlobs,
358
- ignores: testFileGlobs.map((glob) => `!${glob}`),
365
+ files: typeScriptTestFileGlobs,
359
366
  plugins: {
360
367
  '@typescript-eslint': eslintPluginTypescriptEslint,
361
368
  jest: eslintPluginJest,
@@ -1,5 +1,4 @@
1
1
  import eslintConfigPrettier from 'eslint-config-prettier'
2
- // eslint-disable-next-line import/namespace, import/no-named-as-default, import/no-named-as-default-member
3
2
  import eslintPluginPrettier from 'eslint-plugin-prettier'
4
3
 
5
4
  /** @type {import('eslint').Linter.FlatConfig[]} */
package/constants.mjs CHANGED
@@ -1,8 +1,15 @@
1
+ export const supportedFilesGlob = '**/*.{cjs,cts,js,mjs,mts,ts,tsx}'
1
2
  export const testFileGlobs = [
2
- '**/__fixtures__/**',
3
- '**/__mocks__/**',
4
- '**/__tests__/**',
3
+ '**/__fixtures__/**/*.{cjs,cts,js,mjs,mts,ts,tsx}',
4
+ '**/__mocks__/**/*.{cjs,cts,js,mjs,mts,ts,tsx}',
5
+ '**/__tests__/**/*.{cjs,cts,js,mjs,mts,ts,tsx}',
5
6
  '**/*.{spec,test}.{cjs,cts,js,mjs,mts,ts,tsx}',
6
7
  ]
7
8
 
8
9
  export const typeScriptFileGlobs = ['**/*.{cts,mts,ts,tsx}']
10
+ export const typeScriptTestFileGlobs = [
11
+ '**/__fixtures__/**/*.{cts,mts,ts,tsx}',
12
+ '**/__mocks__/**/*.{cts,mts,ts,tsx}',
13
+ '**/__tests__/**/*.{cts,mts,ts,tsx}',
14
+ '**/*.{spec,test}.{cts,mts,ts,tsx}',
15
+ ]
package/index.mjs CHANGED
@@ -28,5 +28,4 @@ export const eslintReactConfig = [
28
28
  ...prettierConfig,
29
29
  ]
30
30
 
31
- export { default as eslintFilesConfig } from './bases/files.mjs'
32
31
  export { default as eslintIgnoresConfig } from './bases/ignores.mjs'
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.0.0",
4
+ "version": "10.0.2",
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": {
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@eslint-community/eslint-plugin-eslint-comments": "^3.2.1",
24
24
  "@eslint/js": "^8.36.0",
25
- "@foray1010/common-presets-utils": "^7.0.0",
25
+ "@foray1010/common-presets-utils": "^7.0.1",
26
26
  "@typescript-eslint/eslint-plugin": "^5.56.0",
27
27
  "@typescript-eslint/parser": "^5.56.0",
28
28
  "confusing-browser-globals": "^1.0.10",
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "access": "public"
60
60
  },
61
- "gitHead": "ee22f073ee1702354310091b7c3a5ec18a930bec"
61
+ "gitHead": "c532946a18c6a773dd05bb8be2c90e905181e165"
62
62
  }
@@ -1,15 +1,22 @@
1
1
  import path from 'node:path'
2
2
 
3
+ import { supportedFilesGlob } from '../constants.mjs'
4
+
3
5
  /**
4
6
  * Extend the flat configs with default files and ignores
5
7
  * @param {{
6
- * readonly filePrefixes?: string[] | undefined,
7
- * readonly ignorePrefixes?: string[] | undefined
8
+ * readonly filePrefixes: string | string[],
9
+ * readonly ignores?: string | string[] | undefined
8
10
  * }} options
9
11
  * @param {readonly import('eslint').Linter.FlatConfig[]} flatConfigs
10
12
  * @returns {readonly import('eslint').Linter.FlatConfig[]}
11
13
  */
12
14
  export function applyConfig(options, flatConfigs) {
15
+ const filePrefixes = [options.filePrefixes].flat()
16
+ if (filePrefixes.length === 0) {
17
+ throw new TypeError('filePrefixes must not be empty')
18
+ }
19
+
13
20
  // Do not allow string such as "eslint:recommended" because it cannot be overridden by files/ignores
14
21
  for (const config of flatConfigs) {
15
22
  if (typeof config === 'string') {
@@ -18,35 +25,29 @@ export function applyConfig(options, flatConfigs) {
18
25
  )
19
26
  }
20
27
 
21
- const keys = Object.keys(config)
22
- if (
23
- keys.length === 1 &&
24
- (keys.includes('files') || keys.includes('ignores'))
25
- ) {
26
- throw new TypeError('Do not use `files` or `ignores` only')
28
+ if (Object.keys(config).includes('ignores')) {
29
+ throw new TypeError('Do not use `ignores` in config')
27
30
  }
28
31
  }
29
32
 
30
33
  return flatConfigs.map((config) => {
31
- const files = generateCombinations(options.filePrefixes, config.files)
32
- const ignores = generateCombinations(options.ignorePrefixes, config.ignores)
34
+ const files = generateCombinations(filePrefixes, config.files)
33
35
  return {
34
36
  ...config,
35
37
  ...(files ? { files } : {}),
36
- ...(ignores ? { ignores } : {}),
38
+ ...(options.ignores ? { ignores: options.ignores } : {}),
37
39
  }
38
40
  })
39
41
  }
40
42
 
41
43
  /**
42
- * @param {string[] | undefined} prefixes
44
+ * @param {string[]} prefixes
43
45
  * @param {string | string[] | undefined} originalGlobs
44
46
  * @returns {string | string[] | undefined}
45
47
  */
46
48
  function generateCombinations(prefixes, originalGlobs) {
47
- if (!prefixes || prefixes.length === 0) return originalGlobs
48
49
  if (!originalGlobs || originalGlobs.length === 0) {
49
- return prefixes.map((prefix) => path.join(prefix, '**'))
50
+ return prefixes.map((prefix) => path.join(prefix, supportedFilesGlob))
50
51
  }
51
52
 
52
53
  const originalGlobList = [originalGlobs].flat()
package/bases/files.mjs DELETED
@@ -1,8 +0,0 @@
1
- /** @type {readonly import('eslint').Linter.FlatConfig[]} */
2
- const filesConfig = [
3
- {
4
- // replace `eslint --ext=cjs,cts,js,mjs,mts,ts,tsx` in legacy config
5
- files: ['**/*.{cjs,cts,js,mjs,mts,ts,tsx}'],
6
- },
7
- ]
8
- export default filesConfig