Skip to content

Commit 62dc1ff

Browse files
committed
feature: @putout/plugin-remove-useless-variabes: migrate to ESM
1 parent d17d684 commit 62dc1ff

File tree

17 files changed

+55
-81
lines changed

17 files changed

+55
-81
lines changed
File renamed without changes.

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

File renamed without changes.

packages/plugin-remove-useless-variables/lib/assignment/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict';
2-
3-
const {types, operator} = require('putout');
1+
import {types, operator} from 'putout';
42

53
const {getBinding} = operator;
64
const {isIdentifier} = types;
75

8-
module.exports.report = () => `Avoid useless assignment`;
6+
export const report = () => `Avoid useless assignment`;
97

10-
module.exports.match = () => ({
8+
export const match = () => ({
119
'(__a = __b).__c': ({__a}, path) => {
1210
if (!isIdentifier(__a))
1311
return false;
@@ -23,6 +21,6 @@ module.exports.match = () => ({
2321
},
2422
});
2523

26-
module.exports.replace = () => ({
24+
export const replace = () => ({
2725
'(__a = __b).__c': '__b.__c',
2826
});

packages/plugin-remove-useless-variables/lib/assignment/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
['assignment', plugin],
97
],

packages/plugin-remove-useless-variables/lib/declaration/index.js

Lines changed: 4 additions & 5 deletions
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
compare,
65
remove,
@@ -15,9 +14,9 @@ const getBody = (path) => {
1514
return body.body || body;
1615
};
1716

18-
module.exports.report = () => `Avoid useless declarations`;
17+
export const report = () => `Avoid useless declarations`;
1918

20-
module.exports.match = ({options}) => ({
19+
export const match = ({options}) => ({
2120
'return __a': ({__a}, path) => {
2221
const binding = path.scope.getAllBindings()[__a.name];
2322

@@ -95,7 +94,7 @@ module.exports.match = ({options}) => ({
9594
},
9695
});
9796

98-
module.exports.replace = () => ({
97+
export const replace = () => ({
9998
'return __a': ({__a}, path) => {
10099
const binding = path.scope.getAllBindings()[__a.name];
101100
const [ref] = binding.referencePaths;

packages/plugin-remove-useless-variables/lib/declaration/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
['remove-useless-variables/declarations', plugin],
97
],

packages/plugin-remove-useless-variables/lib/destruct/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const {types, operator} = require('putout');
1+
import {types, operator} from 'putout';
42

53
const {
64
isIdentifier,
@@ -26,11 +24,11 @@ const getKeyLength = (a) => {
2624

2725
const sum = (a, b) => a + getKeyLength(b);
2826

29-
module.exports.report = (path) => {
27+
export const report = (path) => {
3028
return `Remove useless variable '${path.node.declarations[0].init.name}'`;
3129
};
3230

33-
module.exports.match = () => ({
31+
export const match = () => ({
3432
'const __object = __a': ({__a, __object}, path) => {
3533
const {parentPath} = path.parentPath;
3634

@@ -68,7 +66,7 @@ module.exports.match = () => ({
6866
},
6967
});
7068

71-
module.exports.replace = () => ({
69+
export const replace = () => ({
7270
'const __object = __a': ({__object}, path) => {
7371
replaceWith(path.parentPath.parentPath.get('params.0'), __object);
7472
},

packages/plugin-remove-useless-variables/lib/destruct/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 destruct from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const destruct = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['remove-useless-variables/destruct', destruct],
97
],
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {getTemplateValues} = operator;
54
const FN = 'const __a = function __a(__args) {__body}';
65

7-
module.exports.report = (path) => {
6+
export const report = (path) => {
87
const {__a} = getTemplateValues(path, FN);
98
return `Avoid duplicate declaration of '${__a.name}'`;
109
};
1110

12-
module.exports.replace = () => ({
11+
export const replace = () => ({
1312
'const __a = function __a(__args) {__body}': 'function __a(__args){__body}',
1413
});

packages/plugin-remove-useless-variables/lib/duplicate/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
['duplicate', plugin],
97
],

0 commit comments

Comments
 (0)