@angular-eslint/eslint-plugin 22.2.0 → 22.2.1-alpha.1
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.
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export type Options = [
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type Options = [
|
|
2
|
+
{
|
|
3
|
+
readonly ignoreClassNamePattern?: string;
|
|
4
|
+
readonly allowProvidedInNull?: boolean;
|
|
5
|
+
}
|
|
6
|
+
];
|
|
4
7
|
export type MessageIds = 'useInjectableProvidedIn' | 'suggestInjector';
|
|
5
8
|
export declare const RULE_NAME = "use-injectable-provided-in";
|
|
6
9
|
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> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-injectable-provided-in.d.ts","sourceRoot":"","sources":["../../src/rules/use-injectable-provided-in.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG
|
|
1
|
+
{"version":3,"file":"use-injectable-provided-in.d.ts","sourceRoot":"","sources":["../../src/rules/use-injectable-provided-in.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC;QACzC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;KACxC;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,yBAAyB,GAAG,iBAAiB,CAAC;AACvE,eAAO,MAAM,SAAS,+BAA+B,CAAC;;;;AAMtD,wBAiEG;AAEH,eAAO,MAAM,mBAAmB;;CAE/B,CAAC"}
|
|
@@ -5,6 +5,9 @@ const utils_1 = require("@angular-eslint/utils");
|
|
|
5
5
|
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
6
6
|
exports.RULE_NAME = 'use-injectable-provided-in';
|
|
7
7
|
const METADATA_PROPERTY_NAME = 'providedIn';
|
|
8
|
+
const DEFAULT_OPTIONS = {
|
|
9
|
+
allowProvidedInNull: false,
|
|
10
|
+
};
|
|
8
11
|
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
9
12
|
name: exports.RULE_NAME,
|
|
10
13
|
meta: {
|
|
@@ -20,6 +23,10 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
20
23
|
ignoreClassNamePattern: {
|
|
21
24
|
type: 'string',
|
|
22
25
|
},
|
|
26
|
+
allowProvidedInNull: {
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
default: DEFAULT_OPTIONS.allowProvidedInNull,
|
|
29
|
+
},
|
|
23
30
|
},
|
|
24
31
|
additionalProperties: false,
|
|
25
32
|
},
|
|
@@ -29,15 +36,17 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
29
36
|
suggestInjector: `Use \`${METADATA_PROPERTY_NAME}: '{{injector}}'\``,
|
|
30
37
|
},
|
|
31
38
|
},
|
|
32
|
-
defaultOptions: [
|
|
33
|
-
create(context, [{ ignoreClassNamePattern }]) {
|
|
39
|
+
defaultOptions: [DEFAULT_OPTIONS],
|
|
40
|
+
create(context, [{ ignoreClassNamePattern, allowProvidedInNull }]) {
|
|
34
41
|
const injectableClassDecorator = `ClassDeclaration:not([id.name=${ignoreClassNamePattern}]):not(:has(TSClassImplements:matches([expression.property.name='HttpInterceptor'], [expression.name='HttpInterceptor']))) > Decorator[expression.callee.name="Injectable"]`;
|
|
35
42
|
const providedInMetadataProperty = utils_1.Selectors.metadataProperty(METADATA_PROPERTY_NAME);
|
|
36
43
|
const withoutProvidedInDecorator = `${injectableClassDecorator}:matches([expression.arguments.length=0], [expression.arguments.0.type='ObjectExpression']:not(:has(${providedInMetadataProperty})))`;
|
|
37
|
-
const
|
|
44
|
+
const undefinedProvidedInProperty = `${injectableClassDecorator} ${providedInMetadataProperty}[value.type='Identifier'][value.name='undefined']`;
|
|
45
|
+
const nullProvidedInProperty = `${injectableClassDecorator} ${providedInMetadataProperty}[value.type='Literal'][value.raw='null']`;
|
|
38
46
|
const selectors = [
|
|
39
47
|
withoutProvidedInDecorator,
|
|
40
|
-
|
|
48
|
+
undefinedProvidedInProperty,
|
|
49
|
+
...(allowProvidedInNull ? [] : [nullProvidedInProperty]),
|
|
41
50
|
].join(',');
|
|
42
51
|
return {
|
|
43
52
|
[selectors](node) {
|
|
@@ -59,5 +68,5 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
59
68
|
},
|
|
60
69
|
});
|
|
61
70
|
exports.RULE_DOCS_EXTENSION = {
|
|
62
|
-
rationale: `Using 'providedIn' in the @Injectable() decorator (like '@Injectable({ providedIn: "root" })') enables tree-shaking, which means Angular can remove the service from your production bundle if it's never actually used. Without 'providedIn', services must be registered in a module's providers array, and Angular must include them in the bundle even if they're unused. This can significantly increase bundle size. Additionally, 'providedIn' makes services easier to use (no need to add them to module providers) and makes circular dependencies less likely. The 'providedIn' syntax is the modern, recommended way to provide services.`,
|
|
71
|
+
rationale: `Using 'providedIn' in the @Injectable() decorator (like '@Injectable({ providedIn: "root" })') enables tree-shaking, which means Angular can remove the service from your production bundle if it's never actually used. Without 'providedIn', services must be registered in a module's providers array, and Angular must include them in the bundle even if they're unused. This can significantly increase bundle size. Additionally, 'providedIn' makes services easier to use (no need to add them to module providers) and makes circular dependencies less likely. The 'providedIn' syntax is the modern, recommended way to provide services. Angular treats 'providedIn: null' as equivalent to omitting the property, so it is flagged by default. Set 'allowProvidedInNull' to true if you need to permit this pattern.`,
|
|
63
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin",
|
|
3
|
-
"version": "22.2.
|
|
3
|
+
"version": "22.2.1-alpha.1",
|
|
4
4
|
"description": "ESLint plugin for Angular applications, following https://angular.dev/style-guide",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"@angular-eslint/
|
|
24
|
-
"
|
|
22
|
+
"@angular-eslint/bundled-angular-compiler": "22.2.1-alpha.1",
|
|
23
|
+
"@angular-eslint/utils": "22.2.1-alpha.1",
|
|
24
|
+
"ts-api-utils": "^2.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@angular-eslint/test-utils": "22.2.
|
|
27
|
+
"@angular-eslint/test-utils": "22.2.1-alpha.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@typescript-eslint/utils": "^8.0.0",
|