@yoo-digital/eslint-plugin-angular 2.0.4 → 2.0.6
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 +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/rules/{boolean-attribute-html.d.ts → boolean-attribute-shorthand.d.ts} +1 -1
- package/dist/rules/{boolean-attribute-html.js → boolean-attribute-shorthand.js} +1 -1
- package/dist/rules/{boolean-attribute-ts.d.ts → boolean-input.d.ts} +1 -1
- package/dist/rules/{boolean-attribute-ts.js → boolean-input.js} +72 -26
- package/dist/rules/index.d.ts +2 -2
- package/dist/rules/index.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,15 +12,15 @@ Wrong code is yellow/red underlined in VScode, it can also be raised running : `
|
|
|
12
12
|
|
|
13
13
|
This feature consists of **two complementary rules**:
|
|
14
14
|
|
|
15
|
-
1. **`boolean-
|
|
16
|
-
2. **`boolean-attribute-
|
|
15
|
+
1. **`boolean-input`** - TypeScript rule that enforces `booleanAttribute` transform on boolean inputs
|
|
16
|
+
2. **`boolean-attribute-shorthand`** - Template rule that enforces shorthand syntax for `[attr]="true"` bindings
|
|
17
17
|
|
|
18
18
|
### Setting
|
|
19
19
|
```json
|
|
20
20
|
{
|
|
21
21
|
"rules": {
|
|
22
|
-
"@yoo-digital/eslint-plugin-angular/boolean-
|
|
23
|
-
"@yoo-digital/eslint-plugin-angular/boolean-attribute-
|
|
22
|
+
"@yoo-digital/eslint-plugin-angular/boolean-input": "error",
|
|
23
|
+
"@yoo-digital/eslint-plugin-angular/boolean-attribute-shorthand": "error"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -3,15 +3,15 @@ export declare const configs: {
|
|
|
3
3
|
default: {
|
|
4
4
|
plugins: string[];
|
|
5
5
|
rules: {
|
|
6
|
-
'@yoo-digital/angular/boolean-attribute-
|
|
7
|
-
'@yoo-digital/angular/boolean-
|
|
6
|
+
'@yoo-digital/angular/boolean-attribute-shorthand': string;
|
|
7
|
+
'@yoo-digital/angular/boolean-input': string;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
recommended: {
|
|
11
11
|
plugins: string[];
|
|
12
12
|
rules: {
|
|
13
|
-
'@yoo-digital/angular/boolean-attribute-
|
|
14
|
-
'@yoo-digital/angular/boolean-
|
|
13
|
+
'@yoo-digital/angular/boolean-attribute-shorthand': string;
|
|
14
|
+
'@yoo-digital/angular/boolean-input': string;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
};
|
package/dist/index.js
CHANGED
|
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.configs = exports.rules = void 0;
|
|
4
4
|
const rules_1 = require("./rules");
|
|
5
5
|
exports.rules = {
|
|
6
|
-
'boolean-attribute-
|
|
7
|
-
'boolean-
|
|
6
|
+
'boolean-attribute-shorthand': rules_1.preferBooleanAttributeShorthandRule,
|
|
7
|
+
'boolean-input': rules_1.requireBooleanAttributeTransformRule,
|
|
8
8
|
};
|
|
9
9
|
exports.configs = {
|
|
10
10
|
default: {
|
|
11
11
|
plugins: ['@yoo-digital/eslint-plugin-angular'],
|
|
12
12
|
rules: {
|
|
13
|
-
'@yoo-digital/angular/boolean-attribute-
|
|
14
|
-
'@yoo-digital/angular/boolean-
|
|
13
|
+
'@yoo-digital/angular/boolean-attribute-shorthand': 'warn',
|
|
14
|
+
'@yoo-digital/angular/boolean-input': 'warn',
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
recommended: {
|
|
18
18
|
plugins: ['@yoo-digital/eslint-plugin-angular'],
|
|
19
19
|
rules: {
|
|
20
|
-
'@yoo-digital/angular/boolean-attribute-
|
|
21
|
-
'@yoo-digital/angular/boolean-
|
|
20
|
+
'@yoo-digital/angular/boolean-attribute-shorthand': 'error',
|
|
21
|
+
'@yoo-digital/angular/boolean-input': 'error',
|
|
22
22
|
},
|
|
23
23
|
},
|
|
24
24
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
2
|
type MessageIds = 'preferTrue' | 'suggestTrue';
|
|
3
|
-
export declare const RULE_NAME = "boolean-attribute-
|
|
3
|
+
export declare const RULE_NAME = "boolean-attribute-shorthand";
|
|
4
4
|
/**
|
|
5
5
|
* This rule enforces shorthand syntax for boolean inputs bound to true.
|
|
6
6
|
*
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.preferBooleanAttributeShorthandRule = exports.RULE_NAME = void 0;
|
|
4
4
|
const utils_1 = require("@angular-eslint/utils");
|
|
5
|
-
exports.RULE_NAME = 'boolean-attribute-
|
|
5
|
+
exports.RULE_NAME = 'boolean-attribute-shorthand';
|
|
6
6
|
/**
|
|
7
7
|
* This rule enforces shorthand syntax for boolean inputs bound to true.
|
|
8
8
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
2
|
type MessageIds = 'requireTransformDecorator' | 'requireTransformSignal';
|
|
3
|
-
export declare const RULE_NAME = "boolean-
|
|
3
|
+
export declare const RULE_NAME = "boolean-input";
|
|
4
4
|
/**
|
|
5
5
|
* This rule enforces that boolean @Input() properties and input() signals
|
|
6
6
|
* use the booleanAttribute transform.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.requireBooleanAttributeTransformRule = exports.RULE_NAME = void 0;
|
|
4
|
-
exports.RULE_NAME = 'boolean-
|
|
4
|
+
exports.RULE_NAME = 'boolean-input';
|
|
5
5
|
/**
|
|
6
6
|
* This rule enforces that boolean @Input() properties and input() signals
|
|
7
7
|
* use the booleanAttribute transform.
|
|
@@ -28,44 +28,90 @@ exports.requireBooleanAttributeTransformRule = {
|
|
|
28
28
|
defaultOptions: [],
|
|
29
29
|
create(context) {
|
|
30
30
|
return {
|
|
31
|
-
// Handle @Input() decorator syntax
|
|
31
|
+
// Handle both @Input() decorator syntax and input() signal syntax
|
|
32
32
|
PropertyDefinition(node) {
|
|
33
|
-
//
|
|
34
|
-
if (!node.typeAnnotation || node.typeAnnotation.typeAnnotation.type !== 'TSBooleanKeyword') {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
33
|
+
// Case 1: Check for @Input() decorator with boolean type
|
|
37
34
|
const hasInputDecorator = node.decorators?.some((decorator) => decorator.expression.type === 'CallExpression' &&
|
|
38
35
|
decorator.expression.callee.type === 'Identifier' &&
|
|
39
36
|
decorator.expression.callee.name === 'Input');
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
decorator.expression.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
37
|
+
if (hasInputDecorator) {
|
|
38
|
+
// Handle @Input() decorator
|
|
39
|
+
if (!node.typeAnnotation || node.typeAnnotation.typeAnnotation.type !== 'TSBooleanKeyword') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Check if it already has transform: booleanAttribute
|
|
43
|
+
const inputDecorator = node.decorators?.find((decorator) => decorator.expression.type === 'CallExpression' &&
|
|
44
|
+
decorator.expression.callee.type === 'Identifier' &&
|
|
45
|
+
decorator.expression.callee.name === 'Input');
|
|
46
|
+
if (inputDecorator?.expression.type === 'CallExpression') {
|
|
47
|
+
const args = inputDecorator.expression.arguments;
|
|
48
|
+
if (args.length > 0 && args[0].type === 'ObjectExpression') {
|
|
49
|
+
const hasTransform = args[0].properties.some((prop) => prop.type === 'Property' &&
|
|
50
|
+
prop.key.type === 'Identifier' &&
|
|
51
|
+
prop.key.name === 'transform' &&
|
|
52
|
+
prop.value.type === 'Identifier' &&
|
|
53
|
+
prop.value.name === 'booleanAttribute');
|
|
54
|
+
if (hasTransform) {
|
|
55
|
+
return; // Already has transform
|
|
56
|
+
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
// Report the issue for @Input()
|
|
60
|
+
const propertyName = node.key.type === 'Identifier' ? node.key.name : 'unknown';
|
|
61
|
+
context.report({
|
|
62
|
+
node: node.key,
|
|
63
|
+
messageId: 'requireTransformDecorator',
|
|
64
|
+
data: { name: propertyName },
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
59
67
|
}
|
|
60
|
-
//
|
|
68
|
+
// Case 2: Check for input() signal syntax
|
|
69
|
+
if (!node.value ||
|
|
70
|
+
node.value.type !== 'CallExpression' ||
|
|
71
|
+
node.value.callee.type !== 'Identifier' ||
|
|
72
|
+
node.value.callee.name !== 'input') {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const callExpr = node.value;
|
|
76
|
+
// Check if it's a boolean input (with or without type arguments)
|
|
77
|
+
let isBooleanInput = false;
|
|
78
|
+
if (callExpr.typeArguments && callExpr.typeArguments.params.length > 0) {
|
|
79
|
+
const firstTypeParam = callExpr.typeArguments.params[0];
|
|
80
|
+
isBooleanInput = firstTypeParam.type === 'TSBooleanKeyword';
|
|
81
|
+
}
|
|
82
|
+
if (!isBooleanInput) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// At this point, we know typeArguments exists and has at least one boolean param
|
|
86
|
+
const typeArgs = callExpr.typeArguments;
|
|
87
|
+
// Check if it already has BooleanInput as second type parameter
|
|
88
|
+
const hasBooleanInput = typeArgs.params.length > 1 &&
|
|
89
|
+
typeArgs.params[1].type === 'TSTypeReference' &&
|
|
90
|
+
typeArgs.params[1].typeName.type === 'Identifier' &&
|
|
91
|
+
typeArgs.params[1].typeName.name === 'BooleanInput';
|
|
92
|
+
// Check if it already has transform in options
|
|
93
|
+
const hasTransformOption = callExpr.arguments.length > 1 &&
|
|
94
|
+
callExpr.arguments[1].type === 'ObjectExpression' &&
|
|
95
|
+
callExpr.arguments[1].properties.some((prop) => prop.type === 'Property' &&
|
|
96
|
+
prop.key.type === 'Identifier' &&
|
|
97
|
+
prop.key.name === 'transform' &&
|
|
98
|
+
prop.value.type === 'Identifier' &&
|
|
99
|
+
prop.value.name === 'booleanAttribute');
|
|
100
|
+
// Both BooleanInput type and transform option are required
|
|
101
|
+
// Only skip if BOTH are present
|
|
102
|
+
if (hasBooleanInput && hasTransformOption) {
|
|
103
|
+
return; // Already correctly configured
|
|
104
|
+
}
|
|
105
|
+
// If we reach here, at least one requirement is missing
|
|
106
|
+
// Report the issue for input() signal
|
|
61
107
|
const propertyName = node.key.type === 'Identifier' ? node.key.name : 'unknown';
|
|
62
108
|
context.report({
|
|
63
109
|
node: node.key,
|
|
64
|
-
messageId: '
|
|
110
|
+
messageId: 'requireTransformSignal',
|
|
65
111
|
data: { name: propertyName },
|
|
66
112
|
});
|
|
67
113
|
},
|
|
68
|
-
// Handle input() signal syntax
|
|
114
|
+
// Handle input() signal syntax (standalone variable declarations - rare)
|
|
69
115
|
VariableDeclarator(node) {
|
|
70
116
|
if (node.init?.type !== 'CallExpression' ||
|
|
71
117
|
node.init.callee.type !== 'Identifier' ||
|
package/dist/rules/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { RULE_NAME as
|
|
2
|
-
export { RULE_NAME as
|
|
1
|
+
export { RULE_NAME as BOOLEAN_ATTRIBUTE_SHORTHAND_RULE_NAME, preferBooleanAttributeShorthandRule } from './boolean-attribute-shorthand';
|
|
2
|
+
export { RULE_NAME as BOOLEAN_INPUT_RULE_NAME, requireBooleanAttributeTransformRule } from './boolean-input';
|
package/dist/rules/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireBooleanAttributeTransformRule = exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
Object.defineProperty(exports, "preferBooleanAttributeShorthandRule", { enumerable: true, get: function () { return
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "
|
|
9
|
-
Object.defineProperty(exports, "requireBooleanAttributeTransformRule", { enumerable: true, get: function () { return
|
|
3
|
+
exports.requireBooleanAttributeTransformRule = exports.BOOLEAN_INPUT_RULE_NAME = exports.preferBooleanAttributeShorthandRule = exports.BOOLEAN_ATTRIBUTE_SHORTHAND_RULE_NAME = void 0;
|
|
4
|
+
var boolean_attribute_shorthand_1 = require("./boolean-attribute-shorthand");
|
|
5
|
+
Object.defineProperty(exports, "BOOLEAN_ATTRIBUTE_SHORTHAND_RULE_NAME", { enumerable: true, get: function () { return boolean_attribute_shorthand_1.RULE_NAME; } });
|
|
6
|
+
Object.defineProperty(exports, "preferBooleanAttributeShorthandRule", { enumerable: true, get: function () { return boolean_attribute_shorthand_1.preferBooleanAttributeShorthandRule; } });
|
|
7
|
+
var boolean_input_1 = require("./boolean-input");
|
|
8
|
+
Object.defineProperty(exports, "BOOLEAN_INPUT_RULE_NAME", { enumerable: true, get: function () { return boolean_input_1.RULE_NAME; } });
|
|
9
|
+
Object.defineProperty(exports, "requireBooleanAttributeTransformRule", { enumerable: true, get: function () { return boolean_input_1.requireBooleanAttributeTransformRule; } });
|
package/package.json
CHANGED