@angular-eslint/eslint-plugin 19.4.1-alpha.0 → 19.4.1-alpha.10
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 +1 -0
- package/dist/configs/all.json +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/rules/sort-keys-in-type-decorator.d.ts +11 -0
- package/dist/rules/sort-keys-in-type-decorator.d.ts.map +1 -0
- package/dist/rules/sort-keys-in-type-decorator.js +147 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -73,6 +73,7 @@ Please see https://github.com/angular-eslint/angular-eslint for full usage instr
|
|
|
73
73
|
| [`relative-url-prefix`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/relative-url-prefix.md) | The ./ and ../ prefix is standard syntax for relative URLs; don't depend on Angular's current ability to do without that prefix. See more at https://angular.dev/style-guide#style-05-04 | | | |
|
|
74
74
|
| [`require-localize-metadata`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/require-localize-metadata.md) | Ensures that $localize tagged messages contain helpful metadata to aid with translations. | | | |
|
|
75
75
|
| [`runtime-localize`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/runtime-localize.md) | Ensures that $localize tagged messages can use runtime-loaded translations. | | | |
|
|
76
|
+
| [`sort-keys-in-type-decorator`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/sort-keys-in-type-decorator.md) | Ensures that keys in type decorators (Component, Directive, NgModule, Pipe) are sorted in a consistent order | | :wrench: | |
|
|
76
77
|
| [`use-component-selector`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/use-component-selector.md) | Component selector must be declared | | | |
|
|
77
78
|
| [`use-component-view-encapsulation`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/use-component-view-encapsulation.md) | Disallows using `ViewEncapsulation.None` | | | :bulb: |
|
|
78
79
|
| [`use-injectable-provided-in`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/use-injectable-provided-in.md) | Using the `providedIn` property makes `Injectables` tree-shakable | | | :bulb: |
|
package/dist/configs/all.json
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@angular-eslint/require-lifecycle-on-prototype": "error",
|
|
37
37
|
"@angular-eslint/require-localize-metadata": "error",
|
|
38
38
|
"@angular-eslint/runtime-localize": "error",
|
|
39
|
+
"@angular-eslint/sort-keys-in-type-decorator": "error",
|
|
39
40
|
"@angular-eslint/sort-lifecycle-methods": "error",
|
|
40
41
|
"@angular-eslint/use-component-selector": "error",
|
|
41
42
|
"@angular-eslint/use-component-view-encapsulation": "error",
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ declare const _default: {
|
|
|
38
38
|
"@angular-eslint/require-lifecycle-on-prototype": string;
|
|
39
39
|
"@angular-eslint/require-localize-metadata": string;
|
|
40
40
|
"@angular-eslint/runtime-localize": string;
|
|
41
|
+
"@angular-eslint/sort-keys-in-type-decorator": string;
|
|
41
42
|
"@angular-eslint/sort-lifecycle-methods": string;
|
|
42
43
|
"@angular-eslint/use-component-selector": string;
|
|
43
44
|
"@angular-eslint/use-component-view-encapsulation": string;
|
|
@@ -107,6 +108,7 @@ declare const _default: {
|
|
|
107
108
|
"require-lifecycle-on-prototype": import("@typescript-eslint/utils/ts-eslint").RuleModule<"defineOnPrototype", [], import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
108
109
|
"require-localize-metadata": import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/require-localize-metadata").MessageIds, import("./rules/require-localize-metadata").Options, import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
109
110
|
"runtime-localize": import("@typescript-eslint/utils/ts-eslint").RuleModule<"runtimeLocalize", [], import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
111
|
+
"sort-keys-in-type-decorator": import("@typescript-eslint/utils/ts-eslint").RuleModule<"incorrectOrder", import("./rules/sort-keys-in-type-decorator").Options, import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
110
112
|
"sort-lifecycle-methods": import("@typescript-eslint/utils/ts-eslint").RuleModule<"lifecycleMethodsNotSorted", [], import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
111
113
|
"use-component-selector": import("@typescript-eslint/utils/ts-eslint").RuleModule<"useComponentSelector", [], import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
112
114
|
"use-component-view-encapsulation": import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/use-component-view-encapsulation").MessageIds, [], import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HA,kBAiDE"}
|
package/dist/index.js
CHANGED
|
@@ -48,6 +48,7 @@ const directive_selector_1 = __importStar(require("./rules/directive-selector"))
|
|
|
48
48
|
const no_async_lifecycle_method_1 = __importStar(require("./rules/no-async-lifecycle-method"));
|
|
49
49
|
const no_attribute_decorator_1 = __importStar(require("./rules/no-attribute-decorator"));
|
|
50
50
|
const no_conflicting_lifecycle_1 = __importStar(require("./rules/no-conflicting-lifecycle"));
|
|
51
|
+
const no_duplicates_in_metadata_arrays_1 = __importStar(require("./rules/no-duplicates-in-metadata-arrays"));
|
|
51
52
|
const no_empty_lifecycle_method_1 = __importStar(require("./rules/no-empty-lifecycle-method"));
|
|
52
53
|
const no_forward_ref_1 = __importStar(require("./rules/no-forward-ref"));
|
|
53
54
|
const no_input_prefix_1 = __importStar(require("./rules/no-input-prefix"));
|
|
@@ -70,13 +71,13 @@ const relative_url_prefix_1 = __importStar(require("./rules/relative-url-prefix"
|
|
|
70
71
|
const require_lifecycle_on_prototype_1 = __importStar(require("./rules/require-lifecycle-on-prototype"));
|
|
71
72
|
const require_localize_metadata_1 = __importStar(require("./rules/require-localize-metadata"));
|
|
72
73
|
const runtime_localize_1 = __importStar(require("./rules/runtime-localize"));
|
|
74
|
+
const sort_keys_in_type_decorator_1 = __importStar(require("./rules/sort-keys-in-type-decorator"));
|
|
73
75
|
const sort_lifecycle_methods_1 = __importStar(require("./rules/sort-lifecycle-methods"));
|
|
74
76
|
const use_component_selector_1 = __importStar(require("./rules/use-component-selector"));
|
|
75
77
|
const use_component_view_encapsulation_1 = __importStar(require("./rules/use-component-view-encapsulation"));
|
|
76
78
|
const use_injectable_provided_in_1 = __importStar(require("./rules/use-injectable-provided-in"));
|
|
77
79
|
const use_lifecycle_interface_1 = __importStar(require("./rules/use-lifecycle-interface"));
|
|
78
80
|
const use_pipe_transform_interface_1 = __importStar(require("./rules/use-pipe-transform-interface"));
|
|
79
|
-
const no_duplicates_in_metadata_arrays_1 = __importStar(require("./rules/no-duplicates-in-metadata-arrays"));
|
|
80
81
|
module.exports = {
|
|
81
82
|
configs: {
|
|
82
83
|
all: all_json_1.default,
|
|
@@ -117,6 +118,7 @@ module.exports = {
|
|
|
117
118
|
[require_lifecycle_on_prototype_1.RULE_NAME]: require_lifecycle_on_prototype_1.default,
|
|
118
119
|
[require_localize_metadata_1.RULE_NAME]: require_localize_metadata_1.default,
|
|
119
120
|
[runtime_localize_1.RULE_NAME]: runtime_localize_1.default,
|
|
121
|
+
[sort_keys_in_type_decorator_1.RULE_NAME]: sort_keys_in_type_decorator_1.default,
|
|
120
122
|
[sort_lifecycle_methods_1.RULE_NAME]: sort_lifecycle_methods_1.default,
|
|
121
123
|
[use_component_selector_1.RULE_NAME]: use_component_selector_1.default,
|
|
122
124
|
[use_component_view_encapsulation_1.RULE_NAME]: use_component_view_encapsulation_1.default,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
export type Options = [
|
|
3
|
+
{
|
|
4
|
+
[key: string]: string[];
|
|
5
|
+
}
|
|
6
|
+
];
|
|
7
|
+
export type MessageIds = 'incorrectOrder';
|
|
8
|
+
export declare const RULE_NAME = "sort-keys-in-type-decorator";
|
|
9
|
+
declare const _default: TSESLint.RuleModule<"incorrectOrder", Options, import("../utils/create-eslint-rule").RuleDocs, TSESLint.RuleListener>;
|
|
10
|
+
export default _default;
|
|
11
|
+
//# sourceMappingURL=sort-keys-in-type-decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-keys-in-type-decorator.d.ts","sourceRoot":"","sources":["../../src/rules/sort-keys-in-type-decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AAG9D,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KACzB;CACF,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAoB1C,eAAO,MAAM,SAAS,gCAAgC,CAAC;;AAEvD,wBA+IG"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RULE_NAME = void 0;
|
|
4
|
+
const utils_1 = require("@angular-eslint/utils");
|
|
5
|
+
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
6
|
+
const DEFAULT_ORDER = {
|
|
7
|
+
Component: [
|
|
8
|
+
'selector',
|
|
9
|
+
'imports',
|
|
10
|
+
'standalone',
|
|
11
|
+
'templateUrl',
|
|
12
|
+
'template',
|
|
13
|
+
'styleUrl',
|
|
14
|
+
'styleUrls',
|
|
15
|
+
'styles',
|
|
16
|
+
'encapsulation',
|
|
17
|
+
'changeDetection',
|
|
18
|
+
],
|
|
19
|
+
Directive: ['selector', 'standalone'],
|
|
20
|
+
NgModule: ['declarations', 'imports', 'exports', 'providers', 'bootstrap'],
|
|
21
|
+
Pipe: ['name', 'standalone'],
|
|
22
|
+
};
|
|
23
|
+
exports.RULE_NAME = 'sort-keys-in-type-decorator';
|
|
24
|
+
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
25
|
+
name: exports.RULE_NAME,
|
|
26
|
+
meta: {
|
|
27
|
+
type: 'suggestion',
|
|
28
|
+
docs: {
|
|
29
|
+
description: 'Ensures that keys in type decorators (Component, Directive, NgModule, Pipe) are sorted in a consistent order',
|
|
30
|
+
},
|
|
31
|
+
fixable: 'code',
|
|
32
|
+
schema: [
|
|
33
|
+
{
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
Component: {
|
|
37
|
+
type: 'array',
|
|
38
|
+
items: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
Directive: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
items: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
NgModule: {
|
|
49
|
+
type: 'array',
|
|
50
|
+
items: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
Pipe: {
|
|
55
|
+
type: 'array',
|
|
56
|
+
items: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
additionalProperties: false,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
messages: {
|
|
65
|
+
incorrectOrder: 'Keys in @{{decorator}} decorator should be ordered: {{expectedOrder}}',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
defaultOptions: [DEFAULT_ORDER],
|
|
69
|
+
create(context, [orderConfig]) {
|
|
70
|
+
function checkContext(node, decoratorName) {
|
|
71
|
+
const expectedOrder = orderConfig[decoratorName];
|
|
72
|
+
if (!expectedOrder) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const argument = utils_1.ASTUtils.getDecoratorArgument(node);
|
|
76
|
+
if (!argument) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const properties = utils_1.ASTUtils.getDecoratorProperties(node);
|
|
80
|
+
if (properties.length <= 1) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const firstConfiguredIndex = properties.findIndex(({ key }) => expectedOrder.includes(key.name));
|
|
84
|
+
const lastNonConfiguredIndex = properties.findIndex(({ key }) => !expectedOrder.includes(key.name));
|
|
85
|
+
if (firstConfiguredIndex !== -1 &&
|
|
86
|
+
lastNonConfiguredIndex !== -1 &&
|
|
87
|
+
lastNonConfiguredIndex < firstConfiguredIndex) {
|
|
88
|
+
createInvalidSortRuleForDecorator(context, decoratorName, expectedOrder, properties, properties[lastNonConfiguredIndex]);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const configuredProperties = properties.filter(({ key }) => expectedOrder.includes(key.name));
|
|
92
|
+
if (configuredProperties.length) {
|
|
93
|
+
const actualConfiguredOrder = configuredProperties.map(({ key }) => key.name);
|
|
94
|
+
const expectedConfiguredOrder = expectedOrder.filter((key) => actualConfiguredOrder.includes(key));
|
|
95
|
+
if (actualConfiguredOrder.length &&
|
|
96
|
+
JSON.stringify(actualConfiguredOrder) !==
|
|
97
|
+
JSON.stringify(expectedConfiguredOrder)) {
|
|
98
|
+
const firstOutOfOrderIndex = actualConfiguredOrder.findIndex((key, index) => key !== expectedConfiguredOrder[index]);
|
|
99
|
+
const outOfOrderProperty = configuredProperties[firstOutOfOrderIndex];
|
|
100
|
+
createInvalidSortRuleForDecorator(context, decoratorName, expectedOrder, properties, outOfOrderProperty);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
[utils_1.Selectors.COMPONENT_CLASS_DECORATOR](node) {
|
|
106
|
+
checkContext(node, utils_1.ASTUtils.AngularClassDecorators.Component);
|
|
107
|
+
},
|
|
108
|
+
[utils_1.Selectors.DIRECTIVE_CLASS_DECORATOR](node) {
|
|
109
|
+
checkContext(node, utils_1.ASTUtils.AngularClassDecorators.Directive);
|
|
110
|
+
},
|
|
111
|
+
[utils_1.Selectors.INJECTABLE_CLASS_DECORATOR](node) {
|
|
112
|
+
checkContext(node, utils_1.ASTUtils.AngularClassDecorators.Injectable);
|
|
113
|
+
},
|
|
114
|
+
[utils_1.Selectors.MODULE_CLASS_DECORATOR](node) {
|
|
115
|
+
checkContext(node, utils_1.ASTUtils.AngularClassDecorators.NgModule);
|
|
116
|
+
},
|
|
117
|
+
[utils_1.Selectors.PIPE_CLASS_DECORATOR](node) {
|
|
118
|
+
checkContext(node, utils_1.ASTUtils.AngularClassDecorators.Pipe);
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
function createInvalidSortRuleForDecorator(context, decoratorName, expectedOrder, properties, node) {
|
|
124
|
+
const presentProps = properties.map((prop) => prop.key.name);
|
|
125
|
+
const relevantExpectedOrder = expectedOrder.filter((propName) => presentProps.includes(propName));
|
|
126
|
+
const data = {
|
|
127
|
+
decorator: decoratorName,
|
|
128
|
+
expectedOrder: relevantExpectedOrder.join(', '),
|
|
129
|
+
};
|
|
130
|
+
reportAndFix(context, node, 'incorrectOrder', data, properties, expectedOrder, node.parent);
|
|
131
|
+
}
|
|
132
|
+
function reportAndFix(context, node, messageId, data, properties, expectedOrder, objectExpression) {
|
|
133
|
+
const sourceCode = context.sourceCode;
|
|
134
|
+
context.report({
|
|
135
|
+
node,
|
|
136
|
+
messageId,
|
|
137
|
+
data,
|
|
138
|
+
fix(fixer) {
|
|
139
|
+
const indentation = utils_1.CommentUtils.getObjectIndentation(sourceCode, objectExpression);
|
|
140
|
+
const propNames = properties.map((p) => p.key.name);
|
|
141
|
+
const filteredOrder = expectedOrder.filter((name) => propNames.includes(name));
|
|
142
|
+
const propInfoMap = utils_1.CommentUtils.extractPropertyComments(sourceCode, properties, objectExpression, indentation);
|
|
143
|
+
const sortedText = utils_1.CommentUtils.buildSortedPropertiesWithComments(filteredOrder, propInfoMap, indentation);
|
|
144
|
+
return fixer.replaceText(objectExpression, `{\n${sortedText}\n${indentation.slice(0, -2)}}`);
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin",
|
|
3
|
-
"version": "19.4.1-alpha.
|
|
3
|
+
"version": "19.4.1-alpha.10",
|
|
4
4
|
"description": "ESLint plugin for Angular applications, following https://angular.dev/style-guide",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"LICENSE"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@angular-eslint/bundled-angular-compiler": "19.4.1-alpha.
|
|
22
|
-
"@angular-eslint/utils": "19.4.1-alpha.
|
|
21
|
+
"@angular-eslint/bundled-angular-compiler": "19.4.1-alpha.10",
|
|
22
|
+
"@angular-eslint/utils": "19.4.1-alpha.10"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@angular-eslint/test-utils": "19.4.1-alpha.
|
|
25
|
+
"@angular-eslint/test-utils": "19.4.1-alpha.10"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@typescript-eslint/utils": "^7.11.0 || ^8.0.0",
|