@angular-eslint/eslint-plugin 17.3.1-alpha.2 → 17.3.1-alpha.4

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
@@ -43,7 +43,7 @@
43
43
  | [`component-class-suffix`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/component-class-suffix.md) | Classes decorated with @Component must have suffix "Component" (or custom) in their name. See more at https://angular.io/styleguide#style-02-03 | :white_check_mark: | | |
44
44
  | [`component-max-inline-declarations`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/component-max-inline-declarations.md) | Enforces a maximum number of lines in inline template, styles and animations. See more at https://angular.io/guide/styleguide#style-05-04 | | | |
45
45
  | [`component-selector`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/component-selector.md) | Component selectors should follow given naming rules. See more at https://angular.io/guide/styleguide#style-02-07, https://angular.io/guide/styleguide#style-05-02 and https://angular.io/guide/styleguide#style-05-03. | | | |
46
- | [`consistent-component-styles`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/consistent-component-styles.md) | Ensures component `styles`/`styleUrl` with `string` is used over `styles`/`styleUrls` when there is only a single string in the array | | :wrench: | |
46
+ | [`consistent-component-styles`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/consistent-component-styles.md) | Ensures consistent usage of `styles`/`styleUrls`/`styleUrl` within Component metadata | | :wrench: | |
47
47
  | [`contextual-decorator`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/contextual-decorator.md) | Ensures that classes use contextual decorators in its body | | | |
48
48
  | [`directive-class-suffix`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/directive-class-suffix.md) | Classes decorated with @Directive must have suffix "Directive" (or custom) in their name. See more at https://angular.io/styleguide#style-02-03 | :white_check_mark: | | |
49
49
  | [`directive-selector`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/directive-selector.md) | Directive selectors should follow given naming rules. See more at https://angular.io/guide/styleguide#style-02-06 and https://angular.io/guide/styleguide#style-02-08. | | | |
@@ -88,7 +88,7 @@
88
88
  <!-- prettier-ignore-start -->
89
89
  | Rule | Replaced by |
90
90
  | --- | --- |
91
- | [`prefer-standalone-component`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-standalone-component.md) | [`prefer-standalone`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-standalone-component.md) |
91
+ | [`prefer-standalone-component`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-standalone-component.md) | [`prefer-standalone`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-standalone.md) |
92
92
  <!-- prettier-ignore-end -->
93
93
 
94
94
  <!-- end deprecated rule list -->
@@ -26,8 +26,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
26
26
  },
27
27
  });
28
28
  function validateNode(context, node) {
29
- var _a;
30
- if (!((_a = node.decorators) === null || _a === void 0 ? void 0 : _a.length)) {
29
+ if (!node.decorators?.length) {
31
30
  return;
32
31
  }
33
32
  const classDeclaration = utils_1.ASTUtils.getNearestNodeFrom(node, utils_1.ASTUtils.isClassDeclaration);
@@ -48,7 +47,7 @@ function validateDecorator(context, decorator, classDecoratorName) {
48
47
  return;
49
48
  }
50
49
  const allowedDecorators = utils_1.ASTUtils.ANGULAR_CLASS_DECORATOR_MAPPER.get(classDecoratorName);
51
- if (allowedDecorators === null || allowedDecorators === void 0 ? void 0 : allowedDecorators.has(decoratorName)) {
50
+ if (allowedDecorators?.has(decoratorName)) {
52
51
  return;
53
52
  }
54
53
  context.report({
@@ -27,7 +27,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
27
27
  const methodName = utils_1.ASTUtils.getMethodName(method);
28
28
  if (!methodName ||
29
29
  !utils_1.ASTUtils.isAngularLifecycleMethod(methodName) ||
30
- (allowedMethods === null || allowedMethods === void 0 ? void 0 : allowedMethods.has(methodName))) {
30
+ allowedMethods?.has(methodName)) {
31
31
  continue;
32
32
  }
33
33
  context.report({
@@ -37,7 +37,6 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
37
37
  create(context, [{ suffixes }]) {
38
38
  return {
39
39
  [utils_1.Selectors.DIRECTIVE_CLASS_DECORATOR](node) {
40
- var _a;
41
40
  const selectorPropertyValue = utils_1.ASTUtils.getDecoratorPropertyValue(node, 'selector');
42
41
  if (!selectorPropertyValue)
43
42
  return;
@@ -49,7 +48,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
49
48
  if (!className ||
50
49
  !allSuffixes.some((suffix) => className.endsWith(suffix))) {
51
50
  context.report({
52
- node: (_a = classParent.id) !== null && _a !== void 0 ? _a : classParent,
51
+ node: classParent.id ?? classParent,
53
52
  messageId: 'directiveClassSuffix',
54
53
  data: { suffixes: (0, utils_1.toHumanReadableText)(allSuffixes) },
55
54
  });
@@ -41,8 +41,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
41
41
  {
42
42
  messageId: 'suggestRemoveLifecycleMethod',
43
43
  fix: (fixer) => {
44
- var _a;
45
- const importDeclarations = (_a = utils_1.ASTUtils.getImportDeclarations(node, '@angular/core')) !== null && _a !== void 0 ? _a : [];
44
+ const importDeclarations = utils_1.ASTUtils.getImportDeclarations(node, '@angular/core') ?? [];
46
45
  const interfaceName = utils_1.ASTUtils.getRawText(node).replace(/^ng+/, '');
47
46
  const text = sourceCode.getText();
48
47
  const totalInterfaceOccurrences = getTotalInterfaceOccurrences(text, interfaceName);
@@ -111,8 +111,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
111
111
  }
112
112
  },
113
113
  [utils_1.Selectors.INPUTS_METADATA_PROPERTY_LITERAL](node) {
114
- var _a, _b, _c, _d;
115
- const ancestorMaybeHostDirectiveAPI = (_d = (_c = (_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.parent;
114
+ const ancestorMaybeHostDirectiveAPI = node.parent?.parent?.parent?.parent?.parent;
116
115
  if (ancestorMaybeHostDirectiveAPI &&
117
116
  utils_1.ASTUtils.isProperty(ancestorMaybeHostDirectiveAPI)) {
118
117
  /**
@@ -24,12 +24,11 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
24
24
  create(context) {
25
25
  return {
26
26
  [`${utils_1.Selectors.COMPONENT_OR_DIRECTIVE_CLASS_DECORATOR} ${utils_1.Selectors.metadataProperty(METADATA_PROPERTY_NAME)}`](node) {
27
- var _a, _b;
28
27
  /**
29
28
  * Angular v15 introduced the directive composition API: https://angular.io/guide/directive-composition-api
30
29
  * Using host directive inputs using this API is not a bad practice and should not be reported
31
30
  */
32
- const ancestorMayBeHostDirectiveAPI = (_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent;
31
+ const ancestorMayBeHostDirectiveAPI = node.parent?.parent?.parent;
33
32
  if (ancestorMayBeHostDirectiveAPI &&
34
33
  utils_1.ASTUtils.isProperty(ancestorMayBeHostDirectiveAPI)) {
35
34
  const hostDirectiveAPIPropertyName = 'hostDirectives';
@@ -66,8 +66,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
66
66
  }
67
67
  },
68
68
  [utils_1.Selectors.OUTPUTS_METADATA_PROPERTY_LITERAL](node) {
69
- var _a, _b, _c, _d;
70
- const ancestorMaybeHostDirectiveAPI = (_d = (_c = (_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.parent;
69
+ const ancestorMaybeHostDirectiveAPI = node.parent?.parent?.parent?.parent?.parent;
71
70
  if (ancestorMaybeHostDirectiveAPI &&
72
71
  utils_1.ASTUtils.isProperty(ancestorMaybeHostDirectiveAPI)) {
73
72
  /**
@@ -24,12 +24,11 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
24
24
  create(context) {
25
25
  return {
26
26
  [`${utils_1.Selectors.COMPONENT_OR_DIRECTIVE_CLASS_DECORATOR} ${utils_1.Selectors.metadataProperty(METADATA_PROPERTY_NAME)}`](node) {
27
- var _a, _b;
28
27
  /**
29
28
  * Angular v15 introduced the directive composition API: https://angular.io/guide/directive-composition-api
30
29
  * Using host directive outputs using this API is not a bad practice and should not be reported
31
30
  */
32
- const ancestorMayBeHostDirectiveAPI = (_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent;
31
+ const ancestorMayBeHostDirectiveAPI = node.parent?.parent?.parent;
33
32
  if (ancestorMayBeHostDirectiveAPI &&
34
33
  utils_1.ASTUtils.isProperty(ancestorMayBeHostDirectiveAPI)) {
35
34
  const hostDirectiveAPIPropertyName = 'hostDirectives';
@@ -26,10 +26,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
26
26
  return {
27
27
  [utils_1.Selectors.COMPONENT_CLASS_DECORATOR](node) {
28
28
  const declaredMethods = utils_1.ASTUtils.getDeclaredMethods(node.parent);
29
- const declaredLifeCycleMethods = declaredMethods.filter((method) => {
30
- var _a;
31
- return utils_1.ASTUtils.isAngularLifecycleMethod((_a = utils_1.ASTUtils.getMethodName(method)) !== null && _a !== void 0 ? _a : '');
32
- });
29
+ const declaredLifeCycleMethods = declaredMethods.filter((method) => utils_1.ASTUtils.isAngularLifecycleMethod(utils_1.ASTUtils.getMethodName(method) ?? ''));
33
30
  for (let i = 1; i < declaredLifeCycleMethods.length; ++i) {
34
31
  const before = isBefore(declaredLifeCycleMethods[i], declaredLifeCycleMethods[i - 1]);
35
32
  if (before) {
@@ -31,8 +31,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
31
31
  {
32
32
  messageId: 'suggestRemoveViewEncapsulationNone',
33
33
  fix: (fixer) => {
34
- var _a;
35
- const importDeclarations = (_a = utils_1.ASTUtils.getImportDeclarations(node, '@angular/core')) !== null && _a !== void 0 ? _a : [];
34
+ const importDeclarations = utils_1.ASTUtils.getImportDeclarations(node, '@angular/core') ?? [];
36
35
  return [
37
36
  utils_1.RuleFixes.getNodeToCommaRemoveFix(sourceCode, node.parent.parent, fixer),
38
37
  utils_1.RuleFixes.getImportRemoveFix(sourceCode, importDeclarations, 'ViewEncapsulation', fixer),
@@ -47,10 +47,9 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
47
47
  suggest: ['any', 'platform', 'root'].map((injector) => ({
48
48
  messageId: 'suggestInjector',
49
49
  fix: (fixer) => {
50
- var _a;
51
50
  return utils_1.ASTUtils.isProperty(node)
52
51
  ? fixer.replaceText(node.value, `'${injector}'`)
53
- : (_a = utils_1.RuleFixes.getDecoratorPropertyAddFix(node, fixer, `${METADATA_PROPERTY_NAME}: '${injector}'`)) !== null && _a !== void 0 ? _a : [];
52
+ : utils_1.RuleFixes.getDecoratorPropertyAddFix(node, fixer, `${METADATA_PROPERTY_NAME}: '${injector}'`) ?? [];
54
53
  },
55
54
  data: { injector },
56
55
  })),
@@ -23,9 +23,8 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
23
23
  create(context) {
24
24
  return {
25
25
  [`ClassDeclaration:not(:has(TSClassImplements:matches([expression.name='${PIPE_TRANSFORM}'], [expression.property.name='${PIPE_TRANSFORM}']))) > Decorator[expression.callee.name='Pipe']`]({ parent: classDeclaration, }) {
26
- var _a;
27
26
  context.report({
28
- node: (_a = classDeclaration.id) !== null && _a !== void 0 ? _a : classDeclaration,
27
+ node: classDeclaration.id ?? classDeclaration,
29
28
  messageId: 'usePipeTransformInterface',
30
29
  fix: (fixer) => {
31
30
  const { implementsNodeReplace, implementsTextReplace } = utils_1.RuleFixes.getImplementsSchemaFixer(classDeclaration, PIPE_TRANSFORM);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/eslint-plugin",
3
- "version": "17.3.1-alpha.2",
3
+ "version": "17.3.1-alpha.4",
4
4
  "description": "ESLint plugin for Angular applications, following angular.io/styleguide",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "LICENSE"
18
18
  ],
19
19
  "dependencies": {
20
- "@angular-eslint/utils": "17.3.1-alpha.2",
20
+ "@angular-eslint/utils": "17.3.1-alpha.4",
21
21
  "@typescript-eslint/utils": "7.2.0"
22
22
  },
23
23
  "peerDependencies": {