-
Notifications
You must be signed in to change notification settings - Fork 887
[unnecessary-else] Allowed skipping else if
statements via options
#4599
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting started so quickly on this @timocov! Just a couple of touchups.
@JoshuaKGoldberg I've resolved conflicts and pushed requested changes. Can you take a look please? |
hi @timocov for future PRs, can you please push additional commits instead of amending and force-pushing? we squash commits at the end of PRs, so this workflow makes it easier to review incremental changes. |
Hi @adidahiya. My apologies about that. Sure! If you wish I can re-push with old state and added merge commit instead of rebase. Just give some time :) |
@adidahiya I have a state with old commits and ready to re-push it. Is it ok? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule logic looks great! Just a couple of touchups around the options.
src/rules/unnecessaryElseRule.ts
Outdated
}, | ||
}, | ||
optionsDescription: Lint.Utils.dedent` | ||
You can optionally specify the option \`"allowElseIf"\` to allow "else if" statements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`"allowElseIf"`
Rules typically create an all-caps const
for these option names to reduce the chance of mispelling them anywhere. For example, curlyRule.ts
declares OPTION_AS_NEEDED
and OPTION_IGNORE_SAME_LINE
. Let's switch to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 03b2414
src/rules/unnecessaryElseRule.ts
Outdated
optionExamples: [true], | ||
options: null, | ||
optionsDescription: "Not configurable.", | ||
optionExamples: [true, [true, { allowElseIf: true }]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allowElseIf
TSLint rules use dash-case, so this should be allow-else-if
. For example, noAnyRule.ts
has const OPTION_IGNORE_REST_ARGS = "ignore-rest-args";
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 03b2414
@JoshuaKGoldberg it looks like failed test fails and on master too and doesn't related to the PR. |
PR checklist
Overview of change:
Added option
allowElseIf
forunnecessary-else
rule to skip checkingelse if
statements (onlyelse
).CHANGELOG.md entry:
[new-rule-option]
allow-else-if
option forunnecessary-else
rule