Skip to content

Add vue/no-negated-v-if-condition rule #2794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

waynzh
Copy link
Member

@waynzh waynzh commented Jul 14, 2025

related #2769

Found that the check and fix logic for ternaries is quite different. So, I extract v-if condition into a separate rule.

I’ll submit a follow-up PR later to implement vue/no-negated-condition as an extension of the no-negated-condition.

Update: #2795

@waynzh waynzh requested a review from Copilot July 14, 2025 03:12
Copy link

changeset-bot bot commented Jul 14, 2025

🦋 Changeset detected

Latest commit: fa09bb8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-vue Minor

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

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-condition or another relevant rule instead of duplicating itself.
- [no-negated-v-if-condition](https://eslint.org/docs/rules/no-negated-v-if-condition)

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool, thank you! I have just one minor code style nitpick, the rest looks good to me 🙂

@FloEdelmann FloEdelmann requested a review from ota-meshi July 15, 2025 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule suggestion: vue/no-negated-condition for v-if/v-else in the template
2 participants