@angular-eslint/eslint-plugin 19.7.0-beta.0 → 19.7.1-alpha.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/dist/rules/require-localize-metadata.d.ts +2 -1
- package/dist/rules/require-localize-metadata.d.ts.map +1 -1
- package/dist/rules/require-localize-metadata.js +58 -11
- package/package.json +4 -4
- package/dist/rules/no-host-metadata-property.d.ts +0 -8
- package/dist/rules/no-host-metadata-property.d.ts.map +0 -1
- package/dist/rules/no-host-metadata-property.js +0 -67
- package/dist/rules/prefer-standalone-component.d.ts +0 -6
- package/dist/rules/prefer-standalone-component.d.ts.map +0 -1
- package/dist/rules/prefer-standalone-component.js +0 -59
- package/dist/rules/sort-ngmodule-metadata-arrays.d.ts +0 -10
- package/dist/rules/sort-ngmodule-metadata-arrays.d.ts.map +0 -1
- package/dist/rules/sort-ngmodule-metadata-arrays.js +0 -63
|
@@ -2,9 +2,10 @@ export type Options = [
|
|
|
2
2
|
{
|
|
3
3
|
readonly requireDescription?: boolean;
|
|
4
4
|
readonly requireMeaning?: boolean;
|
|
5
|
+
readonly requireCustomId?: boolean | string;
|
|
5
6
|
}
|
|
6
7
|
];
|
|
7
|
-
export type MessageIds = 'requireLocalizeDescription' | 'requireLocalizeMeaning';
|
|
8
|
+
export type MessageIds = 'requireLocalizeDescription' | 'requireLocalizeMeaning' | 'requireLocalizeCustomId';
|
|
8
9
|
export declare const RULE_NAME = "require-localize-metadata";
|
|
9
10
|
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
10
11
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-localize-metadata.d.ts","sourceRoot":"","sources":["../../src/rules/require-localize-metadata.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"require-localize-metadata.d.ts","sourceRoot":"","sources":["../../src/rules/require-localize-metadata.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;QAClC,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;KAC7C;CACF,CAAC;AAYF,MAAM,MAAM,UAAU,GAClB,4BAA4B,GAC5B,wBAAwB,GACxB,yBAAyB,CAAC;AAC9B,eAAO,MAAM,SAAS,8BAA8B,CAAC;;AAErD,wBAyFG"}
|
|
@@ -6,12 +6,11 @@ const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
|
6
6
|
const DEFAULT_OPTIONS = {
|
|
7
7
|
requireDescription: false,
|
|
8
8
|
requireMeaning: false,
|
|
9
|
+
requireCustomId: false,
|
|
9
10
|
};
|
|
10
|
-
const VALID_LOCALIZED_STRING_WITH_DESCRIPTION = new RegExp(/:(.*\|)?([\w\s]+){1}(@@.*)?:.+/);
|
|
11
|
-
const VALID_LOCALIZED_STRING_WITH_MEANING = new RegExp(/:([\w\s]+\|)(.*)?(@@.*)?:.+/);
|
|
12
11
|
const STYLE_GUIDE_LINK = 'https://angular.dev/guide/i18n';
|
|
13
|
-
const
|
|
14
|
-
const STYLE_GUIDE_LINK_METADATA_FOR_TRANSLATION = `${
|
|
12
|
+
const STYLE_GUIDE_LINK_PREPARE = `${STYLE_GUIDE_LINK}/prepare`;
|
|
13
|
+
const STYLE_GUIDE_LINK_METADATA_FOR_TRANSLATION = `${STYLE_GUIDE_LINK_PREPARE}#i18n-metadata-for-translation`;
|
|
15
14
|
exports.RULE_NAME = 'require-localize-metadata';
|
|
16
15
|
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
17
16
|
name: exports.RULE_NAME,
|
|
@@ -32,6 +31,10 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
32
31
|
type: 'boolean',
|
|
33
32
|
default: DEFAULT_OPTIONS.requireMeaning,
|
|
34
33
|
},
|
|
34
|
+
requireCustomId: {
|
|
35
|
+
oneOf: [{ type: 'boolean' }, { type: 'string' }],
|
|
36
|
+
default: DEFAULT_OPTIONS.requireCustomId,
|
|
37
|
+
},
|
|
35
38
|
},
|
|
36
39
|
additionalProperties: false,
|
|
37
40
|
},
|
|
@@ -39,35 +42,79 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
39
42
|
messages: {
|
|
40
43
|
requireLocalizeDescription: `$localize tagged messages should contain a description. See more at ${STYLE_GUIDE_LINK_METADATA_FOR_TRANSLATION}`,
|
|
41
44
|
requireLocalizeMeaning: `$localize tagged messages should contain a meaning. See more at ${STYLE_GUIDE_LINK_METADATA_FOR_TRANSLATION}`,
|
|
45
|
+
requireLocalizeCustomId: `$localize tagged messages should contain a custom id{{patternMessage}}. See more at ${STYLE_GUIDE_LINK_METADATA_FOR_TRANSLATION}`,
|
|
42
46
|
},
|
|
43
47
|
},
|
|
44
48
|
defaultOptions: [DEFAULT_OPTIONS],
|
|
45
|
-
create(context, [{ requireDescription, requireMeaning }]) {
|
|
49
|
+
create(context, [{ requireDescription, requireMeaning, requireCustomId }]) {
|
|
46
50
|
return {
|
|
47
51
|
TaggedTemplateExpression(taggedTemplateExpression) {
|
|
48
|
-
if ((requireDescription || requireMeaning) &&
|
|
52
|
+
if ((requireDescription || requireMeaning || requireCustomId) &&
|
|
49
53
|
utils_1.ASTUtils.isIdentifier(taggedTemplateExpression.tag)) {
|
|
50
54
|
const identifierName = taggedTemplateExpression.tag.name;
|
|
51
55
|
const templateElement = taggedTemplateExpression.quasi.quasis[0];
|
|
52
56
|
if (identifierName === '$localize' && !!templateElement) {
|
|
53
|
-
const
|
|
54
|
-
if (requireDescription &&
|
|
55
|
-
!VALID_LOCALIZED_STRING_WITH_DESCRIPTION.test(templateElementRawValue)) {
|
|
57
|
+
const metadata = parseMetadata(templateElement.value.raw.trim());
|
|
58
|
+
if (requireDescription && !metadata.description) {
|
|
56
59
|
context.report({
|
|
57
60
|
loc: templateElement.loc,
|
|
58
61
|
messageId: 'requireLocalizeDescription',
|
|
59
62
|
});
|
|
60
63
|
}
|
|
61
|
-
if (requireMeaning &&
|
|
62
|
-
!VALID_LOCALIZED_STRING_WITH_MEANING.test(templateElementRawValue)) {
|
|
64
|
+
if (requireMeaning && !metadata.meaning) {
|
|
63
65
|
context.report({
|
|
64
66
|
loc: templateElement.loc,
|
|
65
67
|
messageId: 'requireLocalizeMeaning',
|
|
66
68
|
});
|
|
67
69
|
}
|
|
70
|
+
if (requireCustomId &&
|
|
71
|
+
!(metadata.customId &&
|
|
72
|
+
(typeof requireCustomId === 'string'
|
|
73
|
+
? RegExp(requireCustomId).test(metadata.customId)
|
|
74
|
+
: true))) {
|
|
75
|
+
context.report({
|
|
76
|
+
loc: templateElement.loc,
|
|
77
|
+
messageId: 'requireLocalizeCustomId',
|
|
78
|
+
data: {
|
|
79
|
+
patternMessage: typeof requireCustomId === 'string'
|
|
80
|
+
? ` matching the pattern /${requireCustomId}/ on '${metadata.customId}'`
|
|
81
|
+
: '',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
68
85
|
}
|
|
69
86
|
}
|
|
70
87
|
},
|
|
71
88
|
};
|
|
72
89
|
},
|
|
73
90
|
});
|
|
91
|
+
// see https://github.com/angular/angular/blob/main/packages/localize/src/utils/src/messages.ts#L247
|
|
92
|
+
const BLOCK_MARKER = ':';
|
|
93
|
+
const MEANING_SEPARATOR = '|';
|
|
94
|
+
const ID_SEPARATOR = '@@';
|
|
95
|
+
function parseMetadata(rawText) {
|
|
96
|
+
const output = {
|
|
97
|
+
rawText,
|
|
98
|
+
meaning: undefined,
|
|
99
|
+
description: undefined,
|
|
100
|
+
customId: undefined,
|
|
101
|
+
};
|
|
102
|
+
if (rawText.charAt(0) !== BLOCK_MARKER) {
|
|
103
|
+
return output;
|
|
104
|
+
}
|
|
105
|
+
const endOfTheBlock = rawText.lastIndexOf(BLOCK_MARKER);
|
|
106
|
+
if (endOfTheBlock === -1) {
|
|
107
|
+
return output;
|
|
108
|
+
}
|
|
109
|
+
const text = rawText.slice(1, endOfTheBlock);
|
|
110
|
+
const [meaningAndDesc, customId] = text.split(ID_SEPARATOR, 2);
|
|
111
|
+
let [meaning, description] = meaningAndDesc.split(MEANING_SEPARATOR, 2);
|
|
112
|
+
if (description === undefined) {
|
|
113
|
+
description = meaning;
|
|
114
|
+
meaning = undefined;
|
|
115
|
+
}
|
|
116
|
+
if (description === '') {
|
|
117
|
+
description = undefined;
|
|
118
|
+
}
|
|
119
|
+
return { rawText, meaning, description, customId };
|
|
120
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin",
|
|
3
|
-
"version": "19.7.
|
|
3
|
+
"version": "19.7.1-alpha.0",
|
|
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.7.
|
|
22
|
-
"@angular-eslint/utils": "19.7.
|
|
21
|
+
"@angular-eslint/bundled-angular-compiler": "19.7.1-alpha.0",
|
|
22
|
+
"@angular-eslint/utils": "19.7.1-alpha.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@angular-eslint/test-utils": "19.7.
|
|
25
|
+
"@angular-eslint/test-utils": "19.7.1-alpha.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@typescript-eslint/utils": "^7.11.0 || ^8.0.0",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type Options = [{
|
|
2
|
-
readonly allowStatic?: boolean;
|
|
3
|
-
}];
|
|
4
|
-
export type MessageIds = 'noHostMetadataProperty';
|
|
5
|
-
export declare const RULE_NAME = "no-host-metadata-property";
|
|
6
|
-
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noHostMetadataProperty", Options, import("../utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
7
|
-
export default _default;
|
|
8
|
-
//# sourceMappingURL=no-host-metadata-property.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-host-metadata-property.d.ts","sourceRoot":"","sources":["../../src/rules/no-host-metadata-property.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,OAAO,GAAG,CAAC;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAClD,eAAO,MAAM,SAAS,8BAA8B,CAAC;;AAIrD,wBA4CG"}
|
|
@@ -1,67 +0,0 @@
|
|
|
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 utils_2 = require("@typescript-eslint/utils");
|
|
6
|
-
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
7
|
-
exports.RULE_NAME = 'no-host-metadata-property';
|
|
8
|
-
const DEFAULT_OPTIONS = { allowStatic: false };
|
|
9
|
-
const METADATA_PROPERTY_NAME = 'host';
|
|
10
|
-
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
11
|
-
name: exports.RULE_NAME,
|
|
12
|
-
meta: {
|
|
13
|
-
type: 'suggestion',
|
|
14
|
-
deprecated: true,
|
|
15
|
-
docs: {
|
|
16
|
-
description: `Disallows usage of the \`${METADATA_PROPERTY_NAME}\` metadata property. NOTE: This used to be recommended by the Angular Team, but now they recommend the exact opposite: https://github.com/angular/angular/issues/54284`,
|
|
17
|
-
},
|
|
18
|
-
schema: [
|
|
19
|
-
{
|
|
20
|
-
type: 'object',
|
|
21
|
-
properties: {
|
|
22
|
-
allowStatic: {
|
|
23
|
-
type: 'boolean',
|
|
24
|
-
default: DEFAULT_OPTIONS.allowStatic,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
additionalProperties: false,
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
messages: {
|
|
31
|
-
noHostMetadataProperty: `Use @${utils_1.ASTUtils.AngularInnerClassDecorators.HostBinding} or @${utils_1.ASTUtils.AngularInnerClassDecorators.HostListener} rather than the \`${METADATA_PROPERTY_NAME}\` metadata property`,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
defaultOptions: [DEFAULT_OPTIONS],
|
|
35
|
-
create(context, [{ allowStatic }]) {
|
|
36
|
-
return {
|
|
37
|
-
[`${utils_1.Selectors.COMPONENT_OR_DIRECTIVE_CLASS_DECORATOR} Property[key.name="${METADATA_PROPERTY_NAME}"]`](node) {
|
|
38
|
-
const properties = allowStatic && utils_1.ASTUtils.isObjectExpression(node.value)
|
|
39
|
-
? node.value.properties.filter(isDynamic)
|
|
40
|
-
: [node];
|
|
41
|
-
properties.forEach((property) => {
|
|
42
|
-
context.report({
|
|
43
|
-
node: property,
|
|
44
|
-
messageId: 'noHostMetadataProperty',
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
function startsWithLetter({ [0]: firstLetter }) {
|
|
52
|
-
return firstLetter.toLowerCase() !== firstLetter.toUpperCase();
|
|
53
|
-
}
|
|
54
|
-
function isEmptyStringValue(property) {
|
|
55
|
-
return (utils_1.ASTUtils.isStringLiteral(property.value) && property.value.value === '');
|
|
56
|
-
}
|
|
57
|
-
function isStatic(property) {
|
|
58
|
-
return (!property.computed &&
|
|
59
|
-
(utils_2.ASTUtils.isIdentifier(property.key) ||
|
|
60
|
-
(utils_1.ASTUtils.isStringLiteral(property.key) &&
|
|
61
|
-
startsWithLetter(property.key.value))));
|
|
62
|
-
}
|
|
63
|
-
function isDynamic(property) {
|
|
64
|
-
return (utils_1.ASTUtils.isProperty(property) &&
|
|
65
|
-
!isStatic(property) &&
|
|
66
|
-
!isEmptyStringValue(property));
|
|
67
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type Options = [];
|
|
2
|
-
export type MessageIds = 'preferStandaloneComponent';
|
|
3
|
-
export declare const RULE_NAME = "prefer-standalone-component";
|
|
4
|
-
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferStandaloneComponent", [], import("../utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
5
|
-
export default _default;
|
|
6
|
-
//# sourceMappingURL=prefer-standalone-component.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-standalone-component.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-standalone-component.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,2BAA2B,CAAC;AACrD,eAAO,MAAM,SAAS,gCAAgC,CAAC;;AAIvD,wBA0DG"}
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
exports.RULE_NAME = 'prefer-standalone-component';
|
|
7
|
-
const METADATA_PROPERTY_NAME = 'standalone';
|
|
8
|
-
const IS_STANDALONE = 'true';
|
|
9
|
-
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
10
|
-
name: exports.RULE_NAME,
|
|
11
|
-
meta: {
|
|
12
|
-
type: 'suggestion',
|
|
13
|
-
docs: {
|
|
14
|
-
description: `Ensures component \`${METADATA_PROPERTY_NAME}\` property is set to \`${IS_STANDALONE}\` in the component decorator`,
|
|
15
|
-
},
|
|
16
|
-
deprecated: true,
|
|
17
|
-
replacedBy: ['prefer-standalone'],
|
|
18
|
-
fixable: 'code',
|
|
19
|
-
schema: [],
|
|
20
|
-
messages: {
|
|
21
|
-
preferStandaloneComponent: `The component \`${METADATA_PROPERTY_NAME}\` property should be set to \`${IS_STANDALONE}\``,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
defaultOptions: [],
|
|
25
|
-
create(context) {
|
|
26
|
-
return {
|
|
27
|
-
[utils_1.Selectors.COMPONENT_CLASS_DECORATOR](node) {
|
|
28
|
-
const standalone = utils_1.ASTUtils.getDecoratorPropertyValue(node, METADATA_PROPERTY_NAME);
|
|
29
|
-
if (standalone &&
|
|
30
|
-
utils_1.ASTUtils.isLiteral(standalone) &&
|
|
31
|
-
standalone.value === true) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
context.report({
|
|
35
|
-
node: nodeToReport(node),
|
|
36
|
-
messageId: 'preferStandaloneComponent',
|
|
37
|
-
fix: (fixer) => {
|
|
38
|
-
if (standalone &&
|
|
39
|
-
utils_1.ASTUtils.isLiteral(standalone) &&
|
|
40
|
-
standalone.value !== true) {
|
|
41
|
-
return [fixer.replaceText(standalone, IS_STANDALONE)].filter(utils_1.isNotNullOrUndefined);
|
|
42
|
-
}
|
|
43
|
-
return [
|
|
44
|
-
utils_1.RuleFixes.getDecoratorPropertyAddFix(node, fixer, `${METADATA_PROPERTY_NAME}: ${IS_STANDALONE}`),
|
|
45
|
-
].filter(utils_1.isNotNullOrUndefined);
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
function nodeToReport(node) {
|
|
53
|
-
if (!utils_1.ASTUtils.isProperty(node)) {
|
|
54
|
-
return node;
|
|
55
|
-
}
|
|
56
|
-
return utils_1.ASTUtils.isMemberExpression(node.value)
|
|
57
|
-
? node.value.property
|
|
58
|
-
: node.value;
|
|
59
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type Options = [
|
|
2
|
-
{
|
|
3
|
-
readonly locale: string;
|
|
4
|
-
}
|
|
5
|
-
];
|
|
6
|
-
export type MessageIds = 'sortNgmoduleMetadataArrays';
|
|
7
|
-
export declare const RULE_NAME = "sort-ngmodule-metadata-arrays";
|
|
8
|
-
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"sortNgmoduleMetadataArrays", Options, import("../utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
9
|
-
export default _default;
|
|
10
|
-
//# sourceMappingURL=sort-ngmodule-metadata-arrays.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sort-ngmodule-metadata-arrays.d.ts","sourceRoot":"","sources":["../../src/rules/sort-ngmodule-metadata-arrays.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,4BAA4B,CAAC;AACtD,eAAO,MAAM,SAAS,kCAAkC,CAAC;;AAGzD,wBA2DG"}
|
|
@@ -1,63 +0,0 @@
|
|
|
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 utils_2 = require("@typescript-eslint/utils");
|
|
6
|
-
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
7
|
-
exports.RULE_NAME = 'sort-ngmodule-metadata-arrays';
|
|
8
|
-
const DEFAULT_LOCALE = 'en-US';
|
|
9
|
-
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
10
|
-
name: exports.RULE_NAME,
|
|
11
|
-
meta: {
|
|
12
|
-
type: 'suggestion',
|
|
13
|
-
deprecated: true,
|
|
14
|
-
docs: {
|
|
15
|
-
description: 'Ensures ASC alphabetical order for `NgModule` metadata arrays for easy visual scanning',
|
|
16
|
-
},
|
|
17
|
-
fixable: 'code',
|
|
18
|
-
schema: [
|
|
19
|
-
{
|
|
20
|
-
type: 'object',
|
|
21
|
-
properties: {
|
|
22
|
-
locale: {
|
|
23
|
-
type: 'string',
|
|
24
|
-
description: 'A string with a BCP 47 language tag.',
|
|
25
|
-
default: DEFAULT_LOCALE,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
additionalProperties: false,
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
messages: {
|
|
32
|
-
sortNgmoduleMetadataArrays: '`NgModule` metadata arrays should be sorted in ASC alphabetical order',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
defaultOptions: [
|
|
36
|
-
{
|
|
37
|
-
locale: DEFAULT_LOCALE,
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
create(context, [{ locale }]) {
|
|
41
|
-
return {
|
|
42
|
-
[`${utils_1.Selectors.MODULE_CLASS_DECORATOR} Property[key.name!="deps"] > ArrayExpression`]({ elements, }) {
|
|
43
|
-
const unorderedNodes = elements
|
|
44
|
-
.filter(utils_2.ASTUtils.isIdentifier)
|
|
45
|
-
.map((current, index, list) => [current, list[index + 1]])
|
|
46
|
-
.find(([current, next]) => {
|
|
47
|
-
return next && current.name.localeCompare(next.name, locale) === 1;
|
|
48
|
-
});
|
|
49
|
-
if (!unorderedNodes)
|
|
50
|
-
return;
|
|
51
|
-
const [unorderedNode, nextNode] = unorderedNodes;
|
|
52
|
-
context.report({
|
|
53
|
-
node: nextNode,
|
|
54
|
-
messageId: 'sortNgmoduleMetadataArrays',
|
|
55
|
-
fix: (fixer) => [
|
|
56
|
-
fixer.replaceText(unorderedNode, nextNode.name),
|
|
57
|
-
fixer.replaceText(nextNode, unorderedNode.name),
|
|
58
|
-
],
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
});
|