@putout/eslint 4.1.0 β†’ 5.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/README.md CHANGED
@@ -29,7 +29,7 @@ NO_ESLINT_WARNINGS=1 putout --fix lib
29
29
  **ESLint** begins his work as a formatter when 🐊**Putout** done his transformations. That's why it used a lot in different parts of application, for testing purpose and using **API** in a simplest possible way. You can access it with:
30
30
 
31
31
  ```js
32
- import eslint from '@putout/eslint';
32
+ import {eslint} from '@putout/eslint';
33
33
  ````
34
34
 
35
35
  To use it simply write:
@@ -84,17 +84,17 @@ You can also simplify creating of plugins for **ESLint** with help of `createPlu
84
84
  So it must contain classic `4` methods:
85
85
 
86
86
  ```js
87
- module.exports.report = () => 'debugger statement should not be used';
87
+ export const report = () => 'debugger statement should not be used';
88
88
 
89
- module.exports.fix = (path) => {
89
+ export const fix = (path) => {
90
90
  return '';
91
91
  };
92
92
 
93
- module.exports.include = () => [
93
+ export const include = () => [
94
94
  'DebuggerStatement',
95
95
  ];
96
96
 
97
- module.exports.filter = (path) => {
97
+ export const filter = (path) => {
98
98
  return true;
99
99
  };
100
100
  ```
@@ -110,19 +110,19 @@ Take a look at more sophisticated example, rule [`remove-duplicate-extensions`](
110
110
  ```js
111
111
  const getValue = ({source}) => source?.value;
112
112
 
113
- module.exports.report = () => 'Avoid duplicate extensions in relative imports';
114
- module.exports.include = () => [
113
+ export const report = () => 'Avoid duplicate extensions in relative imports';
114
+ export const include = () => [
115
115
  'ImportDeclaration',
116
116
  'ImportExpression',
117
117
  'ExportAllDeclaration',
118
118
  'ExportNamedDeclaration',
119
119
  ];
120
120
 
121
- module.exports.fix = ({text}) => {
121
+ export const fix = ({text}) => {
122
122
  return text.replace('.js.js', '.js');
123
123
  };
124
124
 
125
- module.exports.filter = ({node}) => {
125
+ export const filter = ({node}) => {
126
126
  const value = getValue(node);
127
127
  return /\.js\.js/.test(value);
128
128
  };
@@ -131,21 +131,19 @@ module.exports.filter = ({node}) => {
131
131
  To use it just add couple lines to your main plugin file:
132
132
 
133
133
  ```js
134
- const {createPlugin} = require('@putout/eslint/create-plugin');
134
+ import {createPlugin} from '@putout/eslint/create-plugin';
135
135
 
136
136
  const createRule = (a) => ({
137
137
  [a]: createPlugin(require(`./${a}`)),
138
138
  });
139
139
 
140
- module.exports.rules = {
141
- ...createRule('remove-duplicate-extensions'),
142
- };
140
+ module.exports.rules = createRule('remove-duplicate-extensions');
143
141
  ```
144
142
 
145
143
  Or just:
146
144
 
147
145
  ```js
148
- const {createPlugin} = require('@putout/eslint/create-plugin');
146
+ import {createPlugin} from '@putout/eslint/create-plugin';
149
147
 
150
148
  module.exports.rules = {
151
149
  'remove-duplicate-extensions': createPlugin(require('./remove-duplicate-extensions')),
@@ -157,9 +155,9 @@ module.exports.rules = {
157
155
  When you need to run **ESLint** with one plugin (*rule*), just use `lint` it will do the thing.
158
156
 
159
157
  ```js
160
- const lint = require('@putout/eslint/lint');
161
- const {createPlugin} = require('@putout/eslint/create-plugin');
162
- const removeDebugger = require('./remove-debugger');
158
+ import {lint} from '@putout/eslint/lint';
159
+ import {createPlugin} from '@putout/eslint/create-plugin';
160
+ import * as removeDebugger from 'remove-debugger';
163
161
 
164
162
  const [code, places] = lint('debugger', {
165
163
  fix: true, // default
@@ -172,7 +170,7 @@ const [code, places] = lint('debugger', {
172
170
  When you want to skip plugins, and just provide `options` and `filename` you can:
173
171
 
174
172
  ```js
175
- const lint = require('@putout/eslint/lint');
173
+ import {lint} from '@putout/eslint/lint';
176
174
 
177
175
  const [code, places] = lint('debugger', {
178
176
  filename: 'index.js',
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  const prepare = (plugin, context, options) => (node) => {
4
2
  const {filter, report} = plugin;
5
3
  const {sourceCode, filename} = context;
@@ -64,7 +62,7 @@ const prepareFix = (fix, {node, text, getText, filename}) => (fixer) => {
64
62
  ];
65
63
  };
66
64
 
67
- module.exports.createPlugin = (plugin) => {
65
+ export const createPlugin = (plugin) => {
68
66
  const meta = getMeta(plugin);
69
67
 
70
68
  return {
@@ -108,7 +106,7 @@ function getTraversers(names, plugin) {
108
106
  return traversers;
109
107
  }
110
108
 
111
- const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) => {
109
+ export const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) => {
112
110
  let spaces = '';
113
111
  let i = 0;
114
112
 
@@ -121,9 +119,7 @@ const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) =>
121
119
  return spaces.slice(1);
122
120
  };
123
121
 
124
- module.exports.createGetSpacesBeforeNode = createGetSpacesBeforeNode;
125
-
126
- const createGetSpacesAfterNode = ({getText}) => (node, text = getText(node)) => {
122
+ export const createGetSpacesAfterNode = ({getText}) => (node, text = getText(node)) => {
127
123
  const reg = /^[ \n;]+$/;
128
124
 
129
125
  if (isLastNodeInBody(node))
@@ -138,8 +134,6 @@ const createGetSpacesAfterNode = ({getText}) => (node, text = getText(node)) =>
138
134
  return spaces.slice(0, -1);
139
135
  };
140
136
 
141
- module.exports.createGetSpacesAfterNode = createGetSpacesAfterNode;
142
-
143
137
  function isLastNodeInBody(node) {
144
138
  if (node.parent.body) {
145
139
  const {length} = node.parent.body;
package/lib/eslint.js CHANGED
@@ -1,22 +1,18 @@
1
- 'use strict';
2
-
3
- const {join} = require('node:path');
4
- const process = require('node:process');
5
- const tryToCatch = require('try-to-catch');
6
- const once = require('once');
7
-
8
- const {simpleImport} = require('./simple-import.js');
9
- const {isIgnored} = require('./ignore');
1
+ import {join} from 'node:path';
2
+ import process from 'node:process';
3
+ import {tryToCatch} from 'try-to-catch';
4
+ import {simpleImport as _simpleImport} from './simple-import.js';
5
+ import {isIgnored} from './ignore.js';
10
6
 
11
7
  const {keys} = Object;
12
8
  const eslintId = ' (eslint)';
13
9
 
14
- const isNoESLint = once(() => process.env.NO_ESLINT);
15
- const noESLintWarnings = process.env.NO_ESLINT_WARNINGS;
16
- const {ESLINT_CONFIG_FILE} = process.env;
10
+ const {env} = process;
11
+ const isNoESLint = () => env.NO_ESLINT;
12
+ const isNoESLintWarnings = () => env.NO_ESLINT_WARNINGS;
17
13
 
18
14
  const dir = process.cwd();
19
- const overrideConfigFile = parseOverride(dir, ESLINT_CONFIG_FILE);
15
+ const overrideConfigFile = () => parseOverride(dir, env.ESLINT_CONFIG_FILE);
20
16
 
21
17
  const NO_FLAT_CONFIG_FOUND = 'Could not find config file.';
22
18
  const WARNING = 1;
@@ -40,7 +36,16 @@ const noConfigFound = (config, configError) => {
40
36
  return !keys(config.rules).length;
41
37
  };
42
38
 
43
- module.exports = async ({name, code, fix, config, putout = false}) => {
39
+ export const eslint = async (overrides = {}) => {
40
+ const {
41
+ name,
42
+ code,
43
+ fix,
44
+ config,
45
+ putout = false,
46
+ simpleImport = _simpleImport,
47
+ } = overrides;
48
+
44
49
  const noChanges = [
45
50
  code,
46
51
  [],
@@ -49,7 +54,7 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
49
54
  if (isNoESLint())
50
55
  return noChanges;
51
56
 
52
- const [, ESLint] = await tryToCatch(simpleImport, './get-eslint.mjs');
57
+ const [, ESLint] = await tryToCatch(simpleImport, './get-eslint.js');
53
58
 
54
59
  if (!ESLint)
55
60
  return noChanges;
@@ -60,7 +65,7 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
60
65
  name,
61
66
  fix,
62
67
  config,
63
- overrideConfigFile,
68
+ overrideConfigFile: overrideConfigFile(),
64
69
  });
65
70
 
66
71
  const [configError, finalConfig] = await tryToCatch(eslint.calculateConfigForFile, name);
@@ -90,23 +95,21 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
90
95
  const [report] = results;
91
96
  const {output = code} = report;
92
97
 
93
- const places = report
94
- .messages
98
+ const places = report.messages
95
99
  .map(convertToPlace)
96
100
  .filter(Boolean);
97
101
 
98
102
  return [output, places];
99
103
  };
100
104
 
101
- module.exports._noConfigFound = noConfigFound;
105
+ export const _noConfigFound = noConfigFound;
102
106
 
103
107
  const parseRule = (rule) => rule || 'parser';
104
108
 
105
- module.exports.convertToPlace = convertToPlace;
106
- function convertToPlace({ruleId = 'parser', message, line = 0, column = 0, severity}) {
109
+ export function convertToPlace({ruleId = 'parser', message, line = 0, column = 0, severity}) {
107
110
  const rule = `${parseRule(ruleId)}${eslintId}`;
108
111
 
109
- if (severity === WARNING && noESLintWarnings)
112
+ if (severity === WARNING && isNoESLintWarnings())
110
113
  return null;
111
114
 
112
115
  if (isIgnored(message))
@@ -19,8 +19,7 @@ export const getESLint = async ({name, fix, config = [], overrideConfigFile, loa
19
19
  overrideConfig: [
20
20
  ...maybeArray(config), {
21
21
  ignores: ['!.*'],
22
- }
23
- ,
22
+ },
24
23
  ],
25
24
  ...overrideConfigFile && {
26
25
  overrideConfigFile,
package/lib/ignore.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  const MESSAGES = [
4
2
  `Parsing error: Cannot use keyword 'await' outside an async function`,
5
3
  `Parsing error: The keyword 'yield' is reserved`,
@@ -7,7 +5,7 @@ const MESSAGES = [
7
5
  `Parsing error: Unexpected reserved word 'yield'`,
8
6
  ];
9
7
 
10
- module.exports.isIgnored = (message) => {
8
+ export const isIgnored = (message) => {
11
9
  for (const current of MESSAGES) {
12
10
  if (message.includes(current))
13
11
  return true;
package/lib/lint/index.js CHANGED
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import {Linter} from 'eslint';
2
+ import {convertToPlace} from '../eslint.js';
2
3
 
3
- const {Linter} = require('eslint');
4
- const {convertToPlace} = require('../eslint.js');
5
-
6
- module.exports.lint = (source, {fix = true, plugins, filename, options = []}) => {
4
+ export const lint = (source, {fix = true, plugins, filename, options = []}) => {
7
5
  const linter = new Linter({
8
6
  configType: 'flat',
9
7
  });
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.simpleImport = async (url) => {
1
+ export const simpleImport = async (url) => {
4
2
  const result = await import(url);
5
3
  return result.default || result;
6
4
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/eslint",
3
- "version": "4.1.0",
4
- "type": "commonjs",
3
+ "version": "5.0.1",
4
+ "type": "module",
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",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/eslint#readme",
@@ -30,33 +30,31 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "once": "^1.4.0",
33
- "try-to-catch": "^3.0.1"
33
+ "try-to-catch": "^4.0.0"
34
34
  },
35
35
  "keywords": [
36
36
  "putout",
37
37
  "eslint"
38
38
  ],
39
39
  "devDependencies": {
40
- "@putout/eslint-flat": "^2.0.0",
40
+ "@putout/eslint-flat": "^3.0.0",
41
41
  "@putout/plugin-eslint-plugin": "*",
42
42
  "c8": "^10.0.0",
43
- "eslint": "^9.0.0",
43
+ "eslint": "^10.0.0-alpha.0",
44
44
  "eslint-plugin-n": "^17.0.0",
45
- "eslint-plugin-putout": "^25.0.1",
46
- "madrun": "^10.0.0",
47
- "mock-require": "^3.0.3",
45
+ "eslint-plugin-putout": "^29.0.0",
46
+ "madrun": "^11.0.0",
48
47
  "montag": "^1.0.0",
49
48
  "nodemon": "^3.0.1",
50
49
  "putout": "*",
51
- "supertape": "^10.0.0",
52
- "try-catch": "^3.0.0"
50
+ "supertape": "^11.0.3"
53
51
  },
54
52
  "peerDependencies": {
55
- "eslint": ">=8"
53
+ "eslint": ">=9"
56
54
  },
57
55
  "license": "MIT",
58
56
  "engines": {
59
- "node": ">=18"
57
+ "node": ">=20"
60
58
  },
61
59
  "publishConfig": {
62
60
  "access": "public"