@putout/eslint 3.1.0 → 3.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.
@@ -18,6 +18,7 @@ const prepare = (plugin, context, options) => (node) => {
18
18
  });
19
19
 
20
20
  const text = getText(node);
21
+
21
22
  const path = {
22
23
  text,
23
24
  node,
package/lib/eslint.js CHANGED
@@ -70,8 +70,9 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
70
70
  return [code, places];
71
71
  }
72
72
 
73
+ // that's right, we disabled "putout" rules in "config"
74
+ // and now it located in eslint's cache
73
75
  !putout && disablePutout(finalConfig);
74
- // that's right, we disabled "putout" rules in "config" // and now it located in eslint's cache
75
76
 
76
77
  const results = await eslint.lintText(code, {
77
78
  filePath: name,
@@ -1,16 +1,20 @@
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';
4
+ import process from 'node:process';
3
5
 
4
- const {FlatESLint, LegacyESLint} = eslint;
6
+ const CWD = process.cwd();
5
7
 
6
- export const getESLint = ({name, fix, config, overrideConfigFile, ESLintOverride, find = findUpSync}) => {
7
- const eslint = chooseESLint({
8
+ export const getESLint = async ({name, fix, config, overrideConfigFile, loadESLintOverride, find = findUp, findFlat = find, findRC = find}) => {
9
+ const cwd = dirname(name).replace(/^\./, CWD);
10
+ const eslint = await chooseESLint({
8
11
  fix,
9
- name,
12
+ cwd,
10
13
  config,
11
14
  overrideConfigFile,
12
- ESLintOverride,
13
- find,
15
+ loadESLintOverride,
16
+ findFlat,
17
+ findRC,
14
18
  });
15
19
 
16
20
  return {
@@ -19,29 +23,30 @@ export const getESLint = ({name, fix, config, overrideConfigFile, ESLintOverride
19
23
  };
20
24
  };
21
25
 
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
- });
26
+ async function chooseESLint({cwd, config, fix, overrideConfigFile, loadESLintOverride, findFlat, findRC}) {
27
+ const runESLint = await getESLintRunner({
28
+ cwd,
29
+ overrideConfigFile,
30
+ findFlat,
31
+ findRC,
32
+ });
33
33
 
34
- return getOldESLint({
35
- name,
34
+ return await runESLint({
35
+ loadESLintOverride,
36
+ cwd,
36
37
  config,
37
- ESLintOverride,
38
38
  overrideConfigFile,
39
39
  fix,
40
40
  });
41
41
  }
42
42
 
43
- function getOldESLint({fix, config, overrideConfigFile, ESLintOverride = LegacyESLint}) {
44
- const eslint = new ESLintOverride({
43
+ async function getOldESLint({cwd, fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
44
+ const ESLint = await loadESLintOverride({
45
+ useFlatConfig: false,
46
+ });
47
+
48
+ const eslint = new ESLint({
49
+ cwd,
45
50
  fix,
46
51
  overrideConfig: {
47
52
  ignorePatterns: ['!.*'],
@@ -56,8 +61,13 @@ function getOldESLint({fix, config, overrideConfigFile, ESLintOverride = LegacyE
56
61
  return eslint;
57
62
  }
58
63
 
59
- function getFlatESLint({fix, config, overrideConfigFile, ESLintOverride = FlatESLint}) {
60
- const eslint = new ESLintOverride({
64
+ async function getFlatESLint({cwd, fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
65
+ const FlatESLint = await loadESLintOverride({
66
+ useFlatConfig: true,
67
+ });
68
+
69
+ const eslint = new FlatESLint({
70
+ cwd,
61
71
  fix,
62
72
  overrideConfig: {
63
73
  ignores: ['!.*'],
@@ -70,3 +80,24 @@ function getFlatESLint({fix, config, overrideConfigFile, ESLintOverride = FlatES
70
80
 
71
81
  return eslint;
72
82
  }
83
+
84
+ const isFlat = (a) => a?.includes('config');
85
+
86
+ async function getESLintRunner({cwd, findFlat, findRC, overrideConfigFile}) {
87
+ if (overrideConfigFile)
88
+ return isFlat(overrideConfigFile) ? getFlatESLint : getOldESLint;
89
+
90
+ const [rcConfig = '', flatConfig = ''] = await Promise.all([
91
+ findRC(['.eslintrc.json', '.eslintrc.js'], {
92
+ cwd,
93
+ }),
94
+ findFlat(['eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs'], {
95
+ cwd,
96
+ }),
97
+ ]);
98
+
99
+ if (rcConfig.length > flatConfig.length)
100
+ return getOldESLint;
101
+
102
+ return getFlatESLint;
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/eslint",
3
- "version": "3.1.0",
3
+ "version": "3.3.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": "^9.0.0-alpha.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",