@putout/eslint 3.0.0 → 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.
@@ -2,7 +2,6 @@
2
2
 
3
3
  const prepare = (plugin, context, options) => (node) => {
4
4
  const {filter, report} = plugin;
5
-
6
5
  const {sourceCode, filename} = context;
7
6
 
8
7
  const getText = sourceCode.getText.bind(sourceCode);
@@ -95,7 +94,7 @@ function getMeta(plugin) {
95
94
  docs: {
96
95
  recommended,
97
96
  },
98
- schema: {},
97
+ schema: false,
99
98
  fixable,
100
99
  };
101
100
  }
package/lib/eslint.js CHANGED
@@ -19,6 +19,9 @@ const noConfigFound = (config, configError) => {
19
19
  if (configError)
20
20
  return false;
21
21
 
22
+ if (!config)
23
+ return true;
24
+
22
25
  return !keys(config.rules).length;
23
26
  };
24
27
 
@@ -70,8 +73,9 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
70
73
  return [code, places];
71
74
  }
72
75
 
76
+ // that's right, we disabled "putout" rules in "config"
77
+ // and now it located in eslint's cache
73
78
  !putout && disablePutout(finalConfig);
74
- // that's right, we disabled "putout" rules in "config" // and now it located in eslint's cache
75
79
 
76
80
  const results = await eslint.lintText(code, {
77
81
  filePath: name,
@@ -1,16 +1,16 @@
1
- import eslint from 'eslint/use-at-your-own-risk';
2
- import {findUpSync} from 'find-up';
1
+ import {dirname} from 'node:path';
2
+ import {loadESLint} from 'eslint';
3
+ import {findUp} from 'find-up';
3
4
 
4
- const {FlatESLint, LegacyESLint} = eslint;
5
-
6
- export const getESLint = ({name, fix, config, overrideConfigFile, ESLintOverride, find = findUpSync}) => {
7
- const eslint = chooseESLint({
5
+ export const getESLint = async ({name, fix, config, overrideConfigFile, loadESLintOverride, find = findUp, findFlat = find, findRC = find}) => {
6
+ const eslint = await chooseESLint({
8
7
  fix,
9
8
  name,
10
9
  config,
11
10
  overrideConfigFile,
12
- ESLintOverride,
13
- find,
11
+ loadESLintOverride,
12
+ findFlat,
13
+ findRC,
14
14
  });
15
15
 
16
16
  return {
@@ -19,29 +19,28 @@ export const getESLint = ({name, fix, config, overrideConfigFile, ESLintOverride
19
19
  };
20
20
  };
21
21
 
22
- function chooseESLint({name, config, fix, overrideConfigFile, ESLintOverride, find}) {
23
- const flatConfigPath = find('eslint.config.js');
24
-
25
- if (flatConfigPath)
26
- return getFlatESLint({
27
- ESLintOverride,
28
- name,
29
- config,
30
- overrideConfigFile: overrideConfigFile || flatConfigPath,
31
- fix,
32
- });
22
+ async function chooseESLint({name, config, fix, overrideConfigFile, loadESLintOverride, findFlat, findRC}) {
23
+ const runESLint = await getESLintRunner(name, {
24
+ overrideConfigFile,
25
+ findFlat,
26
+ findRC,
27
+ });
33
28
 
34
- return getOldESLint({
29
+ return await runESLint({
30
+ loadESLintOverride,
35
31
  name,
36
32
  config,
37
- ESLintOverride,
38
33
  overrideConfigFile,
39
34
  fix,
40
35
  });
41
36
  }
42
37
 
43
- function getOldESLint({fix, config, overrideConfigFile, ESLintOverride = LegacyESLint}) {
44
- const eslint = new ESLintOverride({
38
+ async function getOldESLint({fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
39
+ const ESLint = await loadESLintOverride({
40
+ useFlatConfig: false,
41
+ });
42
+
43
+ const eslint = new ESLint({
45
44
  fix,
46
45
  overrideConfig: {
47
46
  ignorePatterns: ['!.*'],
@@ -56,8 +55,12 @@ function getOldESLint({fix, config, overrideConfigFile, ESLintOverride = LegacyE
56
55
  return eslint;
57
56
  }
58
57
 
59
- function getFlatESLint({fix, config, overrideConfigFile, ESLintOverride = FlatESLint}) {
60
- const eslint = new ESLintOverride({
58
+ async function getFlatESLint({fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
59
+ const FlatESLint = await loadESLintOverride({
60
+ useFlatConfig: true,
61
+ });
62
+
63
+ const eslint = new FlatESLint({
61
64
  fix,
62
65
  overrideConfig: {
63
66
  ignores: ['!.*'],
@@ -70,3 +73,25 @@ function getFlatESLint({fix, config, overrideConfigFile, ESLintOverride = FlatES
70
73
 
71
74
  return eslint;
72
75
  }
76
+
77
+ const isFlat = (a) => a?.includes('config');
78
+
79
+ async function getESLintRunner(name, {findFlat, findRC, overrideConfigFile}) {
80
+ if (overrideConfigFile)
81
+ return isFlat(overrideConfigFile) ? getFlatESLint : getOldESLint;
82
+
83
+ const cwd = dirname(name);
84
+ const [rcConfig = '', flatConfig = ''] = await Promise.all([
85
+ findRC(['.eslintrc.json', '.eslintrc.js'], {
86
+ cwd,
87
+ }),
88
+ findFlat('eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs', {
89
+ cwd,
90
+ }),
91
+ ]);
92
+
93
+ if (rcConfig.length > flatConfig.length)
94
+ return getOldESLint;
95
+
96
+ return getFlatESLint;
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/eslint",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Wrapper that simplifies ESLint API and makes it compatible with 🐊Putout",
@@ -38,9 +38,9 @@
38
38
  ],
39
39
  "devDependencies": {
40
40
  "@putout/plugin-eslint-plugin": "*",
41
- "c8": "^8.0.0",
42
- "eslint": "^8.45.0",
43
- "eslint-plugin-n": "^16.0.0",
41
+ "c8": "^9.0.0",
42
+ "eslint": "^9.0.0",
43
+ "eslint-plugin-n": "^17.0.0",
44
44
  "eslint-plugin-putout": "^22.0.0",
45
45
  "just-camel-case": "^4.0.2",
46
46
  "lerna": "^6.0.1",
@@ -49,7 +49,7 @@
49
49
  "montag": "^1.0.0",
50
50
  "nodemon": "^3.0.1",
51
51
  "putout": "*",
52
- "supertape": "^9.0.0",
52
+ "supertape": "^10.0.0",
53
53
  "try-catch": "^3.0.0"
54
54
  },
55
55
  "license": "MIT",