@angular-eslint/eslint-plugin 16.1.3-alpha.0 → 16.1.3-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.
@@ -30,6 +30,7 @@
30
30
  "@angular-eslint/prefer-standalone-component": "error",
31
31
  "@angular-eslint/relative-url-prefix": "error",
32
32
  "@angular-eslint/require-localize-metadata": "error",
33
+ "@angular-eslint/sort-lifecycle-methods": "error",
33
34
  "@angular-eslint/sort-ngmodule-metadata-arrays": "error",
34
35
  "@angular-eslint/use-component-selector": "error",
35
36
  "@angular-eslint/use-component-view-encapsulation": "error",
package/dist/index.js CHANGED
@@ -55,6 +55,7 @@ const prefer_output_readonly_1 = __importStar(require("./rules/prefer-output-rea
55
55
  const prefer_standalone_component_1 = __importStar(require("./rules/prefer-standalone-component"));
56
56
  const relative_url_prefix_1 = __importStar(require("./rules/relative-url-prefix"));
57
57
  const require_localize_metadata_1 = __importStar(require("./rules/require-localize-metadata"));
58
+ const sort_lifecycle_methods_1 = __importStar(require("./rules/sort-lifecycle-methods"));
58
59
  const sort_ngmodule_metadata_arrays_1 = __importStar(require("./rules/sort-ngmodule-metadata-arrays"));
59
60
  const use_component_selector_1 = __importStar(require("./rules/use-component-selector"));
60
61
  const use_component_view_encapsulation_1 = __importStar(require("./rules/use-component-view-encapsulation"));
@@ -91,10 +92,11 @@ module.exports = {
91
92
  [no_queries_metadata_property_1.RULE_NAME]: no_queries_metadata_property_1.default,
92
93
  [pipe_prefix_1.RULE_NAME]: pipe_prefix_1.default,
93
94
  [prefer_on_push_component_change_detection_1.RULE_NAME]: prefer_on_push_component_change_detection_1.default,
94
- [prefer_output_readonly_1.RULE_NAME]: prefer_output_readonly_1.default,
95
95
  [prefer_standalone_component_1.RULE_NAME]: prefer_standalone_component_1.default,
96
+ [prefer_output_readonly_1.RULE_NAME]: prefer_output_readonly_1.default,
96
97
  [relative_url_prefix_1.RULE_NAME]: relative_url_prefix_1.default,
97
98
  [require_localize_metadata_1.RULE_NAME]: require_localize_metadata_1.default,
99
+ [sort_lifecycle_methods_1.RULE_NAME]: sort_lifecycle_methods_1.default,
98
100
  [sort_ngmodule_metadata_arrays_1.RULE_NAME]: sort_ngmodule_metadata_arrays_1.default,
99
101
  [use_component_selector_1.RULE_NAME]: use_component_selector_1.default,
100
102
  [use_component_view_encapsulation_1.RULE_NAME]: use_component_view_encapsulation_1.default,
@@ -0,0 +1,46 @@
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 = 'sort-lifecycle-methods';
7
+ exports.default = (0, create_eslint_rule_1.createESLintRule)({
8
+ name: exports.RULE_NAME,
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: 'Ensures that lifecycle methods are declared in order of execution',
13
+ recommended: false,
14
+ },
15
+ schema: [],
16
+ messages: {
17
+ lifecycleMethodsNotSorted: `Lifecycle Methods are not declared in order of execution`,
18
+ },
19
+ },
20
+ defaultOptions: [],
21
+ create(context) {
22
+ const isBefore = (method1, method2) => {
23
+ const methodIndex1 = utils_1.ASTUtils.angularLifecycleMethodsOrdered.indexOf(utils_1.ASTUtils.getMethodName(method1));
24
+ const methodIndex2 = utils_1.ASTUtils.angularLifecycleMethodsOrdered.indexOf(utils_1.ASTUtils.getMethodName(method2));
25
+ return methodIndex1 < methodIndex2;
26
+ };
27
+ return {
28
+ [utils_1.Selectors.COMPONENT_CLASS_DECORATOR](node) {
29
+ const declaredMethods = utils_1.ASTUtils.getDeclaredMethods(node.parent);
30
+ const declaredLifeCycleMethods = declaredMethods.filter((method) => {
31
+ var _a;
32
+ return utils_1.ASTUtils.isAngularLifecycleMethod((_a = utils_1.ASTUtils.getMethodName(method)) !== null && _a !== void 0 ? _a : '');
33
+ });
34
+ for (let i = 1; i < declaredLifeCycleMethods.length; ++i) {
35
+ const before = isBefore(declaredLifeCycleMethods[i], declaredLifeCycleMethods[i - 1]);
36
+ if (before) {
37
+ context.report({
38
+ node: declaredLifeCycleMethods[i].key,
39
+ messageId: 'lifecycleMethodsNotSorted',
40
+ });
41
+ }
42
+ }
43
+ },
44
+ };
45
+ },
46
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/eslint-plugin",
3
- "version": "16.1.3-alpha.0+2e4af4d",
3
+ "version": "16.1.3-alpha.7+470e12b",
4
4
  "description": "ESLint plugin for Angular applications, following angular.io/styleguide",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -17,12 +17,12 @@
17
17
  "LICENSE"
18
18
  ],
19
19
  "dependencies": {
20
- "@angular-eslint/utils": "16.1.3-alpha.0+2e4af4d",
20
+ "@angular-eslint/utils": "16.1.3-alpha.7+470e12b",
21
21
  "@typescript-eslint/utils": "5.62.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "eslint": "^7.20.0 || ^8.0.0",
25
25
  "typescript": "*"
26
26
  },
27
- "gitHead": "2e4af4d7e60c4ceb7a65a5fa5ed8fde102291c01"
27
+ "gitHead": "470e12b5b482857735e2140e3524a5726d4fc6a8"
28
28
  }