@angular-eslint/eslint-plugin-template 19.2.1-alpha.4 → 19.2.1

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":"prefer-self-closing-tags.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-self-closing-tags.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,uBAAuB,CAAC;AACjD,eAAO,MAAM,SAAS,6BAA6B,CAAC;;AAEpD,wBAiJG"}
1
+ {"version":3,"file":"prefer-self-closing-tags.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-self-closing-tags.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,uBAAuB,CAAC;AACjD,eAAO,MAAM,SAAS,6BAA6B,CAAC;;AAEpD,wBA+JG"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RULE_NAME = void 0;
4
+ const bundled_angular_compiler_1 = require("@angular-eslint/bundled-angular-compiler");
4
5
  const utils_1 = require("@angular-eslint/utils");
5
6
  const create_eslint_rule_1 = require("../utils/create-eslint-rule");
6
7
  const get_dom_elements_1 = require("../utils/get-dom-elements");
@@ -41,30 +42,40 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
41
42
  },
42
43
  };
43
44
  function processElementOrTemplateNode(node) {
44
- const { startSourceSpan, endSourceSpan } = node;
45
+ const { children, startSourceSpan, endSourceSpan } = node;
45
46
  if (!endSourceSpan ||
46
47
  (startSourceSpan.start.offset === endSourceSpan.start.offset &&
47
48
  startSourceSpan.end.offset === endSourceSpan.end.offset)) {
48
49
  // No close tag.
49
50
  return;
50
51
  }
52
+ const someChildNodesHaveContent = children.some((node) => {
53
+ // If the node is only whitespace, we can consider it empty.
54
+ //
55
+ // We need to look at the text from the source code, rather
56
+ // than the `TmplAstText.value` property. The `value` property
57
+ // contains the HTML-decoded value, so if the raw text contains
58
+ // ` `, that is decoded to a space, but we don't want to
59
+ // treat that as empty text.
60
+ return (!(node instanceof bundled_angular_compiler_1.TmplAstText) ||
61
+ context.sourceCode.text
62
+ .slice(node.sourceSpan.start.offset, node.sourceSpan.end.offset)
63
+ .trim() !== '');
64
+ });
51
65
  // If the element only contains whitespace, we can consider it
52
- // empty. We cannot use the children to reliably determine whether
53
- // the element only contains whitespace because the template
54
- // parser will HTML-decoded the text. For example, if the raw
55
- // content contains ` `, that is decoded to a space, but
56
- // we need to treat that as content that should be kept.
66
+ // empty.
57
67
  //
58
- // Likewise, if the node only contains comments, those comments
68
+ // If the node only contains comments, those comments
59
69
  // will not appear in the syntax tree, which results in the
60
70
  // content appearing empty.
61
71
  //
62
72
  // So instead of using the syntax tree, we'll look at the
63
73
  // source code and get the text that appears between the
64
74
  // start element and the end element.
65
- if (context.sourceCode.text
75
+ const nodeHasContent = context.sourceCode.text
66
76
  .slice(startSourceSpan.end.offset, endSourceSpan.start.offset)
67
- .trim() !== '') {
77
+ .trim() !== '';
78
+ if (nodeHasContent || someChildNodesHaveContent) {
68
79
  // The element has content.
69
80
  return;
70
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/eslint-plugin-template",
3
- "version": "19.2.1-alpha.4",
3
+ "version": "19.2.1",
4
4
  "description": "ESLint plugin for Angular Templates",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -20,13 +20,13 @@
20
20
  "dependencies": {
21
21
  "aria-query": "5.3.2",
22
22
  "axobject-query": "4.1.0",
23
- "@angular-eslint/bundled-angular-compiler": "19.2.1-alpha.4",
24
- "@angular-eslint/utils": "19.2.1-alpha.4"
23
+ "@angular-eslint/bundled-angular-compiler": "19.2.1",
24
+ "@angular-eslint/utils": "19.2.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/aria-query": "5.0.4",
28
- "@angular-eslint/template-parser": "19.2.1-alpha.4",
29
- "@angular-eslint/test-utils": "19.2.1-alpha.4"
28
+ "@angular-eslint/template-parser": "19.2.1",
29
+ "@angular-eslint/test-utils": "19.2.1"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@typescript-eslint/types": "^7.11.0 || ^8.0.0",