@putout/plugin-for-of 2.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -67,9 +67,8 @@ for (const name of names) {
67
67
 
68
68
  ```js
69
69
  for (const item in object) {
70
- if (object.hasOwnProperty(item)) {
70
+ if (object.hasOwnProperty(item))
71
71
  log(item);
72
- }
73
72
  }
74
73
 
75
74
  for (const item in object) {
@@ -289,7 +288,7 @@ for (const [i, item] of array.entries()) {
289
288
 
290
289
  ### for-entries-n
291
290
 
292
- ##### ❌ Example of incorrect code
291
+ #### ❌ Example of incorrect code
293
292
 
294
293
  ```js
295
294
  const n = array.length;
@@ -30,7 +30,7 @@ const forOfEntriesTemplate = template(`
30
30
  const {keys} = Object;
31
31
  const isRoot = (path) => path.isFunction() || path.isProgram();
32
32
 
33
- module.exports.report = () => `for-of should be used instead of forEach`;
33
+ module.exports.report = () => `Use 'for-of' instead of 'forEach()'`;
34
34
 
35
35
  module.exports.replace = () => ({
36
36
  '__.forEach.call(__a, (__b) => __body)': 'for (const __b of __a) __body',
@@ -78,6 +78,9 @@ module.exports.replace = () => ({
78
78
 
79
79
  module.exports.match = () => ({
80
80
  '__.forEach(__args)': (vars, path) => {
81
+ if (path.parentPath.isSequenceExpression())
82
+ return false;
83
+
81
84
  const objectPath = path.get('callee.object');
82
85
  const fnPath = path.get('arguments.0');
83
86
 
package/lib/index.js CHANGED
@@ -1,21 +1,31 @@
1
1
  'use strict';
2
2
 
3
- const getRule = (a) => ({
4
- [a]: require(`./${a}`),
5
- });
3
+ const map = require('./map');
4
+ const forEach = require('./for-each');
5
+ const forN = require('./for-n');
6
+ const forLength = require('./for-length');
7
+ const forEntries = require('./for-entries');
8
+ const forEntriesN = require('./for-entries-n');
9
+ const forInNegative = require('./for-in-negative');
10
+ const forInPositive = require('./for-in-positive');
11
+ const reduce = require('./reduce');
12
+ const removeUseless = require('./remove-useless');
13
+ const removeUselessVariables = require('./remove-useless-variables');
14
+ const removeUselessArrayFrom = require('./remove-useless-array-from');
15
+ const removeUnusedVariables = require('./remove-unused-variables');
6
16
 
7
17
  module.exports.rules = {
8
- ...getRule('map'),
9
- ...getRule('for-each'),
10
- ...getRule('for-n'),
11
- ...getRule('for-length'),
12
- ...getRule('for-entries'),
13
- ...getRule('for-entries-n'),
14
- ...getRule('for-in-negative'),
15
- ...getRule('for-in-positive'),
16
- ...getRule('reduce'),
17
- ...getRule('remove-useless'),
18
- ...getRule('remove-useless-variables'),
19
- ...getRule('remove-useless-array-from'),
20
- ...getRule('remove-unused-variables'),
18
+ map,
19
+ 'for-each': forEach,
20
+ 'for-n': forN,
21
+ 'for-length': forLength,
22
+ 'for-entries': forEntries,
23
+ 'for-entries-n': forEntriesN,
24
+ 'for-in-negative': forInNegative,
25
+ 'for-in-positive': forInPositive,
26
+ reduce,
27
+ 'remove-useless': removeUseless,
28
+ 'remove-useless-variables': removeUselessVariables,
29
+ 'remove-useless-array-from': removeUselessArrayFrom,
30
+ 'remove-unused-variables': removeUnusedVariables,
21
31
  };
@@ -67,9 +67,8 @@ function isReferenced({scope}, path) {
67
67
  return !current || current.referenced;
68
68
  }
69
69
 
70
- if (path.isObjectPattern()) {
70
+ if (path.isObjectPattern())
71
71
  return true;
72
- }
73
72
 
74
73
  const {node} = path;
75
74
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "2.0.0",
3
+ "version": "4.0.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to apply for...of",
@@ -40,22 +40,22 @@
40
40
  "@putout/plugin-remove-unused-variables": "*",
41
41
  "@putout/plugin-remove-useless-arguments": "*",
42
42
  "@putout/plugin-remove-useless-continue": "*",
43
- "@putout/test": "^7.0.0",
44
- "c8": "^8.0.0",
45
- "eslint": "^8.0.1",
43
+ "@putout/test": "^8.0.0",
44
+ "c8": "^9.0.0",
45
+ "eslint": "^9.0.0-alpha.0",
46
46
  "eslint-plugin-n": "^16.0.0",
47
- "eslint-plugin-putout": "^18.0.0",
47
+ "eslint-plugin-putout": "^22.0.0",
48
48
  "lerna": "^6.0.1",
49
- "madrun": "^9.0.0",
49
+ "madrun": "^10.0.0",
50
50
  "montag": "^1.2.1",
51
- "nodemon": "^2.0.1"
51
+ "nodemon": "^3.0.1"
52
52
  },
53
53
  "peerDependencies": {
54
- "putout": ">=30"
54
+ "putout": ">=34"
55
55
  },
56
56
  "license": "MIT",
57
57
  "engines": {
58
- "node": ">=16"
58
+ "node": ">=18"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public"