@putout/eslint 3.2.0 → 3.4.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/lib/eslint.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const process = require('process');
3
+ const process = require('node:process');
4
4
  const {simpleImport} = require('./simple-import.js');
5
5
  const tryToCatch = require('try-to-catch');
6
6
 
@@ -9,6 +9,7 @@ const eslintId = ' (eslint)';
9
9
  const overrideConfigFile = process.env.ESLINT_CONFIG_FILE;
10
10
  const noESLint = process.env.NO_ESLINT;
11
11
  const noESLintWarnings = process.env.NO_ESLINT_WARNINGS;
12
+ const NO_FLAT_CONFIG_FOUND = 'Could not find config file.';
12
13
 
13
14
  const WARNING = 1;
14
15
 
@@ -16,12 +17,12 @@ const noConfigFound = (config, configError) => {
16
17
  if (configError && configError.messageTemplate === 'no-config-found')
17
18
  return true;
18
19
 
20
+ if (configError?.message === NO_FLAT_CONFIG_FOUND)
21
+ return true;
22
+
19
23
  if (configError)
20
24
  return false;
21
25
 
22
- if (!config)
23
- return true;
24
-
25
26
  return !keys(config.rules).length;
26
27
  };
27
28
 
@@ -1,11 +1,15 @@
1
1
  import {dirname} from 'node:path';
2
2
  import {loadESLint} from 'eslint';
3
3
  import {findUp} from 'find-up';
4
+ import process from 'node:process';
5
+
6
+ const CWD = process.cwd();
4
7
 
5
8
  export const getESLint = async ({name, fix, config, overrideConfigFile, loadESLintOverride, find = findUp, findFlat = find, findRC = find}) => {
9
+ const cwd = dirname(name).replace(/^\./, CWD);
6
10
  const eslint = await chooseESLint({
7
11
  fix,
8
- name,
12
+ cwd,
9
13
  config,
10
14
  overrideConfigFile,
11
15
  loadESLintOverride,
@@ -19,8 +23,9 @@ export const getESLint = async ({name, fix, config, overrideConfigFile, loadESLi
19
23
  };
20
24
  };
21
25
 
22
- async function chooseESLint({name, config, fix, overrideConfigFile, loadESLintOverride, findFlat, findRC}) {
23
- const runESLint = await getESLintRunner(name, {
26
+ async function chooseESLint({cwd, config, fix, overrideConfigFile, loadESLintOverride, findFlat, findRC}) {
27
+ const runESLint = await getESLintRunner({
28
+ cwd,
24
29
  overrideConfigFile,
25
30
  findFlat,
26
31
  findRC,
@@ -28,19 +33,20 @@ async function chooseESLint({name, config, fix, overrideConfigFile, loadESLintOv
28
33
 
29
34
  return await runESLint({
30
35
  loadESLintOverride,
31
- name,
36
+ cwd,
32
37
  config,
33
38
  overrideConfigFile,
34
39
  fix,
35
40
  });
36
41
  }
37
42
 
38
- async function getOldESLint({fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
43
+ async function getOldESLint({cwd, fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
39
44
  const ESLint = await loadESLintOverride({
40
45
  useFlatConfig: false,
41
46
  });
42
47
 
43
48
  const eslint = new ESLint({
49
+ cwd,
44
50
  fix,
45
51
  overrideConfig: {
46
52
  ignorePatterns: ['!.*'],
@@ -55,12 +61,13 @@ async function getOldESLint({fix, config, overrideConfigFile, loadESLintOverride
55
61
  return eslint;
56
62
  }
57
63
 
58
- async function getFlatESLint({fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
64
+ async function getFlatESLint({cwd, fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
59
65
  const FlatESLint = await loadESLintOverride({
60
66
  useFlatConfig: true,
61
67
  });
62
68
 
63
69
  const eslint = new FlatESLint({
70
+ cwd,
64
71
  fix,
65
72
  overrideConfig: {
66
73
  ignores: ['!.*'],
@@ -76,21 +83,23 @@ async function getFlatESLint({fix, config, overrideConfigFile, loadESLintOverrid
76
83
 
77
84
  const isFlat = (a) => a?.includes('config');
78
85
 
79
- async function getESLintRunner(name, {findFlat, findRC, overrideConfigFile}) {
86
+ async function getESLintRunner({cwd, findFlat, findRC, overrideConfigFile}) {
80
87
  if (overrideConfigFile)
81
88
  return isFlat(overrideConfigFile) ? getFlatESLint : getOldESLint;
82
89
 
83
- const cwd = dirname(name);
84
90
  const [rcConfig = '', flatConfig = ''] = await Promise.all([
85
91
  findRC(['.eslintrc.json', '.eslintrc.js'], {
86
92
  cwd,
87
93
  }),
88
- findFlat('eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs', {
94
+ findFlat(['eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs'], {
89
95
  cwd,
90
96
  }),
91
97
  ]);
92
98
 
93
- if (rcConfig.length > flatConfig.length)
99
+ const noConfigFound = !rcConfig && !flatConfig;
100
+ const foundRConfig = rcConfig.length > flatConfig.length;
101
+
102
+ if (noConfigFound || foundRConfig)
94
103
  return getOldESLint;
95
104
 
96
105
  return getFlatESLint;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/eslint",
3
- "version": "3.2.0",
3
+ "version": "3.4.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",