Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4583034

Browse files
committed
feat(eslint-plugin)!: switch prefer-standalone fix to suggestion, reference guide
1 parent6c77dd9 commit4583034

File tree

2 files changed

+62
-23
lines changed

2 files changed

+62
-23
lines changed

‎packages/eslint-plugin/src/rules/prefer-standalone.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ import { createESLintRule } from '../utils/create-eslint-rule';
44

55
exporttypeOptions=[];
66
typeDecoratorTypes='component'|'directive'|'pipe';
7-
exporttypeMessageIds='preferStandalone';
7+
exporttypeMessageIds='preferStandalone'|'removeStandaloneFalse';
88
exportconstRULE_NAME='prefer-standalone';
99

10+
constRECOMMENDED_GUIDE_URL=
11+
'https://angular.dev/reference/migrations/standalone';
12+
1013
exportdefaultcreateESLintRule<Options,MessageIds>({
1114
name:RULE_NAME,
1215
meta:{
1316
type:'suggestion',
1417
docs:{
15-
description:`Ensures Components, Directives and Pipes do not opt out of standalone`,
18+
description:`Ensures Components, Directives and Pipes do not opt out of standalone.`,
1619
recommended:'recommended',
1720
},
18-
fixable:'code',
21+
hasSuggestions:true,
1922
schema:[],
2023
messages:{
21-
preferStandalone:`Components, Directives and Pipes should not opt out of standalone`,
24+
preferStandalone:`Components, Directives and Pipes should not opt out of standalone. Following this guide is highly recommended:${RECOMMENDED_GUIDE_URL}`,
25+
removeStandaloneFalse:`Quickly remove 'standalone: false'. NOTE - Following this guide is highly recommended:${RECOMMENDED_GUIDE_URL}`,
2226
},
2327
},
2428
defaultOptions:[],
@@ -45,19 +49,24 @@ export default createESLintRule<Options, MessageIds>({
4549
node:standalone.parent,
4650
messageId:'preferStandalone',
4751
data:{ type},
48-
fix:(fixer)=>{
49-
// Remove the standalone property altogether if it was set to false
50-
consttokenAfter=context.sourceCode.getTokenAfter(
51-
standalone.parent,
52-
);
53-
// Remove the trailing comma, if present
54-
constremoveStart=standalone.parent.range[0];
55-
letremoveEnd=standalone.parent.range[1];
56-
if(tokenAfter&&tokenAfter.value===','){
57-
removeEnd=tokenAfter.range[1];
58-
}
59-
returnfixer.removeRange([removeStart,removeEnd]);
60-
},
52+
suggest:[
53+
{
54+
messageId:'removeStandaloneFalse',
55+
fix:(fixer)=>{
56+
// Remove the standalone property altogether if it was set to false
57+
consttokenAfter=context.sourceCode.getTokenAfter(
58+
standalone.parent,
59+
);
60+
// Remove the trailing comma, if present
61+
constremoveStart=standalone.parent.range[0];
62+
letremoveEnd=standalone.parent.range[1];
63+
if(tokenAfter&&tokenAfter.value===','){
64+
removeEnd=tokenAfter.range[1];
65+
}
66+
returnfixer.removeRange([removeStart,removeEnd]);
67+
},
68+
},
69+
],
6170
});
6271
};
6372

‎packages/eslint-plugin/tests/rules/prefer-standalone/cases.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,16 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
141141
`,
142142
messageId,
143143
data:{type:'component'},
144-
annotatedOutput:`
144+
suggestions:[
145+
{
146+
messageId:'removeStandaloneFalse',
147+
output:`
145148
@Component({ })
146149
147150
class Test {}
148151
`,
152+
},
153+
],
149154
}),
150155
convertAnnotatedSourceToFailureCase({
151156
description:
@@ -160,14 +165,19 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
160165
`,
161166
messageId,
162167
data:{type:'component'},
163-
annotatedOutput:`
168+
suggestions:[
169+
{
170+
messageId:'removeStandaloneFalse',
171+
output:`
164172
@Component({
165173
166174
167175
template: '<div></div>'
168176
})
169177
class Test {}
170178
`,
179+
},
180+
],
171181
}),
172182
convertAnnotatedSourceToFailureCase({
173183
description:
@@ -179,11 +189,16 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
179189
`,
180190
messageId,
181191
data:{type:'directive'},
182-
annotatedOutput:`
192+
suggestions:[
193+
{
194+
messageId:'removeStandaloneFalse',
195+
output:`
183196
@Directive({ })
184197
185198
class Test {}
186199
`,
200+
},
201+
],
187202
}),
188203
convertAnnotatedSourceToFailureCase({
189204
description:
@@ -198,14 +213,19 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
198213
`,
199214
messageId,
200215
data:{type:'directive'},
201-
annotatedOutput:`
216+
suggestions:[
217+
{
218+
messageId:'removeStandaloneFalse',
219+
output:`
202220
@Directive({
203221
204222
205223
selector: 'x-selector'
206224
})
207225
class Test {}
208226
`,
227+
},
228+
],
209229
}),
210230
convertAnnotatedSourceToFailureCase({
211231
description:
@@ -217,11 +237,16 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
217237
`,
218238
messageId,
219239
data:{type:'pipe'},
220-
annotatedOutput:`
240+
suggestions:[
241+
{
242+
messageId:'removeStandaloneFalse',
243+
output:`
221244
@Pipe({ })
222245
223246
class Test {}
224247
`,
248+
},
249+
],
225250
}),
226251
convertAnnotatedSourceToFailureCase({
227252
description:
@@ -236,13 +261,18 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
236261
`,
237262
messageId,
238263
data:{type:'pipe'},
239-
annotatedOutput:`
264+
suggestions:[
265+
{
266+
messageId:'removeStandaloneFalse',
267+
output:`
240268
@Pipe({
241269
242270
243271
name: 'pipe-name'
244272
})
245273
class Test {}
246274
`,
275+
},
276+
],
247277
}),
248278
];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp