Skip to content

Commit

Permalink
fix: exclude things that don't extend sfCommand or use args
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jan 23, 2023
1 parent 3c56c59 commit 5c42964
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/rules/migration/no-deprecated-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const noDeprecatedProperties = ESLintUtils.RuleCreator.withoutDocs({
if (ancestorsContainsSfCommand(context.getAncestors())) {
if (
node.key.type === AST_NODE_TYPES.Identifier &&
['supportsDevhubUsername', 'varargs', 'args'].includes(node.key.name)
['supportsDevhubUsername', 'varargs'].includes(node.key.name)
) {
context.report({
node,
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no-args-parse-without-strict-false.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ export const noArgsParseWithoutStrictFalse = ESLintUtils.RuleCreator.withoutDocs
(p) =>
p.type === AST_NODE_TYPES.Property &&
p.key.type === AST_NODE_TYPES.Identifier &&
(p.key.name === 'args' || p.key.name === 'argv')
p.key.name === 'argv'
)
) {
// Verify that the class has strict = false
const ancestors = context.getAncestors();
const sfCommand = getSfCommand(ancestors);
if (!sfCommand) {
return;
}
const strictProperty = sfCommand.body.body.find(
(p) =>
p.type === AST_NODE_TYPES.PropertyDefinition &&
Expand Down
10 changes: 5 additions & 5 deletions test/rules/migration/no-deprecated-properties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export default class EnvCreateScratch extends SfCommand<string> {
invalid: [
//
{
name: 'args',
name: 'varargs',
filename: path.normalize('src/commands/foo.ts'),
errors: [{ messageId: 'property', data: { property: 'args' } }],
errors: [{ messageId: 'property', data: { property: 'varargs' } }],
code: `
export default class EnvCreateScratch extends SfCommand<Foo> {
public static readonly args = 'foo';
public static readonly varargs = 'foo';
public static ok = true;
}`,
output: `
Expand All @@ -59,12 +59,12 @@ export default class EnvCreateScratch extends SfCommand<Foo> {
filename: path.normalize('src/commands/foo.ts'),
errors: [
{ messageId: 'property', data: { property: 'varargs' } },
{ messageId: 'property', data: { property: 'args' } },
{ messageId: 'property', data: { property: 'supportsDevhubUsername' } },
],
code: `
export default class EnvCreateScratch extends SfCommand<Foo> {
public static readonly varargs = true;
public static readonly args = true;
public static readonly supportsDevhubUsername = true;
public static readonly requiresProject = true;
}`,
output: `
Expand Down
11 changes: 11 additions & 0 deletions test/rules/no-args-parse-without-strict-false.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
const {flags, args, argv} = await this.parse(EnvCreateScratch);
}
}
`,
},
{
name: 'Not sf command dir',
filename: path.normalize('src/commands/foo.ts'),
code: `
export default class EnvCreateScratch extends SomethingElse<ScratchCreateResponse> {
public async run(): Promise<ScratchCreateResponse> {
const {flags, args, argv} = await this.parse(EnvCreateScratch);
}
}
`,
},
],
Expand Down

0 comments on commit 5c42964

Please sign in to comment.