eslint-plugin-array-func
Advanced tools
Comparing version 5.0.1 to 5.0.2
16
index.js
@@ -15,3 +15,3 @@ /** | ||
name: "eslint-plugin-array-func", | ||
version: "5.0.1" | ||
version: "5.0.1", | ||
}, | ||
@@ -24,7 +24,8 @@ rules: { | ||
"prefer-flat-map": preferFlatMap, | ||
"prefer-flat": preferFlat | ||
"prefer-flat": preferFlat, | ||
}, | ||
configs: {} | ||
configs: {}, | ||
}; | ||
index.configs.recommended = { | ||
name: 'array-func/recommended', | ||
plugins: { "array-func": index }, | ||
@@ -35,6 +36,7 @@ rules: { | ||
"array-func/prefer-array-from": "error", | ||
"array-func/avoid-reverse": "error" | ||
} | ||
"array-func/avoid-reverse": "error", | ||
}, | ||
}; | ||
index.configs.all = { | ||
name: 'array-func/all', | ||
plugins: { "array-func": index }, | ||
@@ -47,6 +49,6 @@ rules: { | ||
"array-func/prefer-flat-map": "error", | ||
"array-func/prefer-flat": "error" | ||
} | ||
"array-func/prefer-flat": "error", | ||
}, | ||
}; | ||
export default index; |
{ | ||
"name": "eslint-plugin-array-func", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "Rules dealing with Array functions and methods.", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint:js": "eslint index.js package.json rules/ test/ --ext js,json", | ||
"lint:js": "eslint index.js package.json rules/ test/", | ||
"lint": "npm run lint:js", | ||
"test": "npm run lint && nyc ava" | ||
"test": "npm run lint && c8 ava", | ||
"coverage": "c8 report -r lcov" | ||
}, | ||
@@ -14,12 +15,12 @@ "author": "Martin Giger (https://humanoids.be)", | ||
"devDependencies": { | ||
"@freaktechnik/eslint-config-node": "^9.2.1", | ||
"@freaktechnik/eslint-config-test": "^9.2.1", | ||
"@typescript-eslint/parser": "^6.19.1", | ||
"ava": "^6.1.0", | ||
"eslint": "^8.56.0", | ||
"@freaktechnik/eslint-config-node": "^10.0.3", | ||
"@freaktechnik/eslint-config-test": "^10.0.6", | ||
"@typescript-eslint/parser": "^8.0.0", | ||
"ava": "^6.1.3", | ||
"c8": "^10.1.2", | ||
"eslint": "^8.57.0", | ||
"eslint-ava-rule-tester": "^5.0.1", | ||
"eslint-plugin-eslint-plugin": "^5.2.1", | ||
"eslint-plugin-eslint-plugin": "^6.2.0", | ||
"eslint-plugin-optimize-regex": "^1.2.1", | ||
"nyc": "^15.1.0", | ||
"typescript": "^5.3.3" | ||
"typescript": "^5.5.4" | ||
}, | ||
@@ -26,0 +27,0 @@ "peerDependencies": { |
134
README.md
# eslint-plugin-array-func | ||
[![codecov](https://codecov.io/gh/freaktechnik/eslint-plugin-array-func/branch/master/graph/badge.svg)](https://codecov.io/gh/freaktechnik/eslint-plugin-array-func) | ||
[![codecov](https://codecov.io/gh/freaktechnik/eslint-plugin-array-func/graph/badge.svg?token=FhaBIu6Ze0)](https://codecov.io/gh/freaktechnik/eslint-plugin-array-func) | ||
@@ -85,13 +85,17 @@ Rules for Array functions and methods. | ||
To use this rule, your `.eslintrc.json` should at least contain the following (may look different for other config file styles): | ||
To use this rule, your `eslint.config.js` should at least contain the following: | ||
```json | ||
{ | ||
"plugins": [ | ||
"array-func" | ||
], | ||
"rules": { | ||
"array-func/from-map": "error" | ||
```js | ||
import arrayFunc from "eslint-plugin-array-func"; | ||
export default [ | ||
{ | ||
plugins: { | ||
"array-func": arrayFunc | ||
}, | ||
rules: { | ||
"array-func/from-map": "error" | ||
} | ||
} | ||
} | ||
]; | ||
``` | ||
@@ -176,13 +180,17 @@ | ||
To use this rule, your `.eslintrc.json` should at least contain the following (may look different for other config file styles): | ||
To use this rule, your `eslint.config.js` should at least contain the following: | ||
```json | ||
{ | ||
"plugins": [ | ||
"array-func" | ||
], | ||
"rules": { | ||
"array-func/no-unnecessary-this-arg": "error" | ||
```js | ||
import arrayFunc from "eslint-plugin-array-func"; | ||
export default [ | ||
{ | ||
plugins: { | ||
"array-func": arrayFunc | ||
}, | ||
rules: { | ||
"array-func/no-unnecessary-this-arg": "error" | ||
} | ||
} | ||
} | ||
]; | ||
``` | ||
@@ -223,13 +231,17 @@ | ||
To use this rule, your `.eslintrc.json` should at least contain the following (may look different for other config file styles): | ||
To use this rule, your `eslint.config.js` should at least contain the following: | ||
```json | ||
{ | ||
"plugins": [ | ||
"array-func" | ||
], | ||
"rules": { | ||
"array-func/prefer-array-from": "error" | ||
```js | ||
import arrayFunc from "eslint-plugin-array-func"; | ||
export default [ | ||
{ | ||
plugins: { | ||
"array-func": arrayFunc | ||
}, | ||
rules: { | ||
"array-func/prefer-array-from": "error" | ||
} | ||
} | ||
} | ||
]; | ||
``` | ||
@@ -272,13 +284,17 @@ | ||
To use this rule, your `.eslintrc.json` should at least contain the following (may look different for other config file styles): | ||
To use this rule, your `eslint.config.js` should at least contain the following: | ||
```json | ||
{ | ||
"plugins": [ | ||
"array-func" | ||
], | ||
"rules": { | ||
"array-func/avoid-reverse": "error" | ||
```js | ||
import arrayFunc from "eslint-plugin-array-func"; | ||
export default [ | ||
{ | ||
plugins: { | ||
"array-func": arrayFunc | ||
}, | ||
rules: { | ||
"array-func/avoid-reverse": "error" | ||
} | ||
} | ||
} | ||
]; | ||
``` | ||
@@ -322,13 +338,17 @@ | ||
To use this rule, your `.eslintrc.json` should at least contain the following (may look different for other config file styles): | ||
To use this rule, your `eslint.config.js` should at least contain the following: | ||
```json | ||
{ | ||
"plugins": [ | ||
"array-func" | ||
], | ||
"rules": { | ||
"array-func/prefer-flat-map": "error" | ||
```js | ||
import arrayFunc from "eslint-plugin-array-func"; | ||
export default [ | ||
{ | ||
plugins: { | ||
"array-func": arrayFunc | ||
}, | ||
rules: { | ||
"array-func/prefer-flat-map": "error" | ||
} | ||
} | ||
} | ||
]; | ||
``` | ||
@@ -370,13 +390,17 @@ | ||
To use this rule, your `.eslintrc.json` should at least contain the following (may look different for other config file styles): | ||
To use this rule, your `eslint.config.js` should at least contain the following: | ||
```json | ||
{ | ||
"plugins": [ | ||
"array-func" | ||
], | ||
"rules": { | ||
"array-func/prefer-flat": "error" | ||
```js | ||
import arrayFunc from "eslint-plugin-array-func"; | ||
export default [ | ||
{ | ||
plugins: { | ||
"array-func": arrayFunc | ||
}, | ||
rules: { | ||
"array-func/prefer-flat": "error" | ||
} | ||
} | ||
} | ||
]; | ||
``` | ||
@@ -383,0 +407,0 @@ |
@@ -9,3 +9,3 @@ /** | ||
reduce: "reduceRight", | ||
reduceRight: "reduce" | ||
reduceRight: "reduce", | ||
}; | ||
@@ -17,3 +17,3 @@ | ||
description: "Prefer methods operating from the right over reversing the array", | ||
recommended: true | ||
recommended: true, | ||
}, | ||
@@ -24,4 +24,4 @@ schema: [], | ||
messages: { | ||
avoidReverse: "Prefer using {{ reversed }} over reversing the array and {{ methodName }}" | ||
} | ||
avoidReverse: "Prefer using {{ reversed }} over reversing the array and {{ methodName }}", | ||
}, | ||
}, | ||
@@ -42,3 +42,3 @@ create(context) { | ||
start: parent.callee.property.loc.start, | ||
end: node.callee.property.loc.end | ||
end: node.callee.property.loc.end, | ||
}, | ||
@@ -48,3 +48,3 @@ messageId: "avoidReverse", | ||
reversed, | ||
methodName: node.callee.property.name | ||
methodName: node.callee.property.name, | ||
}, | ||
@@ -54,13 +54,13 @@ fix(fixer) { | ||
[ | ||
, propertyEnd | ||
, propertyEnd, | ||
] = node.callee.property.range; | ||
return fixer.replaceTextRange([ | ||
propertyStart, | ||
propertyEnd | ||
propertyEnd, | ||
], reversed); | ||
} | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; |
@@ -9,3 +9,3 @@ /** | ||
{ name: 'item' }, | ||
{ name: 'index' } | ||
{ name: 'index' }, | ||
]; | ||
@@ -21,3 +21,3 @@ | ||
description: "Prefer using the mapFn callback of Array.from over an immediate .map() call.", | ||
recommended: true | ||
recommended: true, | ||
}, | ||
@@ -28,4 +28,4 @@ fixable: "code", | ||
messages: { | ||
useMapCb: "Use mapFn callback of Array.from instead of map()" | ||
} | ||
useMapCb: "Use mapFn callback of Array.from instead of map()", | ||
}, | ||
}, | ||
@@ -39,3 +39,3 @@ create(context) { | ||
mapCallback, | ||
mapThisArgument | ||
mapThisArgument, | ||
] = callee.parent.arguments; | ||
@@ -57,3 +57,3 @@ node = callee.parent; | ||
start: parent.callee.loc.start, | ||
end: callee.loc.end | ||
end: callee.loc.end, | ||
}, | ||
@@ -73,3 +73,3 @@ messageId: "useMapCb", | ||
callback, | ||
thisArgument | ||
thisArgument, | ||
] = parent.arguments, | ||
@@ -107,9 +107,9 @@ parameters = callback.type === "Identifier" | ||
callbackStartLocation | ||
, callbackEndLocation | ||
, callbackEndLocation, | ||
] = callback.range, | ||
[ | ||
, parentEndLocation | ||
, parentEndLocation, | ||
] = parent.range, | ||
[ | ||
, nodeEndLocation | ||
, nodeEndLocation, | ||
] = node.range, | ||
@@ -119,3 +119,3 @@ restParameters = sourceCode.getText().slice(callbackEndLocation, parentEndLocation); | ||
callbackStartLocation, | ||
nodeEndLocation | ||
nodeEndLocation, | ||
], `${functionStart}${lastCallback}${functionEnd}${restParameters}`); | ||
@@ -128,13 +128,13 @@ } | ||
[ | ||
, parentEndLocation | ||
, parentEndLocation, | ||
] = parent.range; | ||
return fixer.replaceTextRange([ | ||
parentEndLocation - FUNCTION_END.length, | ||
argumentStartLocation | ||
argumentStartLocation, | ||
], PARAM_SEPARATOR); | ||
} | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; |
@@ -7,3 +7,3 @@ /** | ||
isMethod, | ||
isOnObject | ||
isOnObject, | ||
} from "../lib/helpers/call-expression.js"; | ||
@@ -13,3 +13,3 @@ import { ARROW_FUNCTION_EXPRESSION } from "../lib/type.js"; | ||
const arrayFunctions = { | ||
from: 3 | ||
from: 3, | ||
}, | ||
@@ -24,3 +24,3 @@ // All have param location 2 | ||
'some', | ||
'every' | ||
'every', | ||
], | ||
@@ -43,16 +43,16 @@ METHOD_ARG = 2, | ||
name: node.callee.property.name, | ||
argument: argument.name | ||
argument: argument.name, | ||
}, | ||
fix(fixer) { | ||
const [ | ||
, previousArgumentEnd | ||
, previousArgumentEnd, | ||
] = node.arguments[parameterPosition + FUNC_POS].range, | ||
[ | ||
, argumentEnd | ||
, argumentEnd, | ||
] = argument.range; | ||
return fixer.removeRange([ | ||
previousArgumentEnd, | ||
argumentEnd | ||
argumentEnd, | ||
]); | ||
} | ||
}, | ||
}); | ||
@@ -72,4 +72,4 @@ }, | ||
name: node.callee.property.name, | ||
argument: argument.name || argument.value || argument.raw | ||
} | ||
argument: argument.name || argument.value || argument.raw, | ||
}, | ||
}); | ||
@@ -82,3 +82,3 @@ }; | ||
description: "Avoid the this parameter when providing arrow function as callback in array functions.", | ||
recommended: true | ||
recommended: true, | ||
}, | ||
@@ -90,4 +90,4 @@ schema: [], | ||
unnecessaryThisArgMethod: "Unnecessary this argument '{{ argument }}' with an arrow function as callback to {{ name }}", | ||
unnecessaryThisArgStatic: "Unnecessary this argument '{{ argument }}' with arrow function as callback to Array.{{ name }}" | ||
} | ||
unnecessaryThisArgStatic: "Unnecessary this argument '{{ argument }}' with arrow function as callback to Array.{{ name }}", | ||
}, | ||
}, | ||
@@ -104,5 +104,5 @@ create(context) { | ||
} | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; |
@@ -15,3 +15,3 @@ /** | ||
description: "Prefer using Array.from over spreading an iterable in an array literal. Using Array.from also preserves the original type of TypedArrays while mapping.", | ||
recommended: true | ||
recommended: true, | ||
}, | ||
@@ -22,4 +22,4 @@ schema: [], | ||
messages: { | ||
preferArrayFrom: "Use Array.from to convert from iterable to array" | ||
} | ||
preferArrayFrom: "Use Array.from to convert from iterable to array", | ||
}, | ||
}, | ||
@@ -36,7 +36,7 @@ create(context) { | ||
return fixer.replaceText(node, `Array.from(${sourceCode.getText(firstElement(node.elements).argument)})`); | ||
} | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; |
@@ -10,3 +10,3 @@ /** | ||
description: "Prefer using the flatMap over an immediate .flat() call after a .map().", | ||
recommended: true | ||
recommended: true, | ||
}, | ||
@@ -17,4 +17,4 @@ fixable: "code", | ||
messages: { | ||
preferFlatMap: "Use flatMap instead of .map().flat()" | ||
} | ||
preferFlatMap: "Use flatMap instead of .map().flat()", | ||
}, | ||
}, | ||
@@ -30,3 +30,3 @@ create(context) { | ||
start: node.callee.property.loc.start, | ||
end: callee.loc.end | ||
end: callee.loc.end, | ||
}, | ||
@@ -36,6 +36,6 @@ messageId: "preferFlatMap", | ||
const [ | ||
, endOfMap | ||
, endOfMap, | ||
] = node.range, | ||
[ | ||
, endOfFlat | ||
, endOfFlat, | ||
] = callee.range; | ||
@@ -46,10 +46,10 @@ return [ | ||
endOfMap, | ||
endOfFlat | ||
]) | ||
endOfFlat, | ||
]), | ||
]; | ||
} | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; |
@@ -9,3 +9,3 @@ /** | ||
secondElement = ([ | ||
, second | ||
, second, | ||
]) => second; | ||
@@ -17,3 +17,3 @@ | ||
description: "Prefer using .flat() over concatenating to flatten an array.", | ||
recommended: true | ||
recommended: true, | ||
}, | ||
@@ -24,4 +24,4 @@ schema: [], | ||
messages: { | ||
preferFlat: "Use flat to flatten an array" | ||
} | ||
preferFlat: "Use flat to flatten an array", | ||
}, | ||
}, | ||
@@ -39,3 +39,3 @@ create(context) { | ||
return fixer.replaceText(node, `${sourceCode.getText(firstElement(node.arguments).argument)}.flat()`); | ||
} | ||
}, | ||
}); | ||
@@ -58,8 +58,8 @@ }, | ||
return fixer.replaceText(node.parent.parent, `${sourceCode.getText(node.parent.parent.callee.object)}.flat()`); | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33309
13
504
457