Skip to content

Commit

Permalink
fix: handle more potential nulls (#138)
Browse files Browse the repository at this point in the history
* fix: handle more potential nulls

* refactor: check node.value at top level

* refactor: remove redundant optional

* test: ut for static props with no value
  • Loading branch information
mshanemc authored Jan 12, 2023
1 parent 922aa2f commit 4a36418
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/rules/no-unnecessary-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export const noUnnecessaryProperties = ESLintUtils.RuleCreator.withoutDocs({
PropertyDefinition(node): void {
if (
node.static &&
node.key.type === AST_NODE_TYPES.Identifier &&
node.parent.type === AST_NODE_TYPES.ClassBody &&
node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration &&
node.key?.type === AST_NODE_TYPES.Identifier &&
node.parent?.type === AST_NODE_TYPES.ClassBody &&
node.parent.parent?.type === AST_NODE_TYPES.ClassDeclaration &&
node.value &&
extendsSfCommand(node.parent.parent)
) {
// properties that default to false
Expand Down
8 changes: 8 additions & 0 deletions test/rules/no-uneccessary-properties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static requiresProject = true
public static notInTargetList = false
}
`,
},
{
name: 'other static properties with no value',
code: `
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static org: Org
}
`,
},
{
Expand Down

0 comments on commit 4a36418

Please sign in to comment.