@angular-eslint/eslint-plugin 17.1.2-alpha.5 → 17.1.2-alpha.7

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
@@ -20,6 +20,7 @@
20
20
  | Rule | Description | :white_check_mark: | :wrench: | :bulb: |
21
21
  | --- | --- | --- | --- | --- |
22
22
  | [`contextual-lifecycle`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/contextual-lifecycle.md) | Ensures that lifecycle methods are used in a correct context | :white_check_mark: | | |
23
+ | [`no-async-lifecycle-method`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/no-async-lifecycle-method.md) | Angular Lifecycle methods should not be async. Angular does not wait for async lifecycle but the code incorrectly suggests it does. | | | |
23
24
  | [`no-attribute-decorator`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/no-attribute-decorator.md) | The @Attribute decorator is used to obtain a single value for an attribute. This is a much less common use-case than getting a stream of values (using @Input), so often the @Attribute decorator is mistakenly used when @Input was what was intended. This rule disallows usage of @Attribute decorator altogether in order to prevent these mistakes. | | | |
24
25
  | [`sort-lifecycle-methods`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/sort-lifecycle-methods.md) | Ensures that lifecycle methods are declared in order of execution | | | |
25
26
  <!-- prettier-ignore-end -->
@@ -9,6 +9,7 @@
9
9
  "@angular-eslint/contextual-lifecycle": "error",
10
10
  "@angular-eslint/directive-class-suffix": "error",
11
11
  "@angular-eslint/directive-selector": "error",
12
+ "@angular-eslint/no-async-lifecycle-method": "error",
12
13
  "@angular-eslint/no-attribute-decorator": "error",
13
14
  "@angular-eslint/no-conflicting-lifecycle": "error",
14
15
  "@angular-eslint/no-empty-lifecycle-method": "error",
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ const contextual_decorator_1 = __importStar(require("./rules/contextual-decorato
34
34
  const contextual_lifecycle_1 = __importStar(require("./rules/contextual-lifecycle"));
35
35
  const directive_class_suffix_1 = __importStar(require("./rules/directive-class-suffix"));
36
36
  const directive_selector_1 = __importStar(require("./rules/directive-selector"));
37
+ const no_async_lifecycle_method_1 = __importStar(require("./rules/no-async-lifecycle-method"));
37
38
  const no_attribute_decorator_1 = __importStar(require("./rules/no-attribute-decorator"));
38
39
  const no_conflicting_lifecycle_1 = __importStar(require("./rules/no-conflicting-lifecycle"));
39
40
  const no_empty_lifecycle_method_1 = __importStar(require("./rules/no-empty-lifecycle-method"));
@@ -75,6 +76,7 @@ module.exports = {
75
76
  [contextual_lifecycle_1.RULE_NAME]: contextual_lifecycle_1.default,
76
77
  [directive_class_suffix_1.RULE_NAME]: directive_class_suffix_1.default,
77
78
  [directive_selector_1.RULE_NAME]: directive_selector_1.default,
79
+ [no_async_lifecycle_method_1.RULE_NAME]: no_async_lifecycle_method_1.default,
78
80
  [no_attribute_decorator_1.RULE_NAME]: no_attribute_decorator_1.default,
79
81
  [no_conflicting_lifecycle_1.RULE_NAME]: no_conflicting_lifecycle_1.default,
80
82
  [no_empty_lifecycle_method_1.RULE_NAME]: no_empty_lifecycle_method_1.default,
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RULE_NAME = void 0;
4
+ const utils_1 = require("@angular-eslint/utils");
5
+ const create_eslint_rule_1 = require("../utils/create-eslint-rule");
6
+ exports.RULE_NAME = 'no-async-lifecycle-method';
7
+ exports.default = (0, create_eslint_rule_1.createESLintRule)({
8
+ name: exports.RULE_NAME,
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: `Angular Lifecycle methods should not be async. Angular does not wait for async lifecycle but the code incorrectly suggests it does.`,
13
+ },
14
+ schema: [],
15
+ messages: {
16
+ noAsyncLifecycleMethod: 'Angular Lifecycle method should not be async',
17
+ },
18
+ },
19
+ defaultOptions: [],
20
+ create(context) {
21
+ const angularDecoratorsPattern = (0, utils_1.toPattern)([
22
+ 'Component',
23
+ 'Directive',
24
+ 'Injectable',
25
+ 'NgModule',
26
+ 'Pipe',
27
+ ]);
28
+ const angularLifecycleMethodsPattern = (0, utils_1.toPattern)([
29
+ ...utils_1.ASTUtils.ANGULAR_LIFECYCLE_METHODS,
30
+ ]);
31
+ return {
32
+ [`${utils_1.Selectors.decoratorDefinition(angularDecoratorsPattern)} > ClassBody > MethodDefinition[key.name=${angularLifecycleMethodsPattern}]`](node) {
33
+ if (node.value.async === true) {
34
+ context.report({
35
+ node: node.key,
36
+ messageId: 'noAsyncLifecycleMethod',
37
+ });
38
+ }
39
+ },
40
+ };
41
+ },
42
+ });
@@ -22,11 +22,18 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
22
22
  defaultOptions: [],
23
23
  create(context) {
24
24
  const sourceCode = context.getSourceCode();
25
+ const angularDecoratorsPattern = (0, utils_1.toPattern)([
26
+ 'Component',
27
+ 'Directive',
28
+ 'Injectable',
29
+ 'NgModule',
30
+ 'Pipe',
31
+ ]);
25
32
  const angularLifecycleMethodsPattern = (0, utils_1.toPattern)([
26
33
  ...utils_1.ASTUtils.ANGULAR_LIFECYCLE_METHODS,
27
34
  ]);
28
35
  return {
29
- [`ClassDeclaration:has(Decorator[expression.callee.name=/^(Component|Directive|Injectable|NgModule|Pipe)$/]) > ClassBody > ${utils_1.Selectors.methodDefinition(angularLifecycleMethodsPattern)}[value.body.body.length=0]`](node) {
36
+ [`${utils_1.Selectors.decoratorDefinition(angularDecoratorsPattern)} > ClassBody > ${utils_1.Selectors.methodDefinition(angularLifecycleMethodsPattern)}[value.body.body.length=0]`](node) {
30
37
  context.report({
31
38
  node,
32
39
  messageId: 'noEmptyLifecycleMethod',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/eslint-plugin",
3
- "version": "17.1.2-alpha.5",
3
+ "version": "17.1.2-alpha.7",
4
4
  "description": "ESLint plugin for Angular applications, following angular.io/styleguide",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -17,8 +17,8 @@
17
17
  "LICENSE"
18
18
  ],
19
19
  "dependencies": {
20
- "@angular-eslint/utils": "17.1.2-alpha.5",
21
- "@typescript-eslint/utils": "6.13.1"
20
+ "@angular-eslint/utils": "17.1.2-alpha.7",
21
+ "@typescript-eslint/utils": "6.18.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "eslint": "^7.20.0 || ^8.0.0",