Skip to content

Commit e71ea95

Browse files
committed
feature: @putout/plugin-eslint: convert to ESM
1 parent 83d6c4f commit e71ea95

File tree

66 files changed

+255
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+255
-367
lines changed

packages/plugin-eslint/.madrun.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
1+
import {run} from 'madrun';
22

3-
const {run} = require('madrun');
4-
5-
module.exports = {
3+
export default {
64
'test': () => `tape 'test/*.js' 'lib/**/*.spec.js'`,
75
'watch:test': async () => `nodemon -w lib -x "${await run('test')}"`,
86
'lint': () => `putout .`,

packages/plugin-eslint/.putout.json

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"rules": {
3-
"putout/apply-namespace-specifier": "off"
4-
},
52
"match": {
63
"*.md": {
74
"putout/convert-match-to-function": "off",
+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import {safeAlign} from 'eslint-plugin-putout';
22
import {defineConfig} from 'eslint/config';
33

4-
export default defineConfig([
5-
safeAlign, {
6-
ignores: ['**/fixture'],
7-
},
8-
]);
4+
export default defineConfig([safeAlign, {}]);

packages/plugin-eslint/lib/add-putout/index.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
'use strict';
2-
3-
const {types, operator} = require('putout');
4-
const {
1+
import {types, operator} from 'putout';
2+
import {
53
getExtends,
64
getPlugins,
75
isExtends,
86
isPlugins,
9-
} = require('../get.js');
7+
} from '../get.js';
108

119
const {__json} = operator;
1210
const {stringLiteral} = types;
1311

14-
module.exports.report = () => `Add 'putout' to 'plugins' and 'extends'`;
12+
export const report = () => `Add 'putout' to 'plugins' and 'extends'`;
1513

16-
module.exports.match = () => ({
14+
export const match = () => ({
1715
[__json]: ({__object}) => {
1816
if (!isExtends(__object) || !isPlugins(__object))
1917
return false;
@@ -27,7 +25,7 @@ module.exports.match = () => ({
2725
},
2826
});
2927

30-
module.exports.replace = () => ({
28+
export const replace = () => ({
3129
[__json]: ({__object}, path) => {
3230
getExtends(__object).push(stringLiteral('putout:plugin/safe+align'));
3331
getPlugins(__object).push(stringLiteral('putout'));

packages/plugin-eslint/lib/add-putout/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('./index.js');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
'eslint/add-putout': plugin,
86
});
97

packages/plugin-eslint/lib/apply-create-eslint-config/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
'use strict';
1+
import {types, operator} from 'putout';
22

3-
const {types, operator} = require('putout');
43
const {replaceWith} = operator;
54
const {isSpreadElement} = types;
65

7-
module.exports.report = () => `Use 'createESLintConfig()' instead of spread ('...')`;
6+
export const report = () => `Use 'createESLintConfig()' instead of spread ('...')`;
87

9-
module.exports.match = () => ({
8+
export const match = () => ({
109
'module.exports = __array': hasSpreads({
1110
selector: 'right.elements',
1211
}),
@@ -15,7 +14,7 @@ module.exports.match = () => ({
1514
}),
1615
});
1716

18-
module.exports.replace = () => ({
17+
export const replace = () => ({
1918
'module.exports = __array': extractSpreads({
2019
selector: 'right.elements',
2120
template: 'module.exports = createESLintConfig(__array)',

packages/plugin-eslint/lib/apply-create-eslint-config/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-create-eslint-config', plugin],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
1+
export const report = () => `Use 'defineConfig' instead of 'createESLintConfig'`;
22

3-
module.exports.report = () => `Use 'defineConfig' instead of 'createESLintConfig'`;
4-
5-
module.exports.replace = () => ({
3+
export const replace = () => ({
64
'createESLintConfig(__args)': 'defineConfig(__args)',
75
});

packages/plugin-eslint/lib/apply-define-config/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-define-config', plugin],
97
],

packages/plugin-eslint/lib/apply-dir-to-flat/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {isESM} = operator;
54
const createName = (a) => isESM(a) ? 'import.meta.url' : '__dirname';
65

7-
module.exports.report = () => `Add '__dirname/import.meta.url' as first argument`;
6+
export const report = () => `Add '__dirname/import.meta.url' as first argument`;
87

9-
module.exports.replace = () => ({
8+
export const replace = () => ({
109
'matchToFlatDir(__a)': (vars, path) => {
1110
const name = createName(path);
1211
return `matchToFlatDir(${name}, __a)`;

packages/plugin-eslint/lib/apply-dir-to-flat/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-dir-to-flat', plugin],
97
],

packages/plugin-eslint/lib/apply-ignores/index.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
2-
3-
const {
1+
import {
42
template,
53
types,
64
operator,
7-
} = require('putout');
5+
} from 'putout';
86

97
const {stringify} = JSON;
108
const {getProperties, __json} = operator;
@@ -22,9 +20,9 @@ const createIgnoresLegacy = (list) => template.ast(`({
2220
"ignorePatterns": ${stringify(list)},
2321
})`);
2422

25-
module.exports.report = () => `Ignore 'fixture'`;
23+
export const report = () => `Ignore 'fixture'`;
2624

27-
module.exports.match = () => ({
25+
export const match = () => ({
2826
'module.exports = __a': isId,
2927
'export default __a': isId,
3028
[__json]: (vars, path) => {
@@ -35,7 +33,7 @@ module.exports.match = () => ({
3533
},
3634
});
3735

38-
module.exports.replace = ({options}) => {
36+
export const replace = ({options}) => {
3937
const {ignores = DEFAULT} = options;
4038

4139
return {

packages/plugin-eslint/lib/apply-ignores/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-ignores', plugin],
97
],

packages/plugin-eslint/lib/apply-match-to-flat/index.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
2-
3-
const {
1+
import {
42
template,
53
operator,
64
types,
7-
} = require('putout');
5+
} from 'putout';
86

97
const {
108
identifier,
@@ -23,13 +21,13 @@ const {
2321
__json,
2422
} = operator;
2523

26-
module.exports.report = () => `Apply 'matchToFlat()'`;
24+
export const report = () => `Apply 'matchToFlat()'`;
2725

2826
const createMatchToFlat = template('export const match = %%match%%');
2927

30-
module.exports.exclude = () => [__json];
28+
export const exclude = () => [__json];
3129

32-
module.exports.fix = ({objects}) => {
30+
export const fix = ({objects}) => {
3331
const statementPath = objects[0].find(isStatement);
3432
const match = objectExpression([]);
3533
let added = false;
@@ -55,7 +53,7 @@ module.exports.fix = ({objects}) => {
5553
}));
5654
};
5755

58-
module.exports.traverse = ({push, pathStore, store}) => ({
56+
export const traverse = ({push, pathStore, store}) => ({
5957
ObjectExpression(path) {
6058
if (!path.parentPath.isArrayExpression())
6159
return;

packages/plugin-eslint/lib/apply-match-to-flat/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-match-to-flat', plugin],
97
],

packages/plugin-eslint/lib/apply-safe-align/index.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict';
2-
3-
const {operator} = require('putout');
4-
const {getRules, getExtends} = require('../get.js');
1+
import {operator} from 'putout';
2+
import {getRules, getExtends} from '../get.js';
53

64
const {remove, __json} = operator;
75

8-
module.exports.report = () => 'Use "putout/safe+align" instead of "putout/safe"';
6+
export const report = () => 'Use "putout/safe+align" instead of "putout/safe"';
97

10-
module.exports.match = () => ({
8+
export const match = () => ({
119
[__json]: ({__object}) => {
1210
const elements = getExtends(__object);
1311

@@ -27,7 +25,7 @@ const isRules = (path) => path.get('key').isStringLiteral({
2725
value: 'rules',
2826
});
2927

30-
module.exports.replace = () => ({
28+
export const replace = () => ({
3129
[__json]: ({__object}, path) => {
3230
const elements = getExtends(__object);
3331
const rules = getRules(__object);

packages/plugin-eslint/lib/apply-safe-align/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as convertIdeToSafe from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const convertIdeToSafe = require('./index.js');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
'eslint/convert-safe-to-safe-align': convertIdeToSafe,
86
});
97

packages/plugin-eslint/lib/convert-export-match-to-declaration/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict';
1+
import {operator, template} from 'putout';
22

3-
const {operator, template} = require('putout');
43
const {
54
replaceWith,
65
insertAfter,
@@ -10,12 +9,12 @@ const {
109
const MATCH = 'module.exports.match = __object';
1110
const DEFAULT = 'module.exports = __a';
1211

13-
module.exports.report = () => `Export 'match' at end of file in CommonJS`;
12+
export const report = () => `Export 'match' at end of file in CommonJS`;
1413

1514
const declareMatch = template('const match = %%match%%');
1615
const exportMatch = template.ast('module.exports.match = match');
1716

18-
module.exports.fix = ({path, moduleExports}) => {
17+
export const fix = ({path, moduleExports}) => {
1918
const {right} = path.node;
2019

2120
replaceWith(path, declareMatch({
@@ -25,7 +24,7 @@ module.exports.fix = ({path, moduleExports}) => {
2524
insertAfter(moduleExports, exportMatch);
2625
};
2726

28-
module.exports.traverse = ({pathStore, push}) => ({
27+
export const traverse = ({pathStore, push}) => ({
2928
[MATCH]: storeIfWasNot({
3029
pathStore,
3130
}),

packages/plugin-eslint/lib/convert-export-match-to-declaration/index.spec.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
3+
import * as slice from '../remove-useless-slice/index.js';
24

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
const slice = require('../remove-useless-slice');
6-
7-
const test = createTest(__dirname, {
5+
const test = createTest(import.meta.url, {
86
plugins: [
97
['convert-export-match-to-declaration', plugin],
108
],

packages/plugin-eslint/lib/convert-files-to-array/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict';
1+
import {types, operator} from 'putout';
22

3-
const {types, operator} = require('putout');
43
const {
54
isArrayExpression,
65
isObjectExpression,
@@ -13,7 +12,7 @@ const {
1312
compare,
1413
} = operator;
1514

16-
module.exports.report = ({main}) => {
15+
export const report = ({main}) => {
1716
const message = `Convert 'files' to an array`;
1817

1918
if (isObjectExpression(main))
@@ -22,11 +21,11 @@ module.exports.report = ({main}) => {
2221
return `${message} to simplify migrating to FlatConfig`;
2322
};
2423

25-
module.exports.fix = ({path, value}) => {
24+
export const fix = ({path, value}) => {
2625
path.node.value = arrayExpression([value]);
2726
};
2827

29-
module.exports.traverse = ({push}) => ({
28+
export const traverse = ({push}) => ({
3029
__object: traverseFiles(push, 'flat'),
3130
[__json]: traverseFiles(push),
3231
});

packages/plugin-eslint/lib/convert-files-to-array/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-files-to-array', plugin],
97
],

0 commit comments

Comments
 (0)