@angular-eslint/eslint-plugin 20.5.1-alpha.4 → 20.5.1-alpha.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"no-uncalled-signals.d.ts","sourceRoot":"","sources":["../../src/rules/no-uncalled-signals.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EAGZ,MAAM,0BAA0B,CAAC;AAIlC,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AACnE,eAAO,MAAM,SAAS,wBAAwB,CAAC;;AAE/C,wBA0DG"}
1
+ {"version":3,"file":"no-uncalled-signals.d.ts","sourceRoot":"","sources":["../../src/rules/no-uncalled-signals.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EAGZ,MAAM,0BAA0B,CAAC;AAIlC,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AACnE,eAAO,MAAM,SAAS,wBAAwB,CAAC;;AAW/C,wBAwEG"}
@@ -5,6 +5,14 @@ const utils_1 = require("@typescript-eslint/utils");
5
5
  const create_eslint_rule_1 = require("../utils/create-eslint-rule");
6
6
  const signals_1 = require("../utils/signals");
7
7
  exports.RULE_NAME = 'no-uncalled-signals';
8
+ const CONDITIONAL_SELECTOR = [
9
+ utils_1.AST_NODE_TYPES.ConditionalExpression,
10
+ utils_1.AST_NODE_TYPES.DoWhileStatement,
11
+ utils_1.AST_NODE_TYPES.ForStatement,
12
+ utils_1.AST_NODE_TYPES.IfStatement,
13
+ utils_1.AST_NODE_TYPES.SwitchCase,
14
+ utils_1.AST_NODE_TYPES.WhileStatement,
15
+ ].join(',');
8
16
  exports.default = (0, create_eslint_rule_1.createESLintRule)({
9
17
  name: exports.RULE_NAME,
10
18
  meta: {
@@ -22,34 +30,42 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
22
30
  defaultOptions: [],
23
31
  create(context) {
24
32
  const services = utils_1.ESLintUtils.getParserServices(context);
33
+ function checkForUncalledSignal(node) {
34
+ // Unwrap negated expressions so that
35
+ // we look at what was being negated.
36
+ if (node.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
37
+ node.operator === '!') {
38
+ node = node.argument;
39
+ }
40
+ const type = services.getTypeAtLocation(node);
41
+ const identifierType = type.getSymbol()?.name;
42
+ if (identifierType && signals_1.KNOWN_SIGNAL_TYPES.has(identifierType)) {
43
+ context.report({
44
+ node,
45
+ messageId: 'noUncalledSignals',
46
+ suggest: [
47
+ {
48
+ messageId: 'suggestCallSignal',
49
+ fix: (fixer) => fixer.insertTextAfter(node, '()'),
50
+ },
51
+ ],
52
+ });
53
+ }
54
+ }
25
55
  return {
26
- '*.test[type=Identifier],*.test Identifier,[type=LogicalExpression] Identifier'(node) {
27
- if (node.parent.type === utils_1.AST_NODE_TYPES.CallExpression) {
28
- return;
29
- }
30
- // Check if this identifier is the property or object in a MemberExpression that's being called.
31
- // If the identifier is a signal and it's being called, then the signal's value is being read.
32
- // If it's the object, then a method on the signal (most likely the `set` method) is being called.
33
- if (node.parent.type === utils_1.AST_NODE_TYPES.MemberExpression &&
34
- (node.parent.object === node || node.parent.property === node) &&
35
- node.parent.parent?.type === utils_1.AST_NODE_TYPES.CallExpression) {
36
- return;
37
- }
38
- const type = services.getTypeAtLocation(node);
39
- const identifierType = type.getSymbol()?.name;
40
- if (identifierType && signals_1.KNOWN_SIGNAL_TYPES.has(identifierType)) {
41
- context.report({
42
- node,
43
- messageId: 'noUncalledSignals',
44
- suggest: [
45
- {
46
- messageId: 'suggestCallSignal',
47
- fix: (fixer) => fixer.replaceText(node, `${node.name}()`),
48
- },
49
- ],
50
- });
56
+ [CONDITIONAL_SELECTOR](node) {
57
+ if (node.test) {
58
+ checkForUncalledSignal(node.test);
51
59
  }
52
60
  },
61
+ LogicalExpression(node) {
62
+ checkForUncalledSignal(node.left);
63
+ checkForUncalledSignal(node.right);
64
+ },
65
+ BinaryExpression(node) {
66
+ checkForUncalledSignal(node.left);
67
+ checkForUncalledSignal(node.right);
68
+ },
53
69
  };
54
70
  },
55
71
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/eslint-plugin",
3
- "version": "20.5.1-alpha.4",
3
+ "version": "20.5.1-alpha.6",
4
4
  "description": "ESLint plugin for Angular applications, following https://angular.dev/style-guide",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -19,11 +19,11 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "ts-api-utils": "^2.1.0",
22
- "@angular-eslint/bundled-angular-compiler": "20.5.1-alpha.4",
23
- "@angular-eslint/utils": "20.5.1-alpha.4"
22
+ "@angular-eslint/bundled-angular-compiler": "20.5.1-alpha.6",
23
+ "@angular-eslint/utils": "20.5.1-alpha.6"
24
24
  },
25
25
  "devDependencies": {
26
- "@angular-eslint/test-utils": "20.5.1-alpha.4"
26
+ "@angular-eslint/test-utils": "20.5.1-alpha.6"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@typescript-eslint/utils": "^7.11.0 || ^8.0.0",