Skip to content

Commit

Permalink
fix: make deprecateAliases a suggestion (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc authored Jan 11, 2023
1 parent 72f8517 commit cfb49d4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
23 changes: 17 additions & 6 deletions src/rules/migration/encourage-alias-deprecation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils';
import { RuleFix } from '@typescript-eslint/utils/dist/ts-eslint';
import { isInCommandDirectory, ancestorsContainsSfCommand } from '../../shared/commands';
import { flagPropertyIsNamed, isFlag } from '../../shared/flags';

Expand Down Expand Up @@ -46,9 +47,14 @@ export const encourageAliasDeprecation = ESLintUtils.RuleCreator.withoutDocs({
context.report({
node,
messageId: 'command',
fix: (fixer) => {
return fixer.insertTextBefore(node, 'public static readonly deprecateAliases = true;');
},
suggest: [
{
messageId: 'command',
fix: (fixer): RuleFix => {
return fixer.insertTextBefore(node, 'public static readonly deprecateAliases = true;');
},
},
],
});
}
}
Expand All @@ -74,9 +80,14 @@ export const encourageAliasDeprecation = ESLintUtils.RuleCreator.withoutDocs({
context.report({
node: aliasesProperty,
messageId: 'flag',
fix: (fixer) => {
return fixer.insertTextBefore(aliasesProperty, 'deprecateAliases:true,');
},
suggest: [
{
messageId: 'flag',
fix: (fixer): RuleFix => {
return fixer.insertTextBefore(aliasesProperty, 'deprecateAliases:true,');
},
},
],
});
}
}
Expand Down
40 changes: 30 additions & 10 deletions test/rules/migration/encourageAliasDeprecation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,56 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
{
name: 'aliases without deprecation',
filename: path.normalize('src/commands/foo.ts'),
errors: [{ messageId: 'command' }],
code: `
errors: [
{
messageId: 'command',
suggestions: [
{
messageId: 'command',
output: `
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static readonly aliases = ['foo'];
public static readonly deprecateAliases = true;public static readonly aliases = ['foo'];
}`,
output: `
},
],
},
],
output: null,
code: `
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static readonly deprecateAliases = true;public static readonly aliases = ['foo'];
public static readonly aliases = ['foo'];
}`,
},
{
name: 'flag alias without deprecation',
filename: path.normalize('src/commands/foo.ts'),
errors: [{ messageId: 'flag' }],
code: `
errors: [
{
messageId: 'flag',
suggestions: [
{
messageId: 'flag',
output: `
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static readonly flags = {
foo: Flags.string({
aliases: ['bar'],
deprecateAliases:true,aliases: ['bar'],
})
}
}`,
output: `
},
],
},
],
code: `
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static readonly flags = {
foo: Flags.string({
deprecateAliases:true,aliases: ['bar'],
aliases: ['bar'],
})
}
}`,
output: null,
},
],
});

0 comments on commit cfb49d4

Please sign in to comment.