Skip to content

Commit b0bcf7e

Browse files
committed
compare current to sorted
1 parent 52a34d4 commit b0bcf7e

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

lib/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ const requireIndex = require('requireindex');
1818

1919
// import all rules in lib/rules
2020
module.exports.rules = requireIndex(__dirname + '/rules');
21-
22-
23-

lib/rules/sort-react-dependency-arrays.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ module.exports = {
3838
const dependencies = node.arguments[1];
3939

4040
if (dependencies && dependencies.type === 'ArrayExpression' && dependencies.elements.length > 1) {
41+
const currentNames = dependencies.elements.map(item => item.name);
4142
const sorted = [...dependencies.elements].sort((a, b) => (a.name < b.name ? -1 : 1));
4243
const sortedNames = sorted.map((dep) => dep.name);
4344

44-
context.report({
45-
node,
46-
message: 'Sorting dependencies',
47-
fix: function (fixer) {
48-
return fixer.replaceText(dependencies, `[${sortedNames}]`);
49-
}
50-
});
45+
if (String(currentNames) !== String(sortedNames)) {
46+
context.report({
47+
node,
48+
message: 'Sorting dependencies',
49+
fix: function (fixer) {
50+
return fixer.replaceText(dependencies, `[${sortedNames}]`);
51+
}
52+
});
53+
}
5154
}
5255
}
5356
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "eslint-plugin-sort-react-dependency-arrays",
33
"description": "ESLint plugin to alphabetically sort React hook dependency arrays",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"author": "Steven Sacks <[email protected]>",
66
"keywords": [
77
"eslint",

0 commit comments

Comments
 (0)