Skip to content

Commit c0ebec0

Browse files
authored
Merge branch 'master' into prefer-template-ref/auto-fix
2 parents c6feec2 + 4b4630b commit c0ebec0

33 files changed

+1036
-1245
lines changed

.changeset/gorgeous-colts-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue": patch
3+
---
4+
5+
Updates resources

.changeset/rich-zebras-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue": minor
3+
---
4+
5+
Changed `vue/no-negated-v-if-condition` suggestion to autofix

docs/rules/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ For example:
238238
| [vue/no-empty-component-block] | disallow the `<template>` `<script>` `<style>` block to be empty | :wrench: | :hammer: |
239239
| [vue/no-import-compiler-macros] | disallow importing Vue compiler macros | :wrench: | :warning: |
240240
| [vue/no-multiple-objects-in-class] | disallow passing multiple objects in an array to class | | :hammer: |
241-
| [vue/no-negated-v-if-condition] | disallow negated conditions in v-if/v-else | :bulb: | :hammer: |
241+
| [vue/no-negated-v-if-condition] | disallow negated conditions in v-if/v-else | :wrench: | :hammer: |
242242
| [vue/no-potential-component-option-typo] | disallow a potential typo in your component property | :bulb: | :hammer: |
243243
| [vue/no-ref-object-reactivity-loss] | disallow usages of ref objects that can lead to loss of reactivity | | :warning: |
244244
| [vue/no-restricted-block] | disallow specific block | | :hammer: |

docs/rules/no-negated-v-if-condition.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ since: v10.4.0
1010

1111
> disallow negated conditions in v-if/v-else
1212
13-
- :bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
13+
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fix-problems) can automatically fix some of the problems reported by this rule.
1414

1515
## :book: Rule Details
1616

1717
This rule disallows negated conditions in `v-if` and `v-else-if` directives which have an `v-else` branch.
1818

1919
Negated conditions make the code less readable. When there's an `else` clause, it's better to use a positive condition and switch the branches.
2020

21-
<eslint-code-block :rules="{'vue/no-negated-v-if-condition': ['error']}">
21+
<eslint-code-block fix :rules="{'vue/no-negated-v-if-condition': ['error']}">
2222

2323
```vue
2424
<template>

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export default typegen([
275275
'@typescript-eslint/no-explicit-any': 'off',
276276
'@typescript-eslint/no-empty-object-type': 'off',
277277
'@typescript-eslint/no-namespace': 'off',
278+
'@typescript-eslint/no-non-null-assertion': 'off',
278279
'@typescript-eslint/triple-slash-reference': 'off',
279280
'@typescript-eslint/unified-signatures': 'off',
280281
'@typescript-eslint/ban-ts-comment': [

lib/configs/flat/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = [
88
name: 'vue/base/setup',
99
plugins: {
1010
get vue() {
11-
return require('../../index')
11+
return require('../../plugin')
1212
}
1313
},
1414
languageOptions: {
@@ -20,7 +20,7 @@ module.exports = [
2020
files: ['*.vue', '**/*.vue'],
2121
plugins: {
2222
get vue() {
23-
return require('../../index')
23+
return require('../../plugin')
2424
}
2525
},
2626
languageOptions: {

lib/configs/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const configs = {
2+
// eslintrc configs
3+
base: require('./base'),
4+
5+
'vue2-essential': require('./vue2-essential'),
6+
'vue2-strongly-recommended': require('./vue2-strongly-recommended'),
7+
'vue2-recommended': require('./vue2-recommended'),
8+
9+
essential: require('./vue3-essential'),
10+
'strongly-recommended': require('./vue3-strongly-recommended'),
11+
recommended: require('./vue3-recommended'),
12+
13+
// flat configs
14+
'flat/base': require('./flat/base.js'),
15+
16+
'flat/vue2-essential': require('./flat/vue2-essential.js'),
17+
'flat/vue2-strongly-recommended': require('./flat/vue2-strongly-recommended.js'),
18+
'flat/vue2-recommended': require('./flat/vue2-recommended.js'),
19+
20+
'flat/essential': require('./flat/vue3-essential.js'),
21+
'flat/strongly-recommended': require('./flat/vue3-strongly-recommended.js'),
22+
'flat/recommended': require('./flat/vue3-recommended.js'),
23+
24+
// config-format-agnostic configs
25+
'no-layout-rules': require('./no-layout-rules')
26+
}
27+
28+
module.exports = configs

lib/index.js

Lines changed: 3 additions & 289 deletions
Large diffs are not rendered by default.

lib/plugin.js

Lines changed: 266 additions & 0 deletions
Large diffs are not rendered by default.

lib/rules/no-negated-v-if-condition.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,10 @@ module.exports = {
7676
categories: undefined,
7777
url: 'https://eslint.vuejs.org/rules/no-negated-v-if-condition.html'
7878
},
79-
fixable: null,
80-
hasSuggestions: true,
79+
fixable: 'code',
8180
schema: [],
8281
messages: {
83-
negatedCondition: 'Unexpected negated condition in v-if with v-else.',
84-
fixNegatedCondition:
85-
'Convert to positive condition and swap if/else blocks.'
82+
negatedCondition: 'Unexpected negated condition in v-if with v-else.'
8683
}
8784
},
8885
/** @param {RuleContext} context */
@@ -152,14 +149,7 @@ module.exports = {
152149
context.report({
153150
node: expression,
154151
messageId: 'negatedCondition',
155-
suggest: [
156-
{
157-
messageId: 'fixNegatedCondition',
158-
*fix(fixer) {
159-
yield* swapElements(fixer, element, elseElement, expression)
160-
}
161-
}
162-
]
152+
fix: (fixer) => swapElements(fixer, element, elseElement, expression)
163153
})
164154
}
165155

0 commit comments

Comments
 (0)