Skip to content

Commit 9658521

Browse files
committed
feature: @putout/plugin-types: migrate to ESM
1 parent 65452fa commit 9658521

19 files changed

Lines changed: 54 additions & 84 deletions

File tree

packages/plugin-types/lib/apply-is-array/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
1+
export const report = () => `Use 'Array.isArray()' instead of 'instanceof'`;
22

3-
module.exports.report = () => `Use 'Array.isArray()' instead of 'instanceof'`;
4-
5-
module.exports.replace = ({options}) => {
3+
export const replace = ({options}) => {
64
const {inline} = options;
75

86
return {

packages/plugin-types/lib/apply-is-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 applyIsArray from './index.js';
23

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

packages/plugin-types/lib/convert-typeof-to-is-type/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 {operator} from 'putout';
22

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

65
const NAMES = {
@@ -50,8 +49,8 @@ const NOT_BODIES = {
5049
equalUndefined: '__a !== undefined',
5150
};
5251

53-
module.exports.report = () => `Use function to check type instead of 'typeof' or 'instanceof'`;
54-
module.exports.match = () => ({
52+
export const report = () => `Use function to check type instead of 'typeof' or 'instanceof'`;
53+
export const match = () => ({
5554
[EQUAL]: check,
5655
[NOT_EQUAL]: check,
5756
[EQUAL_INSTANCE_OF]: check,
@@ -60,7 +59,7 @@ module.exports.match = () => ({
6059
[NOT_EQUAL_UNDEFINED]: check,
6160
});
6261

63-
module.exports.replace = () => ({
62+
export const replace = () => ({
6463
[BODIES.function]: 'isFn(__a)',
6564
[BODIES.string]: 'isString(__a)',
6665
[BODIES.number]: 'isNumber(__a)',

packages/plugin-types/lib/convert-typeof-to-is-type/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 convertTypeofToIsType from './index.js';
23

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

packages/plugin-types/lib/declare/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
module.exports.declare = () => ({
1+
export const declare = () => ({
42
isString: `const isString = (a) => typeof a === 'string'`,
53
isEmptyString: `const isEmptyString = (a) => !a && isString(a)`,
64
isNumber: `const isNumber = (a) => !Number.isNaN(a) && typeof a === 'number'`,

packages/plugin-types/lib/declare/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 declare from './index.js';
23

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

packages/plugin-types/lib/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
'use strict';
1+
import * as applyIsArray from './apply-is-array/index.js';
2+
import * as declare from './declare/index.js';
3+
import * as convertTypeofToIsType from './convert-typeof-to-is-type/index.js';
4+
import * as removeUselessConversion from './remove-useless-conversion/index.js';
5+
import * as removeUselessConstructor from './remove-useless-constructor/index.js';
6+
import * as removeDoubleNegations from './remove-double-negations/index.js';
7+
import * as removeUselessTypeof from './remove-useless-typeof/index.js';
28

3-
const applyIsArray = require('./apply-is-array');
4-
const declare = require('./declare');
5-
const convertTypeofToIsType = require('./convert-typeof-to-is-type');
6-
const removeUselessConversion = require('./remove-useless-conversion');
7-
const removeUselessConstructor = require('./remove-useless-constructor');
8-
const removeDoubleNegations = require('./remove-double-negations');
9-
const removeUselessTypeof = require('./remove-useless-typeof');
10-
11-
module.exports.rules = {
9+
export const rules = {
1210
'apply-is-array': applyIsArray,
13-
declare,
11+
'declare': declare,
1412
'convert-typeof-to-is-type': convertTypeofToIsType,
1513
'remove-useless-conversion': removeUselessConversion,
1614
'remove-useless-constructor': removeUselessConstructor,

packages/plugin-types/lib/remove-double-negations/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
1+
export const report = () => `Avoid double negations in conditions`;
22

3-
module.exports.report = () => `Avoid double negations in conditions`;
3+
export const filter = ({parentPath}) => !parentPath.isJSXExpressionContainer();
44

5-
module.exports.filter = ({parentPath}) => !parentPath.isJSXExpressionContainer();
6-
7-
module.exports.replace = () => ({
5+
export const replace = () => ({
86
'if (!!__a) __b': 'if (__a) __b',
97
'!!__a ? __b : __c': '__a ? __b : __c',
108
'!!__a && __b': '__a && __b',

0 commit comments

Comments
 (0)