Skip to content

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
Contributor

@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
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

(Sorry for the late reply. I've been very busy lately 😓)
LGTM! Thank you!

@ota-meshi ota-meshi merged commit 02890f3 into master Jul 31, 2025
12 checks passed
@ota-meshi ota-meshi deleted the feature/np-negated-condition branch July 31, 2025 03:10
@github-actions github-actions bot mentioned this pull request Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants