Skip to content

Commit 32f1ff0

Browse files
committed
feature: @putout/plugin-remove-useless-spread: migrate to ESM
1 parent 7de443d commit 32f1ff0

11 files changed

Lines changed: 39 additions & 51 deletions

File tree

File renamed without changes.

packages/plugin-remove-useless-spread/eslint.config.mjs renamed to packages/plugin-remove-useless-spread/eslint.config.js

File renamed without changes.

packages/plugin-remove-useless-spread/lib/array/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
'use strict';
1+
import {types} from 'putout';
22

3-
const {types} = require('putout');
43
const {
54
isNumericLiteral,
65
isMemberExpression,
76
isIdentifier,
87
} = types;
98

10-
module.exports.report = () => `Avoid useless spread '...'`;
9+
export const report = () => `Avoid useless spread '...'`;
1110

12-
module.exports.match = () => ({
11+
export const match = () => ({
1312
'[...Array(__a)]': ({__a}) => !isNumericLiteral(__a),
1413
'[...__a(__args)]': ({__a}) => {
1514
if (!isMemberExpression(__a))
@@ -30,7 +29,7 @@ module.exports.match = () => ({
3029
},
3130
});
3231

33-
module.exports.replace = () => ({
32+
export const replace = () => ({
3433
'[...Array(__a)]': 'Array(__a)',
3534
'for (const __a of [...__b]) __c': 'for (const __a of __b) __c',
3635
'Array.from([...__a])': 'Array.from(__a)',

packages/plugin-remove-useless-spread/lib/array/index.spec.js

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

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

packages/plugin-remove-useless-spread/lib/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
1+
import * as array from './array/index.js';
2+
import * as object from './object/index.js';
3+
import * as nested from './nested/index.js';
24

3-
const array = require('./array');
4-
const object = require('./object');
5-
const nested = require('./nested');
6-
7-
module.exports.rules = {
5+
export const rules = {
86
array,
97
object,
108
nested,

packages/plugin-remove-useless-spread/lib/nested/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {remove, insertAfter} = operator;
54

6-
module.exports.report = () => `Remove useless nested spread`;
5+
export const report = () => `Remove useless nested spread`;
76

8-
module.exports.fix = ({path, argPath}) => {
7+
export const fix = ({path, argPath}) => {
98
const elements = argPath.get('elements');
109

1110
for (const element of elements.reverse())
@@ -14,7 +13,7 @@ module.exports.fix = ({path, argPath}) => {
1413
remove(path);
1514
};
1615

17-
module.exports.traverse = ({push}) => ({
16+
export const traverse = ({push}) => ({
1817
SpreadElement(path) {
1918
const {parentPath} = path;
2019
const argPath = path.get('argument');

packages/plugin-remove-useless-spread/lib/nested/index.spec.js

Lines changed: 3 additions & 5 deletions
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
['nested', plugin],
97
],
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
'use strict';
1+
import {types} from 'putout';
22

3-
const {types} = require('putout');
43
const {
54
isCallExpression,
65
isReturnStatement,
76
isSpreadElement,
87
} = types;
98

10-
module.exports.report = () => `Avoid useless spread '...'`;
9+
export const report = () => `Avoid useless spread '...'`;
1110

12-
module.exports.filter = (path) => {
11+
export const exclude = () => [
12+
'({...__b && {__c: __d}})',
13+
'__a = {...__a}',
14+
];
15+
16+
export const replace = () => ({
17+
'({...__a})': '__a',
18+
});
19+
20+
export const filter = (path) => {
1321
const {node, parentPath} = path;
1422
const [first] = node.properties;
1523

@@ -27,11 +35,3 @@ module.exports.filter = (path) => {
2735
return isReturnStatement(path.parentPath);
2836
};
2937

30-
module.exports.exclude = () => [
31-
'({...__b && {__c: __d}})',
32-
'__a = {...__a}',
33-
];
34-
35-
module.exports.replace = () => ({
36-
'({...__a})': '__a',
37-
});

packages/plugin-remove-useless-spread/lib/object/index.spec.js

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

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

packages/plugin-remove-useless-spread/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@putout/plugin-remove-useless-spread",
33
"version": "12.0.0",
4-
"type": "commonjs",
4+
"type": "module",
55
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
66
"description": "🐊Putout plugin adds ability to remove useless spread",
77
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-spread#readme",
@@ -43,11 +43,11 @@
4343
"madrun": "^11.0.0"
4444
},
4545
"peerDependencies": {
46-
"putout": ">=38"
46+
"putout": ">=40"
4747
},
4848
"license": "MIT",
4949
"engines": {
50-
"node": ">=18"
50+
"node": ">=20"
5151
},
5252
"publishConfig": {
5353
"access": "public"

0 commit comments

Comments
 (0)