Skip to content

Commit d13ee4a

Browse files
committed
feature: @putout/plugin-parens: migrate to ESM
1 parent 67631d7 commit d13ee4a

File tree

15 files changed

+48
-70
lines changed

15 files changed

+48
-70
lines changed

packages/plugin-parens/lib/add-missing-for-assign/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
unaryExpression,
65
binaryExpression,
@@ -13,9 +12,9 @@ const {
1312

1413
const {replaceWith, addParens} = operator;
1514

16-
module.exports.report = () => `SyntaxError: Invalid left-hand side in assignment expression`;
15+
export const report = () => `SyntaxError: Invalid left-hand side in assignment expression`;
1716

18-
module.exports.fix = (path) => {
17+
export const fix = (path) => {
1918
const {
2019
left,
2120
right,
@@ -53,7 +52,7 @@ module.exports.fix = (path) => {
5352
addParens(path);
5453
};
5554

56-
module.exports.traverse = ({push}) => ({
55+
export const traverse = ({push}) => ({
5756
AssignmentExpression(path) {
5857
if (isLogicalExpression(path.node.left))
5958
push(path);

packages/plugin-parens/lib/add-missing-for-assign/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
['add-missing-for-assign', plugin],
97
],

packages/plugin-parens/lib/add-missing-for-await/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
'use strict';
2-
3-
const {
1+
import {
42
print,
53
types,
64
operator,
7-
} = require('putout');
5+
} from 'putout';
86

97
const {awaitExpression} = types;
108
const {replaceWith, addParens} = operator;
119

12-
module.exports.report = (path) => {
10+
export const report = (path) => {
1311
const line = print(path.get('argument.callee'));
1412
return `TypeError: '${line}' is not a function`;
1513
};
1614

17-
module.exports.fix = (path) => {
15+
export const fix = (path) => {
1816
const {argument} = path.node;
1917
const newPath = replaceWith(path, argument);
2018
const objectPath = newPath.get('expression.callee.object');
@@ -24,7 +22,7 @@ module.exports.fix = (path) => {
2422
addParens(path);
2523
};
2624

27-
module.exports.traverse = ({push}) => ({
25+
export const traverse = ({push}) => ({
2826
AwaitExpression(path) {
2927
const argPath = path.get('argument');
3028

packages/plugin-parens/lib/add-missing-for-await/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
['add-missing-for-await', plugin],
97
],

packages/plugin-parens/lib/add-missing-for-template/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 {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {addParens} = operator;
54

6-
module.exports.report = () => `Add missing parens: invalid tagged template on optional chain`;
5+
export const report = () => `Add missing parens: invalid tagged template on optional chain`;
76

8-
module.exports.fix = (path) => {
7+
export const fix = (path) => {
98
addParens(path);
109
};
1110

12-
module.exports.traverse = ({push}) => ({
11+
export const traverse = ({push}) => ({
1312
TaggedTemplateExpression(path) {
1413
const tagPath = path.get('tag');
1514

packages/plugin-parens/lib/add-missing-for-template/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
['add-missing-for-template', plugin],
97
],

packages/plugin-parens/lib/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
'use strict';
1+
import * as addMissingForAwait from './add-missing-for-await/index.js';
2+
import * as addMissingForTemplate from './add-missing-for-template/index.js';
3+
import * as addMissingForAssign from './add-missing-for-assign/index.js';
4+
import * as removeUselessForAwait from './remove-useless-for-await/index.js';
5+
import * as removeUselessForParams from './remove-useless-for-params/index.js';
26

3-
const addMissingForAwait = require('./add-missing-for-await');
4-
const addMissingForTemplate = require('./add-missing-for-template');
5-
const addMissingForAssign = require('./add-missing-for-assign');
6-
const removeUselessForAwait = require('./remove-useless-for-await');
7-
const removeUselessForParams = require('./remove-useless-for-params');
8-
9-
module.exports.rules = {
7+
export const rules = {
108
'add-missing-for-awai': addMissingForAwait,
119
'add-missing-for-template': addMissingForTemplate,
1210
'add-missing-for-assign': addMissingForAssign,

packages/plugin-parens/lib/remove-useless-for-await/index.js

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

3-
const {operator} = require('putout');
43
const {hasParens} = operator;
54

6-
module.exports.report = () => `Remove useless parens around 'await'`;
5+
export const report = () => `Remove useless parens around 'await'`;
76

8-
module.exports.fix = (path) => {
7+
export const fix = (path) => {
98
path.node.extra = {
109
parenthesized: false,
1110
};
1211
};
1312

14-
module.exports.traverse = ({push}) => ({
13+
export const traverse = ({push}) => ({
1514
AwaitExpression(path) {
1615
if (!hasParens(path))
1716
return;

0 commit comments

Comments
 (0)