Skip to content

Commit

Permalink
feat: handle possible non-static flags prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 10, 2022
1 parent 2a6c99c commit 0cb2781
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/rules/flagCrossReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const flagCrossReferences = ESLintUtils.RuleCreator.withoutDocs({
.filter(Boolean);

if (
flagsNode.type === 'PropertyDefinition' &&
flagsNode?.type === 'PropertyDefinition' &&
flagsNode.key.type === 'Identifier' &&
flagsNode.value.type === 'ObjectExpression'
) {
Expand Down
8 changes: 4 additions & 4 deletions src/shared/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const isFlag = (node: TSESTree.Node): boolean =>

export const isFlagsStaticProperty = (node: TSESTree.Node): boolean =>
node.type === AST_NODE_TYPES.PropertyDefinition &&
node.value.type === AST_NODE_TYPES.ObjectExpression &&
node.static &&
node.value?.type === AST_NODE_TYPES.ObjectExpression &&
node.key.type === AST_NODE_TYPES.Identifier &&
node.key?.name === 'flags' &&
node.accessibility === 'public' &&
node.static;
node.key.name === 'flags' &&
node.accessibility === 'public';
12 changes: 12 additions & 0 deletions test/rules/flagCrossReferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
'some-literal': Flags.string({}),
}
}
`,
// non static other definition of flags
`
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static flags = {
alias: Flags.string({
dependsOn: ['some-literal']
}),
'some-literal': Flags.string({}),
}
private flags: CmdFlags;
}
`,
`
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
Expand Down

0 comments on commit 0cb2781

Please sign in to comment.