Skip to content

Commit 7bb6b7f

Browse files
committed
fix broken rule, set Angular/Typescript as optionalPeerDeps
1 parent ddcb0fc commit 7bb6b7f

10 files changed

+1214
-4400
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module.exports = {
44
root: true,
5-
extends: ['eslint:recommended', 'plugin:eslint-plugin/recommended', 'plugin:node/recommended'],
5+
extends: ['eslint:recommended', 'plugin:eslint-plugin/recommended', 'plugin:n/recommended'],
66
env: {
77
node: true,
88
},

CHANGELOG.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
Please see [the README](./README.md) for details of added rules.
99

10+
## 5.4.0
11+
12+
- no-indexed-access-on-enums - fix missing import that caused eslint to crash when using this rule
13+
- Mark Angular and Typescript peerDependencies as optional
14+
- Switch from eslint-plugin-node to eslint-plugin-n
15+
- eslint-plugin-node is no no longer maintained, eslint-plugin-n is a fork
16+
- no-spreading-accumulators - pass error message in to remove eslint-plugin/prefer-message-ids lint error
17+
1018
## [5.3.0]
1119

1220
- Disable the rule `no-call-expression` from `@angular-eslint/eslint-plugin-template` to allow using [signals](https://angular.dev/guide/signals)
@@ -34,9 +42,9 @@ Please see [the README](./README.md) for details of added rules.
3442
### Changed
3543

3644
- Removal of the rules `deny-constructor-di` and `import-inject-object` from `@rdlabo/eslint-plugin-rules` because the auto-fix has too many issues:
37-
- It applies on irrelevant places cf https://github.com/rdlabo-team/eslint-plugin-rules/issues/1#issuecomment-1980955010
38-
- It gets lost with access modifiers cf https://github.com/rdlabo-team/eslint-plugin-rules/issues/4
39-
- It generates broken code cf https://github.com/rdlabo-team/eslint-plugin-rules/issues/5
45+
- It applies on irrelevant places cf <https://github.com/rdlabo-team/eslint-plugin-rules/issues/1#issuecomment-1980955010>
46+
- It gets lost with access modifiers cf <https://github.com/rdlabo-team/eslint-plugin-rules/issues/4>
47+
- It generates broken code cf <https://github.com/rdlabo-team/eslint-plugin-rules/issues/5>
4048
- Removal of deprecated configurations
4149

4250
## [5.1.0]
@@ -59,7 +67,7 @@ Please see [the README](./README.md) for details of added rules.
5967

6068
### Changed
6169

62-
- Rule `no-indexed-access-on-enums` disabled due to the bug https://github.com/criteo/eslint-plugin-criteo/issues/30
70+
- Rule `no-indexed-access-on-enums` disabled due to the bug <https://github.com/criteo/eslint-plugin-criteo/issues/30>
6371
- Rule `ngx-component-display` now ignores components matching `^.*(?:Dialog|Modal)Component$` (previously, only `^.*DialogComponent$` were ignored)
6472

6573
## [4.12.0]
@@ -165,7 +173,7 @@ Please see [the README](./README.md) for details of added rules.
165173
### Changed
166174

167175
- [BREAKING] Upgrade Angular plugins to version 13 for compatibility with Angular 13
168-
- [BREAKING] Move dependent plugins to peerDependencies so that they appear in the root node_modules (https://github.com/criteo/eslint-plugin-criteo/issues/15)
176+
- [BREAKING] Move dependent plugins to peerDependencies so that they appear in the root node_modules (<https://github.com/criteo/eslint-plugin-criteo/issues/15>)
169177
- [BREAKING] Update `engines` field in package.json to only allow npm versions >= 7
170178

171179
## [3.2.1]

lib/rules/filename-match-export.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
'use strict';
66

7-
const path = require('path');
7+
const path = require('node:path');
88

99
const clean = (value) => (value ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '');
1010

lib/rules/filename.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
'use strict';
66

7-
const path = require('path');
7+
const path = require('node:path');
88
const {
99
COMPONENT_SELECTOR,
1010
STYLE_URL_SELECTOR,

lib/rules/independent-folders.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
'use strict';
66

7-
const path = require('path');
7+
const path = require('node:path');
88

99
const isUnderPath = (folderPath, targetPath) => {
1010
const relative = path.relative(folderPath, targetPath);
@@ -87,8 +87,8 @@ module.exports = {
8787
buildReport(
8888
node,
8989
featureFolderIndex !== -1 ? featureFolders[featureFolderIndex] : sharedFolders[sharedFolderIndex],
90-
otherFeatureFolders[featureFolderImportedIndex]
91-
)
90+
otherFeatureFolders[featureFolderImportedIndex],
91+
),
9292
);
9393
}
9494
},

lib/rules/ngx-component-display.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = {
7070

7171
// Try to get the HostBinding decorator
7272
const decorator = (displayNode.decorators || []).find(
73-
(decorator) => decorator.expression.callee.name === 'HostBinding'
73+
(decorator) => decorator.expression.callee.name === 'HostBinding',
7474
);
7575

7676
if (!decorator) {

lib/rules/no-indexed-access-on-enums.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
'use strict';
77

8+
const ts = require('typescript');
89
const moreInfo = `More info: https://github.com/criteo/eslint-plugin-criteo#no-indexed-access-on-enums`;
910

1011
module.exports = {

lib/rules/no-spreading-accumulators.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ module.exports = {
1212
type: 'problem',
1313
fixable: 'code',
1414
schema: [],
15+
messages: {
16+
objectMessage: `Creating a new object by spreading the previous accumulator at every iteration of a .reduce() call has O(n^2) time & spatial complexity. If possible, make this O(n) by assigning to the existing accumulator or use mappedBy() or mappedByUnique() instead of .reduce(). ${moreInfo}`,
17+
arrayMessage: `Creating a new array by spreading the previous accumulator at every iteration of a .reduce() call has O(n^2) time & spatial complexity. If possible, make this O(n) by pushing to the existing accumulator instead. ${moreInfo}`,
18+
},
1519
},
1620
create: function (context) {
1721
return {
1822
'CallExpression:has([callee.property.name=reduce])[arguments] > ArrowFunctionExpression'(node) {
19-
const objectMessage = `Creating a new object by spreading the previous accumulator at every iteration of a .reduce() call has O(n^2) time & spatial complexity. If possible, make this O(n) by assigning to the existing accumulator or use mappedBy() or mappedByUnique() instead of .reduce(). ${moreInfo}`;
20-
const arrayMessage = `Creating a new array by spreading the previous accumulator at every iteration of a .reduce() call has O(n^2) time & spatial complexity. If possible, make this O(n) by pushing to the existing accumulator instead. ${moreInfo}`;
21-
2223
// only fetch the source code if getNodeText is called, and only fetch it once if we do
2324
const sourceCode = {
2425
_source: null,
@@ -29,10 +30,10 @@ module.exports = {
2930
},
3031
};
3132

32-
const getReportConfig = (spreadNode, fix, message) => ({
33+
const getReportConfig = (spreadNode, fix, messageId) => ({
3334
node: spreadNode.argument,
3435
loc: spreadNode.loc,
35-
message,
36+
messageId,
3637
fix,
3738
});
3839

@@ -83,7 +84,7 @@ module.exports = {
8384
const nonSpreadPropertyTexts = expression.properties
8485
.filter((o, i) => i != spreadIndex)
8586
.map(
86-
(o) => `${arrowFnFirstArgName}[${sourceCode.getNodeText(o.key)}] = ${sourceCode.getNodeText(o.value)}`
87+
(o) => `${arrowFnFirstArgName}[${sourceCode.getNodeText(o.key)}] = ${sourceCode.getNodeText(o.value)}`,
8788
);
8889
if (nonSpreadPropertyTexts.length <= 0) return undefined;
8990

@@ -92,7 +93,7 @@ module.exports = {
9293
const fix = (fixer) => [fixer.replaceTextRange(arrowFn.range, newArrowFnText)];
9394
return fix;
9495
};
95-
const reportConfig = getReportConfig(spreadNode, getObjectFix(), objectMessage);
96+
const reportConfig = getReportConfig(spreadNode, getObjectFix(), 'objectMessage');
9697
return context.report(reportConfig);
9798
} else if (expression.type === 'ArrayExpression') {
9899
let spreadIndex = null;
@@ -130,13 +131,13 @@ module.exports = {
130131
if (!nonSpreadElementTexts || nonSpreadElementTexts.length <= 0) return undefined;
131132

132133
const bodyText = `${arrowFnFirstArgName}.push(${nonSpreadElementTexts.join(
133-
', '
134+
', ',
134135
)}); return ${arrowFnFirstArgName};`;
135136
const newArrowFnText = `(${paramsText}) => { ${bodyText} }`;
136137
const fix = (fixer) => [fixer.replaceTextRange(arrowFn.range, newArrowFnText)];
137138
return fix;
138139
};
139-
const reportConfig = getReportConfig(spreadNode, getArrayFix(), arrayMessage);
140+
const reportConfig = getReportConfig(spreadNode, getArrayFix(), 'arrayMessage');
140141
return context.report(reportConfig);
141142
}
142143
},

0 commit comments

Comments
 (0)