Add vue/no-negated-v-if-condition rule#2794
Conversation
🦋 Changeset detectedLatest commit: fa09bb8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull Request Overview
Introduces a new ESLint rule vue/no-negated-v-if-condition to prohibit negated conditions in v-if/v-else(-if) when there’s an else branch, with auto-suggestion to invert and swap blocks.
- Add rule implementation with detection and fix suggestions
- Add comprehensive tests covering valid/invalid scenarios
- Register rule in plugin and document it
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/lib/rules/no-negated-v-if-condition.js | New test suite covering valid/invalid cases |
| lib/rules/no-negated-v-if-condition.js | Rule logic, detection of negated conditions, fix suggestion generators |
| lib/index.js | Plugin registration for the new rule |
| docs/rules/no-negated-v-if-condition.md | Rule documentation with examples |
| docs/rules/index.md | Added rule entry to the rules index |
Comments suppressed due to low confidence (1)
docs/rules/no-negated-v-if-condition.md:57
- [nitpick] In the Related Rules section, this rule currently links to itself. Consider updating it to reference the core ESLint rule
no-negated-conditionor another relevant rule instead of duplicating itself.
- [no-negated-v-if-condition](https://eslint.org/docs/rules/no-negated-v-if-condition)
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
…ure/np-negated-condition
FloEdelmann
left a comment
There was a problem hiding this comment.
Really cool, thank you! I have just one minor code style nitpick, the rest looks good to me 🙂
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
ota-meshi
left a comment
There was a problem hiding this comment.
(Sorry for the late reply. I've been very busy lately 😓)
LGTM! Thank you!
related #2769
Found that the check and fix logic for ternaries is quite different. So, I extract
v-ifcondition into a separate rule.I’ll submit a follow-up PR later to implement
vue/no-negated-conditionas an extension of theno-negated-condition.Update: #2795