@smarterdrafter/eslint-plugin-angular 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Smarter Drafter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @smarterdrafter/eslint-plugin-angular
2
+
3
+ Smarter Drafter shared ESLint rules for Angular templates.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install --save-dev @smarterdrafter/eslint-plugin-angular
9
+ ```
10
+
11
+ In your `.eslintrc.json`, add the plugin and enable the rules inside the HTML override:
12
+
13
+ ```jsonc
14
+ {
15
+ "overrides": [
16
+ {
17
+ "files": ["*.html"],
18
+ "extends": ["plugin:@angular-eslint/template/recommended"],
19
+ "plugins": ["@smarterdrafter/angular"],
20
+ "rules": {
21
+ "@smarterdrafter/angular/no-static-string-property-binding": "error"
22
+ }
23
+ }
24
+ ]
25
+ }
26
+ ```
27
+
28
+ ## Rules
29
+
30
+ ### `no-static-string-property-binding`
31
+
32
+ Disallows property bindings whose value is a bare string literal. Under Angular's `strictTemplates`, both forms get the same type check against the input's declared type, so the bracket form adds visual noise without any safety benefit.
33
+
34
+ ```html
35
+ <!-- ✗ flagged + auto-fixable -->
36
+ <app-alert [type]="'warning'" />
37
+ <app-button [iconPosition]="'end'" />
38
+ <img [src]="'/assets/logo.png'" />
39
+
40
+ <!-- ✓ preferred -->
41
+ <app-alert type="warning" />
42
+ <app-button iconPosition="end" />
43
+ <img src="/assets/logo.png" />
44
+
45
+ <!-- ✓ not flagged — these legitimately need the brackets -->
46
+ <app-button [type]="buttonType" />
47
+ <app-button [count]="5" />
48
+ <app-button [disabled]="true" />
49
+ <app-alert [type]="isError ? 'danger' : 'success'" />
50
+ <button [attr.aria-label]="'Close'" />
51
+ ```
52
+
53
+ Auto-fix rewrites `[name]="'value'"` → `name="value"`. The fix is skipped if the literal value contains a character that would need HTML-escaping (`"`, `<`, `>`, `&`) — the violation is still reported, you just fix it by hand.
54
+
55
+ ## License
56
+
57
+ MIT
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ rules: {
5
+ 'no-static-string-property-binding': require('./rules/no-static-string-property-binding'),
6
+ },
7
+ };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@smarterdrafter/eslint-plugin-angular",
3
+ "version": "1.0.0",
4
+ "description": "Smarter Drafter shared ESLint rules for Angular templates",
5
+ "main": "index.js",
6
+ "files": [
7
+ "index.js",
8
+ "rules/",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "keywords": [
13
+ "eslint",
14
+ "eslintplugin",
15
+ "eslint-plugin",
16
+ "angular",
17
+ "angular-template"
18
+ ],
19
+ "license": "MIT",
20
+ "author": "Smarter Drafter",
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "peerDependencies": {
25
+ "@angular-eslint/eslint-plugin-template": ">=17.0.0",
26
+ "eslint": ">=8.0.0"
27
+ }
28
+ }
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const BINDING_TYPE_PROPERTY = 0;
4
+
5
+ module.exports = {
6
+ meta: {
7
+ type: 'suggestion',
8
+ docs: {
9
+ description:
10
+ 'Prefer plain attributes (`name="value"`) over property bindings whose value is a bare string literal (`[name]="\'value\'"`).',
11
+ },
12
+ fixable: 'code',
13
+ schema: [],
14
+ messages: {
15
+ preferPlainAttribute:
16
+ 'Use plain attribute `{{name}}="{{value}}"` instead of property binding to a static string. Under strictTemplates the type check is the same, and the brackets add visual noise.',
17
+ },
18
+ },
19
+ create(context) {
20
+ const sourceCode = context.sourceCode || context.getSourceCode();
21
+
22
+ return {
23
+ BoundAttribute(node) {
24
+ if (node.__originalType !== BINDING_TYPE_PROPERTY) {
25
+ return;
26
+ }
27
+
28
+ const ast = node.value && node.value.ast;
29
+ if (!ast || ast.constructor.name !== 'LiteralPrimitive') {
30
+ return;
31
+ }
32
+ if (typeof ast.value !== 'string') {
33
+ return;
34
+ }
35
+
36
+ const stringValue = ast.value;
37
+ const start = node.sourceSpan.start.offset;
38
+ const end = node.sourceSpan.end.offset;
39
+
40
+ const canFix = !/["<>&]/.test(stringValue);
41
+
42
+ context.report({
43
+ loc: {
44
+ start: sourceCode.getLocFromIndex(start),
45
+ end: sourceCode.getLocFromIndex(end),
46
+ },
47
+ messageId: 'preferPlainAttribute',
48
+ data: { name: node.name, value: stringValue },
49
+ fix: canFix
50
+ ? (fixer) => fixer.replaceTextRange([start, end], `${node.name}="${stringValue}"`)
51
+ : undefined,
52
+ });
53
+ },
54
+ };
55
+ },
56
+ };