@yoo-digital/eslint-plugin-angular 0.1.9

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 ADDED
@@ -0,0 +1,6 @@
1
+ # eslint-plugin-angular
2
+
3
+ ## eslint-plugin-angular
4
+
5
+ To define custom lint rules for Angular. Similar to eslint-config-angular where existing rules are set.
6
+
@@ -0,0 +1,15 @@
1
+ export declare const rules: Record<string, any>;
2
+ export declare const configs: {
3
+ default: {
4
+ plugins: string[];
5
+ rules: {
6
+ '@yoo-digital/angular/prefer-boolean-attribute-shorthand': string;
7
+ };
8
+ };
9
+ recommended: {
10
+ plugins: string[];
11
+ rules: {
12
+ '@yoo-digital/angular/prefer-boolean-attribute-shorthand': string;
13
+ };
14
+ };
15
+ };
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configs = exports.rules = void 0;
4
+ const rules_1 = require("./rules");
5
+ exports.rules = {
6
+ 'prefer-boolean-attribute-shorthand': rules_1.preferBooleanAttributeShorthandRule,
7
+ };
8
+ exports.configs = {
9
+ default: {
10
+ plugins: ['@yoo-digital/eslint-plugin-angular'],
11
+ rules: {
12
+ '@yoo-digital/angular/prefer-boolean-attribute-shorthand': 'warn',
13
+ },
14
+ },
15
+ recommended: {
16
+ plugins: ['@yoo-digital/eslint-plugin-angular'],
17
+ rules: {
18
+ '@yoo-digital/angular/prefer-boolean-attribute-shorthand': 'error',
19
+ },
20
+ },
21
+ };
22
+ module.exports = {
23
+ rules: exports.rules,
24
+ configs: exports.configs,
25
+ };
@@ -0,0 +1 @@
1
+ export { preferBooleanAttributeShorthandRule, RULE_NAME } from './prefer-boolean-attribute-shorthand';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RULE_NAME = exports.preferBooleanAttributeShorthandRule = void 0;
4
+ var prefer_boolean_attribute_shorthand_1 = require("./prefer-boolean-attribute-shorthand");
5
+ Object.defineProperty(exports, "preferBooleanAttributeShorthandRule", { enumerable: true, get: function () { return prefer_boolean_attribute_shorthand_1.preferBooleanAttributeShorthandRule; } });
6
+ Object.defineProperty(exports, "RULE_NAME", { enumerable: true, get: function () { return prefer_boolean_attribute_shorthand_1.RULE_NAME; } });
@@ -0,0 +1,8 @@
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ interface Options {
3
+ allowFalseLiteral?: boolean;
4
+ }
5
+ type MessageIds = 'preferTrue' | 'preferFalse' | 'suggestTrue' | 'suggestRemove';
6
+ export declare const RULE_NAME = "prefer-boolean-attribute-shorthand";
7
+ export declare const preferBooleanAttributeShorthandRule: TSESLint.RuleModule<MessageIds, Options[]>;
8
+ export {};
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.preferBooleanAttributeShorthandRule = exports.RULE_NAME = void 0;
4
+ const utils_1 = require("@angular-eslint/utils");
5
+ exports.RULE_NAME = 'prefer-boolean-attribute-shorthand';
6
+ exports.preferBooleanAttributeShorthandRule = {
7
+ meta: {
8
+ type: 'suggestion',
9
+ docs: {
10
+ description: 'Prefer boolean input attribute shorthand instead of binding to literal true/false.',
11
+ },
12
+ hasSuggestions: true,
13
+ schema: [
14
+ {
15
+ type: 'object',
16
+ properties: {
17
+ allowFalseLiteral: { type: 'boolean' },
18
+ },
19
+ additionalProperties: false,
20
+ },
21
+ ],
22
+ messages: {
23
+ preferTrue: 'Use attribute shorthand "{{attr}}" instead of [{{attr}}]="true".',
24
+ preferFalse: 'Avoid binding [{{attr}}]="false"; remove the binding or ensure default is false.',
25
+ suggestTrue: 'Replace with attribute shorthand {{attr}}',
26
+ suggestRemove: 'Remove the false binding',
27
+ },
28
+ },
29
+ defaultOptions: [
30
+ {
31
+ allowFalseLiteral: false,
32
+ },
33
+ ],
34
+ create(context) {
35
+ // Robust to missing options: default to [{}] if undefined
36
+ const optionsArr = context.options ?? [{}];
37
+ const options = optionsArr[0] ?? {};
38
+ const allowFalseLiteral = options.allowFalseLiteral ?? false;
39
+ const parserServices = (0, utils_1.getTemplateParserServices)(context);
40
+ return {
41
+ BoundAttribute(node) {
42
+ const { value } = node;
43
+ if (!value || !value.ast)
44
+ return;
45
+ const ast = value.ast;
46
+ if (ast?.constructor?.name === 'LiteralPrimitive' && typeof ast.value === 'boolean') {
47
+ const attrName = node.name;
48
+ const loc = parserServices.convertNodeSourceSpanToLoc(node.sourceSpan);
49
+ const start = node.sourceSpan.start.offset;
50
+ const end = node.sourceSpan.end.offset;
51
+ if (ast.value === true) {
52
+ context.report({
53
+ loc,
54
+ messageId: 'preferTrue',
55
+ data: { attr: attrName },
56
+ suggest: [
57
+ {
58
+ messageId: 'suggestTrue',
59
+ data: { attr: attrName },
60
+ fix: (fixer) => fixer.replaceTextRange([start, end], attrName),
61
+ },
62
+ ],
63
+ });
64
+ }
65
+ else if (ast.value === false && !allowFalseLiteral) {
66
+ context.report({
67
+ loc,
68
+ messageId: 'preferFalse',
69
+ data: { attr: attrName },
70
+ suggest: [
71
+ {
72
+ messageId: 'suggestRemove',
73
+ data: { attr: attrName },
74
+ fix: (fixer) => fixer.replaceTextRange([start, end], ''),
75
+ },
76
+ ],
77
+ });
78
+ }
79
+ }
80
+ },
81
+ };
82
+ },
83
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@yoo-digital/eslint-plugin-angular",
3
+ "version": "0.1.9",
4
+ "description": "Yoo Digital custom Angular ESLint plugin providing prefer-boolean-attribute-shorthand rule.",
5
+ "type": "commonjs",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "clean": "rm -rf dist",
13
+ "build": "tsc -p tsconfig.json",
14
+ "lint": "eslint src --ext .ts",
15
+ "prepublishOnly": "npm run clean && npm run build"
16
+ },
17
+ "keywords": [
18
+ "eslint",
19
+ "eslintplugin",
20
+ "angular",
21
+ "lint",
22
+ "yoo-digital"
23
+ ],
24
+ "author": "Yoo Digital",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/yoo-digital/eslint-plugin-angular.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/yoo-digital/eslint-plugin-angular/issues"
32
+ },
33
+ "homepage": "https://github.com/yoo-digital/eslint-plugin-angular#readme",
34
+ "peerDependencies": {
35
+ "eslint": "^8.57.0",
36
+ "typescript": ">=5.5.0 <5.7.0",
37
+ "@angular-eslint/eslint-plugin": ">=19.0.0 <21.0.0",
38
+ "@angular-eslint/template-parser": ">=19.0.0 <21.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "typescript": "^5.9.3",
42
+ "@typescript-eslint/utils": "^8.7.0",
43
+ "eslint": "^8.57.0",
44
+ "@angular-eslint/eslint-plugin": "^20.5.0",
45
+ "@angular-eslint/template-parser": "^20.5.0",
46
+ "@types/node": "^20.11.0"
47
+ }
48
+ }