File tree 33 files changed +145
-207
lines changed
remove-useless-array-from
33 files changed +145
-207
lines changed Original file line number Diff line number Diff line change 1
- 'use strict ';
1
+ import { types } from 'putout ';
2
2
3
- const { types} = require ( 'putout' ) ;
4
3
const {
5
4
isVariableDeclaration,
6
5
isIdentifier,
7
6
isArrayPattern,
8
7
isObjectPattern,
9
8
} = types ;
10
9
11
- module . exports . report = ( ) => `Add missing declaration` ;
10
+ export const report = ( ) => `Add missing declaration` ;
12
11
13
- module . exports . match = ( ) => ( {
12
+ export const match = ( ) => ( {
14
13
'for (__a of __b) __c' : ( { __a} , path ) => {
15
14
if ( isVariableDeclaration ( __a ) )
16
15
return false ;
@@ -42,6 +41,6 @@ module.exports.match = () => ({
42
41
} ,
43
42
} ) ;
44
43
45
- module . exports . replace = ( ) => ( {
44
+ export const replace = ( ) => ( {
46
45
'for (__a of __b) __c' : 'for (const __a of __b) __c' ,
47
46
} ) ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
1
+ import { createTest } from '@putout/test' ;
2
+ import * as plugin from './index.js' ;
2
3
3
- const { createTest} = require ( '@putout/test' ) ;
4
- const plugin = require ( '.' ) ;
5
-
6
- const test = createTest ( __dirname , {
4
+ const test = createTest ( import . meta. url , {
7
5
plugins : [
8
6
[ 'add-missing-declaration' , plugin ] ,
9
7
] ,
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- const {
1
+ import {
4
2
template ,
5
3
operator ,
6
4
types ,
7
- } = require ( 'putout' ) ;
5
+ } from 'putout' ;
8
6
9
7
const {
10
8
isIdentifier,
@@ -30,9 +28,9 @@ const forOfEntriesTemplate = template(`
30
28
const { keys} = Object ;
31
29
const isRoot = ( path ) => path . isFunction ( ) || path . isProgram ( ) ;
32
30
33
- module . exports . report = ( ) => `Use 'for-of' instead of 'forEach()'` ;
31
+ export const report = ( ) => `Use 'for-of' instead of 'forEach()'` ;
34
32
35
- module . exports . replace = ( ) => ( {
33
+ export const replace = ( ) => ( {
36
34
'__.forEach.call(__a, (__b) => __body)' : 'for (const __b of __a) __body' ,
37
35
'__.forEach(__args)' : ( vars , path ) => {
38
36
const { params, body} = path . node . arguments [ 0 ] ;
@@ -76,7 +74,7 @@ module.exports.replace = () => ({
76
74
} ,
77
75
} ) ;
78
76
79
- module . exports . match = ( ) => ( {
77
+ export const match = ( ) => ( {
80
78
'__.forEach(__args)' : ( vars , path ) => {
81
79
const { parentPath} = path ;
82
80
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- const { createTest} = require ( '@putout/test' ) ;
4
-
5
- const convertConstToLet = require ( '@putout/plugin-convert-const-to-let' ) ;
6
- const removeUselessContinue = require ( '@putout/plugin-remove-useless-continue' ) ;
7
- const plugin = require ( '.' ) ;
8
-
9
- const removeUselessVariables = require ( '../remove-useless-variables' ) ;
1
+ import { createRequire } from 'node:module' ;
2
+ import { createTest } from '@putout/test' ;
3
+ import * as convertConstToLet from '@putout/plugin-convert-const-to-let' ;
4
+ import * as removeUselessContinue from '@putout/plugin-remove-useless-continue' ;
5
+ import * as plugin from './index.js' ;
6
+ import * as removeUselessVariables from '../remove-useless-variables/index.js' ;
7
+
8
+ const require = createRequire ( import . meta. url ) ;
10
9
const convertComparisonToBoolean = require ( '@putout/plugin-conditions' ) . rules [ 'convert-comparison-to-boolean' ] ;
11
10
12
- const test = createTest ( __dirname , {
11
+ const test = createTest ( import . meta . url , {
13
12
plugins : [
14
13
[ 'for-of/for-each' , plugin ] ,
15
14
] ,
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- const {
1
+ import {
4
2
operator ,
5
3
template ,
6
4
types ,
7
- } = require ( 'putout' ) ;
5
+ } from 'putout' ;
8
6
9
7
const {
10
8
compare,
@@ -13,14 +11,14 @@ const {
13
11
14
12
const { isBlockStatement} = types ;
15
13
16
- module . exports . report = ( ) => `Use 'for...of' instead of 'for'` ;
14
+ export const report = ( ) => `Use 'for...of' instead of 'for'` ;
17
15
18
16
const forLoopToN = 'for (let __i = 0; __i < __n; __i++) __c' ;
19
17
const getForOfLoop = template ( `for (const [INDEX, LEFT] of RIGHT.entries()) BODY` ) ;
20
18
const assignIterable = ( __i ) => `const __a = __b[${ __i . name } ]` ;
21
19
const assignN = ( __n ) => `const ${ __n . name } = __e.length` ;
22
20
23
- module . exports . filter = ( path ) => {
21
+ export const filter = ( path ) => {
24
22
const { node} = path ;
25
23
const prevPath = path . getPrevSibling ( ) ;
26
24
@@ -57,7 +55,7 @@ module.exports.filter = (path) => {
57
55
return references > 3 ;
58
56
} ;
59
57
60
- module . exports . replace = ( ) => ( {
58
+ export const replace = ( ) => ( {
61
59
[ forLoopToN ] : ( { __c, __i} ) => {
62
60
const [ node ] = __c . body ;
63
61
const { __a, __b} = getTemplateValues ( node , assignIterable ( __i ) ) ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
1
+ import montag from 'montag' ;
2
+ import { createTest } from '@putout/test' ;
3
+ import * as entriesN from './index.js' ;
2
4
3
- const montag = require ( 'montag' ) ;
4
- const { createTest} = require ( '@putout/test' ) ;
5
- const entriesN = require ( './index.js' ) ;
6
-
7
- const test = createTest ( __dirname , {
5
+ const test = createTest ( import . meta. url , {
8
6
plugins : [
9
7
[ 'convert-for-to-for-of/entries-n' , entriesN ] ,
10
8
] ,
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- const {
1
+ import {
4
2
operator ,
5
3
types ,
6
4
template ,
7
- } = require ( 'putout' ) ;
5
+ } from 'putout' ;
8
6
9
7
const {
10
8
compare,
@@ -13,14 +11,14 @@ const {
13
11
14
12
const { isBlockStatement} = types ;
15
13
16
- module . exports . report = ( ) => `Use 'for...of' instead of 'for'` ;
14
+ export const report = ( ) => `Use 'for...of' instead of 'for'` ;
17
15
18
16
const forLoop = 'for (let __i = 0; __i < __e.length; __i++) __c' ;
19
17
const getForOfLoop = template ( `for (const [INDEX, ITEM] of ITEMS.entries()) BODY` ) ;
20
18
const assignIterable = ( __i ) => `const __a = __b[${ __i . name } ]` ;
21
19
const assignIterableWithName = ( __i , __e ) => `const __a = ${ __e . name } [${ __i . name } ]` ;
22
20
23
- module . exports . filter = ( path ) => {
21
+ export const filter = ( path ) => {
24
22
const { node} = path ;
25
23
const { body} = node ;
26
24
@@ -43,7 +41,7 @@ module.exports.filter = (path) => {
43
41
return compare ( first , assignIterableWithName ( __i , __e ) ) ;
44
42
} ;
45
43
46
- module . exports . replace = ( ) => ( {
44
+ export const replace = ( ) => ( {
47
45
[ forLoop ] : ( { __c, __i} ) => {
48
46
const [ node ] = __c . body ;
49
47
const { __a, __b} = getTemplateValues ( node , assignIterable ( __i ) ) ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
1
+ import removeUnusedVariables from '@putout/plugin-remove-unused-variables' ;
2
+ import { createTest } from '@putout/test' ;
3
+ import * as forEntries from './index.js' ;
2
4
3
- const removeUnusedVariables = require ( '@putout/plugin-remove-unused-variables' ) ;
4
- const { createTest} = require ( '@putout/test' ) ;
5
- const forEntries = require ( '.' ) ;
6
-
7
- const test = createTest ( __dirname , {
5
+ const test = createTest ( import . meta. url , {
8
6
plugins : [
9
7
[ 'for-of/for-entries' , forEntries ] ,
10
8
] ,
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- const { generate, operator} = require ( 'putout' ) ;
1
+ import { generate , operator } from 'putout' ;
4
2
5
3
const {
6
4
contains,
7
5
getTemplateValues,
8
6
} = operator ;
9
7
10
- module . exports . report = ( ) => `for-of should be used instead of for-in` ;
8
+ export const report = ( ) => `for-of should be used instead of for-in` ;
11
9
12
- module . exports . match = ( ) => ( {
10
+ export const match = ( ) => ( {
13
11
'for (__a in __b) __body' : ( { __a, __b, __body} ) => {
14
12
const declaration = getTemplateValues ( __a , 'var __a' ) ;
15
13
@@ -22,7 +20,7 @@ module.exports.match = () => ({
22
20
} ,
23
21
} ) ;
24
22
25
- module . exports . replace = ( ) => ( {
23
+ export const replace = ( ) => ( {
26
24
'for (__a in __b) __body' : ( { __b, __body} ) => {
27
25
const [ first ] = __body . body ;
28
26
const condition = getTemplateValues ( first , 'if (!__b.hasOwnProperty(__a)) __c' ) ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
1
+ import { createTest } from '@putout/test' ;
2
+ import * as negative from './index.js' ;
2
3
3
- const { createTest} = require ( '@putout/test' ) ;
4
- const negative = require ( '.' ) ;
5
-
6
- const test = createTest ( __dirname , {
4
+ const test = createTest ( import . meta. url , {
7
5
plugins : [
8
6
[ 'convert-for-in-to-for-of/negative' , negative ] ,
9
7
] ,
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- const { generate, operator} = require ( 'putout' ) ;
1
+ import { generate , operator } from 'putout' ;
4
2
5
3
const {
6
4
contains,
7
5
getTemplateValues,
8
6
} = operator ;
9
7
10
- module . exports . report = ( ) => `for-of should be used instead of for-in` ;
8
+ export const report = ( ) => `for-of should be used instead of for-in` ;
11
9
12
- module . exports . match = ( ) => ( {
10
+ export const match = ( ) => ( {
13
11
'for (__a in __b) __body' : ( { __a, __b, __body} ) => {
14
12
const declaration = getTemplateValues ( __a , 'var __a' ) ;
15
13
@@ -22,7 +20,7 @@ module.exports.match = () => ({
22
20
} ,
23
21
} ) ;
24
22
25
- module . exports . replace = ( ) => ( {
23
+ export const replace = ( ) => ( {
26
24
'for (__a in __b) __body' : ( { __b, __body} ) => {
27
25
const [ first ] = __body . body ;
28
26
const condition = getTemplateValues ( first , 'if (__b.hasOwnProperty(__a)) __body' ) ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
1
+ import { createTest } from '@putout/test' ;
2
+ import * as convertForInToForOf from './index.js' ;
2
3
3
- const { createTest} = require ( '@putout/test' ) ;
4
- const convertForInToForOf = require ( '.' ) ;
5
-
6
- const test = createTest ( __dirname , {
4
+ const test = createTest ( import . meta. url , {
7
5
plugins : [
8
6
[ 'convert-for-in-to-for-of' , convertForInToForOf ] ,
9
7
] ,
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- const {
1
+ import {
4
2
operator ,
5
3
types ,
6
4
template ,
7
- } = require ( 'putout' ) ;
5
+ } from 'putout' ;
8
6
9
7
const {
10
8
compare,
@@ -13,14 +11,14 @@ const {
13
11
14
12
const { isBlockStatement} = types ;
15
13
16
- module . exports . report = ( ) => `Use 'for...of' instead of 'for'` ;
14
+ export const report = ( ) => `Use 'for...of' instead of 'for'` ;
17
15
18
16
const forLoop = 'for (let __i = 0; __i < __e.length; __i++) __c' ;
19
17
const getForOfLoop = template ( `for (const LEFT of RIGHT) BODY` ) ;
20
18
const assignIterable = ( __i ) => `const __a = __b[${ __i . name } ]` ;
21
19
const assignIterableWithName = ( __i , __e ) => `const __a = ${ __e . name } [${ __i . name } ]` ;
22
20
23
- module . exports . filter = ( path ) => {
21
+ export const filter = ( path ) => {
24
22
const { node} = path ;
25
23
const { body} = node ;
26
24
@@ -37,7 +35,7 @@ module.exports.filter = (path) => {
37
35
return compare ( first , assignIterableWithName ( __i , __e ) ) ;
38
36
} ;
39
37
40
- module . exports . replace = ( ) => ( {
38
+ export const replace = ( ) => ( {
41
39
[ forLoop ] : ( { __c, __i} ) => {
42
40
const [ node ] = __c . body ;
43
41
const { __a, __b} = getTemplateValues ( node , assignIterable ( __i ) ) ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
1
+ import removeUnusedVariables from '@putout/plugin-remove-unused-variables' ;
2
+ import { createTest } from '@putout/test' ;
3
+ import * as convertForToForOf from './index.js' ;
2
4
3
- const removeUnusedVariables = require ( '@putout/plugin-remove-unused-variables' ) ;
4
- const { createTest} = require ( '@putout/test' ) ;
5
- const convertForToForOf = require ( './index.js' ) ;
6
-
7
- const test = createTest ( __dirname , {
5
+ const test = createTest ( import . meta. url , {
8
6
plugins : [
9
7
[ 'for-of/length' , convertForToForOf ] ,
10
8
] ,
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- const {
1
+ import {
4
2
operator ,
5
3
template ,
6
4
types ,
7
- } = require ( 'putout' ) ;
5
+ } from 'putout' ;
8
6
9
7
const {
10
8
compare,
@@ -13,14 +11,14 @@ const {
13
11
14
12
const { isBlockStatement} = types ;
15
13
16
- module . exports . report = ( ) => `Use 'for...of' instead of 'for'` ;
14
+ export const report = ( ) => `Use 'for...of' instead of 'for'` ;
17
15
18
16
const forLoopToN = 'for (let __i = 0; __i < __n; __i++) __c' ;
19
17
const getForOfLoop = template ( `for (const LEFT of RIGHT) BODY` ) ;
20
18
const assignIterable = ( __i ) => `const __a = __b[${ __i . name } ]` ;
21
19
const assignN = ( __n ) => `const ${ __n . name } = __e.length` ;
22
20
23
- module . exports . filter = ( path ) => {
21
+ export const filter = ( path ) => {
24
22
const { node} = path ;
25
23
const prevPath = path . getPrevSibling ( ) ;
26
24
@@ -46,7 +44,7 @@ module.exports.filter = (path) => {
46
44
return references <= 3 ;
47
45
} ;
48
46
49
- module . exports . replace = ( ) => ( {
47
+ export const replace = ( ) => ( {
50
48
[ forLoopToN ] : ( { __c, __i} ) => {
51
49
const [ node ] = __c . body ;
52
50
const { __a, __b} = getTemplateValues ( node , assignIterable ( __i ) ) ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
1
+ import { createRequire } from 'node:module' ;
2
+ import { createTest } from '@putout/test' ;
3
+ import * as forN from './index.js' ;
2
4
3
- const { createTest} = require ( '@putout/test' ) ;
4
- const forN = require ( '.' ) ;
5
+ const require = createRequire ( import . meta. url ) ;
5
6
6
- const test = createTest ( __dirname , {
7
+ const test = createTest ( import . meta . url , {
7
8
plugins : [
8
9
[ 'for-of/n' , forN ] ,
9
10
] ,
You can’t perform that action at this time.
0 commit comments