@angular-eslint/eslint-plugin 16.1.0-alpha.0 → 16.1.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/configs/all.json
CHANGED
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@angular-eslint/pipe-prefix": "error",
|
|
28
28
|
"@angular-eslint/prefer-on-push-component-change-detection": "error",
|
|
29
29
|
"@angular-eslint/prefer-output-readonly": "error",
|
|
30
|
+
"@angular-eslint/prefer-standalone-component": "error",
|
|
30
31
|
"@angular-eslint/relative-url-prefix": "error",
|
|
31
|
-
"@angular-eslint/sort-imports-metadata": "error",
|
|
32
32
|
"@angular-eslint/sort-ngmodule-metadata-arrays": "error",
|
|
33
33
|
"@angular-eslint/use-component-selector": "error",
|
|
34
34
|
"@angular-eslint/use-component-view-encapsulation": "error",
|
package/dist/index.js
CHANGED
|
@@ -51,9 +51,9 @@ const no_pipe_impure_1 = __importStar(require("./rules/no-pipe-impure"));
|
|
|
51
51
|
const no_queries_metadata_property_1 = __importStar(require("./rules/no-queries-metadata-property"));
|
|
52
52
|
const pipe_prefix_1 = __importStar(require("./rules/pipe-prefix"));
|
|
53
53
|
const prefer_on_push_component_change_detection_1 = __importStar(require("./rules/prefer-on-push-component-change-detection"));
|
|
54
|
+
const prefer_standalone_component_1 = __importStar(require("./rules/prefer-standalone-component"));
|
|
54
55
|
const prefer_output_readonly_1 = __importStar(require("./rules/prefer-output-readonly"));
|
|
55
56
|
const relative_url_prefix_1 = __importStar(require("./rules/relative-url-prefix"));
|
|
56
|
-
const sort_imports_metadata_1 = __importStar(require("./rules/sort-imports-metadata"));
|
|
57
57
|
const sort_ngmodule_metadata_arrays_1 = __importStar(require("./rules/sort-ngmodule-metadata-arrays"));
|
|
58
58
|
const use_component_selector_1 = __importStar(require("./rules/use-component-selector"));
|
|
59
59
|
const use_component_view_encapsulation_1 = __importStar(require("./rules/use-component-view-encapsulation"));
|
|
@@ -90,9 +90,9 @@ module.exports = {
|
|
|
90
90
|
[no_queries_metadata_property_1.RULE_NAME]: no_queries_metadata_property_1.default,
|
|
91
91
|
[pipe_prefix_1.RULE_NAME]: pipe_prefix_1.default,
|
|
92
92
|
[prefer_on_push_component_change_detection_1.RULE_NAME]: prefer_on_push_component_change_detection_1.default,
|
|
93
|
+
[prefer_standalone_component_1.RULE_NAME]: prefer_standalone_component_1.default,
|
|
93
94
|
[prefer_output_readonly_1.RULE_NAME]: prefer_output_readonly_1.default,
|
|
94
95
|
[relative_url_prefix_1.RULE_NAME]: relative_url_prefix_1.default,
|
|
95
|
-
[sort_imports_metadata_1.RULE_NAME]: sort_imports_metadata_1.default,
|
|
96
96
|
[sort_ngmodule_metadata_arrays_1.RULE_NAME]: sort_ngmodule_metadata_arrays_1.default,
|
|
97
97
|
[use_component_selector_1.RULE_NAME]: use_component_selector_1.default,
|
|
98
98
|
[use_component_view_encapsulation_1.RULE_NAME]: use_component_view_encapsulation_1.default,
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
recommended: false,
|
|
16
|
+
},
|
|
17
|
+
fixable: 'code',
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: {
|
|
20
|
+
preferStandaloneComponent: `The component \`${METADATA_PROPERTY_NAME}\` property should be set to \`${IS_STANDALONE}\``,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultOptions: [],
|
|
24
|
+
create(context) {
|
|
25
|
+
return {
|
|
26
|
+
[utils_1.Selectors.COMPONENT_CLASS_DECORATOR](node) {
|
|
27
|
+
const standalone = utils_1.ASTUtils.getDecoratorPropertyValue(node, METADATA_PROPERTY_NAME);
|
|
28
|
+
if (standalone &&
|
|
29
|
+
utils_1.ASTUtils.isLiteral(standalone) &&
|
|
30
|
+
standalone.value === true) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
context.report({
|
|
34
|
+
node: nodeToReport(node),
|
|
35
|
+
messageId: 'preferStandaloneComponent',
|
|
36
|
+
fix: (fixer) => {
|
|
37
|
+
if (standalone &&
|
|
38
|
+
utils_1.ASTUtils.isLiteral(standalone) &&
|
|
39
|
+
standalone.value !== true) {
|
|
40
|
+
return [fixer.replaceText(standalone, IS_STANDALONE)].filter(utils_1.isNotNullOrUndefined);
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
utils_1.RuleFixes.getDecoratorPropertyAddFix(node, fixer, `${METADATA_PROPERTY_NAME}: ${IS_STANDALONE}`),
|
|
44
|
+
].filter(utils_1.isNotNullOrUndefined);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
function nodeToReport(node) {
|
|
52
|
+
if (!utils_1.ASTUtils.isProperty(node)) {
|
|
53
|
+
return node;
|
|
54
|
+
}
|
|
55
|
+
return utils_1.ASTUtils.isMemberExpression(node.value)
|
|
56
|
+
? node.value.property
|
|
57
|
+
: node.value;
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin",
|
|
3
|
-
"version": "16.1.
|
|
3
|
+
"version": "16.1.1-alpha.0+dce6381",
|
|
4
4
|
"description": "ESLint plugin for Angular applications, following angular.io/styleguide",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"LICENSE"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@angular-eslint/utils": "16.1.
|
|
21
|
-
"@typescript-eslint/utils": "5.
|
|
20
|
+
"@angular-eslint/utils": "16.1.1-alpha.0+dce6381",
|
|
21
|
+
"@typescript-eslint/utils": "5.62.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"eslint": "^7.20.0 || ^8.0.0",
|
|
25
25
|
"typescript": "*"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "dce6381cafcbe2de109d0a53b4c9c3e3bf1ae569"
|
|
28
28
|
}
|
|
@@ -1,156 +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-imports-metadata';
|
|
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
|
-
docs: {
|
|
14
|
-
description: 'Ensures ASC alphabetical order for import arrays for easy visual scanning',
|
|
15
|
-
recommended: false,
|
|
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
|
-
sortImportsMetadata: 'Imports should be sorted in ASC alphabetical order',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
defaultOptions: [
|
|
36
|
-
{
|
|
37
|
-
locale: DEFAULT_LOCALE,
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
create(context, [{ locale }]) {
|
|
41
|
-
const selectors = [
|
|
42
|
-
`${utils_1.Selectors.COMPONENT_OR_DIRECTIVE_CLASS_DECORATOR} Property[key.name="imports"] > ArrayExpression`,
|
|
43
|
-
`${utils_1.Selectors.MODULE_CLASS_DECORATOR} Property[key.name="imports"] > ArrayExpression`,
|
|
44
|
-
`${utils_1.Selectors.PIPE_CLASS_DECORATOR} Property[key.name="imports"] > ArrayExpression`,
|
|
45
|
-
].join(',');
|
|
46
|
-
return {
|
|
47
|
-
[selectors]({ elements }) {
|
|
48
|
-
var _a, _b;
|
|
49
|
-
const imports = elements.filter(utils_2.ASTUtils.isIdentifier);
|
|
50
|
-
if (importsAreSorted(imports, locale)) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const firstOriginalElement = elements[0];
|
|
54
|
-
const lastOriginalElement = elements[elements.length - 1];
|
|
55
|
-
const nodeForFixer = firstOriginalElement.parent;
|
|
56
|
-
// IMPORTANT NOTE: Although we want to delegate formatting to the user's formatter of choice, this rule will perform basic formatting to ensure some presentability (especially around block comments)
|
|
57
|
-
// If all of the imports are on one line, indent the output 2 columns ahead of the `imports` keyword
|
|
58
|
-
// Else, indent the output to match the indentation of the first import
|
|
59
|
-
const whitespacePrefix = elements.every((element) => (element === null || element === void 0 ? void 0 : element.loc.start.line) === firstOriginalElement.loc.start.line)
|
|
60
|
-
? ' '.repeat(((_a = nodeForFixer.parent) === null || _a === void 0 ? void 0 : _a.loc.start.column) + 2)
|
|
61
|
-
: ' '.repeat(firstOriginalElement.loc.start.column);
|
|
62
|
-
// For each import entry, get all related comments, stringify them, and group them with the import entry
|
|
63
|
-
const importEntriesWithComments = getImportEntriesWithComments(imports, context, whitespacePrefix);
|
|
64
|
-
// Sort the imports
|
|
65
|
-
importEntriesWithComments.sort((importA, importB) => importA.importName.localeCompare(importB.importName, locale));
|
|
66
|
-
const sortedImportsWithCommentsString = `[\n${getSortedImportsWithCommentsAsString(importEntriesWithComments, whitespacePrefix)}${' '.repeat((_b = nodeForFixer.parent) === null || _b === void 0 ? void 0 : _b.loc.start.column)}]`;
|
|
67
|
-
context.report({
|
|
68
|
-
messageId: 'sortImportsMetadata',
|
|
69
|
-
loc: {
|
|
70
|
-
start: firstOriginalElement.loc.start,
|
|
71
|
-
end: lastOriginalElement.loc.end,
|
|
72
|
-
},
|
|
73
|
-
fix: (fixer) => fixer.replaceText(nodeForFixer, sortedImportsWithCommentsString),
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
function getImportEntriesWithComments(imports, context, whitespacePrefix) {
|
|
80
|
-
const sourceCode = context.getSourceCode();
|
|
81
|
-
const importEntriesWithComments = [];
|
|
82
|
-
for (let i = 0; i < imports.length; i++) {
|
|
83
|
-
const importEntry = imports[i];
|
|
84
|
-
// Handle comments above the import entry
|
|
85
|
-
let commentsBeforeImport = sourceCode.getCommentsBefore(importEntry);
|
|
86
|
-
const previousImportEntry = imports[i - 1];
|
|
87
|
-
if (previousImportEntry) {
|
|
88
|
-
commentsBeforeImport = commentsBeforeImport.filter((comment) => comment.loc.start.line !== previousImportEntry.loc.start.line);
|
|
89
|
-
}
|
|
90
|
-
const commentsBeforeString = getCommentsAsString(commentsBeforeImport, whitespacePrefix);
|
|
91
|
-
// Handle comments on the same line as the import entry
|
|
92
|
-
// Same-line comments appear in the next import entry's `getCommentsBefore`
|
|
93
|
-
let commentsSameLineString = '';
|
|
94
|
-
const nextImportEntry = imports[i + 1];
|
|
95
|
-
if (nextImportEntry) {
|
|
96
|
-
commentsSameLineString = getCommentsAsString(sourceCode
|
|
97
|
-
.getCommentsBefore(nextImportEntry)
|
|
98
|
-
.filter((comment) => comment.loc.start.line === importEntry.loc.start.line));
|
|
99
|
-
}
|
|
100
|
-
// Handle comments after the import entry
|
|
101
|
-
const commentsAfterString = getCommentsAsString(sourceCode.getCommentsAfter(importEntry), whitespacePrefix);
|
|
102
|
-
const importEntryWithComments = {
|
|
103
|
-
commentsBefore: commentsBeforeString,
|
|
104
|
-
commentsSameLine: commentsSameLineString,
|
|
105
|
-
commentsAfter: commentsAfterString,
|
|
106
|
-
importName: importEntry.name,
|
|
107
|
-
};
|
|
108
|
-
importEntriesWithComments.push(importEntryWithComments);
|
|
109
|
-
}
|
|
110
|
-
return importEntriesWithComments;
|
|
111
|
-
}
|
|
112
|
-
function getSortedImportsWithCommentsAsString(sortedImportEntriesWithComments, whitespacePrefix) {
|
|
113
|
-
let sortedImportsWithCommentsString = '';
|
|
114
|
-
for (const importEntry of sortedImportEntriesWithComments) {
|
|
115
|
-
if (importEntry.commentsBefore) {
|
|
116
|
-
sortedImportsWithCommentsString += `${importEntry.commentsBefore}`;
|
|
117
|
-
}
|
|
118
|
-
sortedImportsWithCommentsString += `${whitespacePrefix}${importEntry.importName},`;
|
|
119
|
-
if (importEntry.commentsSameLine) {
|
|
120
|
-
sortedImportsWithCommentsString += ` ${importEntry.commentsSameLine}`;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
sortedImportsWithCommentsString += '\n';
|
|
124
|
-
}
|
|
125
|
-
if (importEntry.commentsAfter) {
|
|
126
|
-
sortedImportsWithCommentsString += `${importEntry.commentsAfter}`;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return sortedImportsWithCommentsString;
|
|
130
|
-
}
|
|
131
|
-
function getCommentsAsString(comments, whitespacePrefix) {
|
|
132
|
-
let commentsString = '';
|
|
133
|
-
if (comments) {
|
|
134
|
-
for (const comment of comments) {
|
|
135
|
-
if (comment.type === 'Line') {
|
|
136
|
-
commentsString += `${whitespacePrefix ? whitespacePrefix : ''}//${comment.value}\n`;
|
|
137
|
-
}
|
|
138
|
-
else if (comment.type === 'Block') {
|
|
139
|
-
commentsString += `${whitespacePrefix ? whitespacePrefix : ''}/*${comment.value}*/\n`;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return commentsString;
|
|
144
|
-
}
|
|
145
|
-
function importsAreSorted(imports, locale) {
|
|
146
|
-
const importNames = imports.map((importEntry) => importEntry.name);
|
|
147
|
-
let secondIndex;
|
|
148
|
-
for (let firstIndex = 0; firstIndex < importNames.length; firstIndex++) {
|
|
149
|
-
secondIndex = firstIndex + 1;
|
|
150
|
-
if (importNames[firstIndex].localeCompare(importNames[secondIndex], locale) >
|
|
151
|
-
0) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return true;
|
|
156
|
-
}
|