Skip to content

Commit dbfe89c

Browse files
committed
accept suggestions
1 parent 62119d5 commit dbfe89c

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

docs/rules/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ For example:
353353
| [vue/no-v-text](./no-v-text.md) | disallow use of v-text | |
354354
| [vue/padding-line-between-blocks](./padding-line-between-blocks.md) | require or disallow padding lines between blocks | :wrench: |
355355
| [vue/prefer-separate-static-class](./prefer-separate-static-class.md) | require static class names in template to be in a separate `class` attribute | :wrench: |
356-
| [vue/prefer-true-attribute-shorthand](./prefer-true-attribute-shorthand.md) | require shorthand form attribute when `v-bind` value is `true`. | :bulb: |
356+
| [vue/prefer-true-attribute-shorthand](./prefer-true-attribute-shorthand.md) | require shorthand form attribute when `v-bind` value is `true` | :bulb: |
357357
| [vue/require-direct-export](./require-direct-export.md) | require the component to be directly exported | |
358358
| [vue/require-emit-validator](./require-emit-validator.md) | require type definitions in emits | :bulb: |
359359
| [vue/require-expose](./require-expose.md) | require declare public properties using `expose` | :bulb: |

docs/rules/prefer-true-attribute-shorthand.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
pageClass: rule-details
33
sidebarDepth: 0
44
title: vue/prefer-true-attribute-shorthand
5-
description: require shorthand form attribute when `v-bind` value is `true`.
5+
description: require shorthand form attribute when `v-bind` value is `true`
66
---
77
# vue/prefer-true-attribute-shorthand
88

9-
> require shorthand form attribute when `v-bind` value is `true`.
9+
> require shorthand form attribute when `v-bind` value is `true`
1010
1111
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
1212
- :bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
@@ -31,32 +31,48 @@ description: require shorthand form attribute when `v-bind` value is `true`.
3131

3232
</eslint-code-block>
3333

34-
However, those two representations are not always equivalent.
35-
This case will be occurred if the definition of a prop includes `String`:
34+
::: warning Warning
35+
The shorthand form is not always equivalent! If a prop accepts multiple types, but Boolean is not the first one, a shorthand prop won't pass `true`.
36+
:::
3637

3738
```vue
38-
<template>
39-
<pre>{{ prop }}</pre>
40-
</template>
41-
4239
<script>
4340
export default {
4441
name: 'MyComponent',
4542
props: {
46-
prop: [String, Boolean]
43+
bool: Boolean,
44+
boolOrString: [Boolean, String],
45+
stringOrBool: [String, Boolean],
4746
}
4847
}
4948
</script>
5049
```
5150

51+
**Shorthand form:**
52+
5253
```vue
53-
<template>
54-
<MyComponent prop />
55-
<MyComponent :prop="true"/>
56-
</template>
54+
<MyComponent bool bool-or-string string-or-bool />
55+
```
56+
57+
```
58+
bool: true (boolean)
59+
boolOrString: true (boolean)
60+
stringOrBool: "" (string)
61+
```
62+
63+
**Longhand form:**
64+
65+
```vue
66+
<MyComponent :bool="true" :bool-or-string="true" :string-or-bool="true" />
67+
```
68+
69+
```
70+
bool: true (boolean)
71+
boolOrString: true (boolean)
72+
stringOrBool: true (boolean)
5773
```
5874

59-
Those two calls will introduce different render result. See [this demo](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdCBzZXR1cD5cbmltcG9ydCBNeUNvbXBvbmVudCBmcm9tICcuL015Q29tcG9uZW50LnZ1ZSdcbjwvc2NyaXB0PlxuXG48dGVtcGxhdGU+XG4gIDxNeUNvbXBvbmVudCBhIGIvPlxuICA8TXlDb21wb25lbnQgOmE9XCJ0cnVlXCIgOmI9XCJ0cnVlXCIvPlxuPC90ZW1wbGF0ZT4iLCJpbXBvcnQtbWFwLmpzb24iOiJ7XG4gIFwiaW1wb3J0c1wiOiB7XG4gICAgXCJ2dWVcIjogXCJodHRwczovL3NmYy52dWVqcy5vcmcvdnVlLnJ1bnRpbWUuZXNtLWJyb3dzZXIuanNcIlxuICB9XG59IiwiTXlDb21wb25lbnQudnVlIjoiPHNjcmlwdD5cbmV4cG9ydCBkZWZhdWx0IHtcbiAgcHJvcHM6IHtcbiAgICBhOiBCb29sZWFuLFxuICAgIGI6IFtTdHJpbmcsIEJvb2xlYW5dXG4gIH1cbn1cbjwvc2NyaXB0PlxuXG48dGVtcGxhdGU+XG4gIDxwcmU+XG5hOiB7e2F9fVxuYjoge3tifX1cbiAgPC9wcmU+XG48L3RlbXBsYXRlPiJ9).
75+
Those two calls will introduce different render result. See [this demo](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdCBzZXR1cD5cbmltcG9ydCBNeUNvbXBvbmVudCBmcm9tICcuL015Q29tcG9uZW50LnZ1ZSdcbjwvc2NyaXB0PlxuXG48dGVtcGxhdGU+XG4gIFNob3J0aGFuZCBmb3JtOlxuICA8TXlDb21wb25lbnQgYm9vbCBib29sLW9yLXN0cmluZyBzdHJpbmctb3ItYm9vbCAvPlxuICBcbiAgTG9uZ2hhbmQgZm9ybTpcbiAgPE15Q29tcG9uZW50IDpib29sPVwidHJ1ZVwiIDpib29sLW9yLXN0cmluZz1cInRydWVcIiA6c3RyaW5nLW9yLWJvb2w9XCJ0cnVlXCIgLz5cbjwvdGVtcGxhdGU+IiwiaW1wb3J0LW1hcC5qc29uIjoie1xuICBcImltcG9ydHNcIjoge1xuICAgIFwidnVlXCI6IFwiaHR0cHM6Ly9zZmMudnVlanMub3JnL3Z1ZS5ydW50aW1lLmVzbS1icm93c2VyLmpzXCJcbiAgfVxufSIsIk15Q29tcG9uZW50LnZ1ZSI6IjxzY3JpcHQ+XG5leHBvcnQgZGVmYXVsdCB7XG4gIHByb3BzOiB7XG4gICAgYm9vbDogQm9vbGVhbixcbiAgICBib29sT3JTdHJpbmc6IFtCb29sZWFuLCBTdHJpbmddLFxuICAgIHN0cmluZ09yQm9vbDogW1N0cmluZywgQm9vbGVhbl0sXG4gIH1cbn1cbjwvc2NyaXB0PlxuXG48dGVtcGxhdGU+XG4gIDxwcmU+XG5ib29sOiB7e2Jvb2x9fSAoe3sgdHlwZW9mIGJvb2wgfX0pXG5ib29sT3JTdHJpbmc6IHt7Ym9vbE9yU3RyaW5nfX0gKHt7IHR5cGVvZiBib29sT3JTdHJpbmcgfX0pXG5zdHJpbmdPckJvb2w6IHt7c3RyaW5nT3JCb29sfX0gKHt7IHR5cGVvZiBzdHJpbmdPckJvb2wgfX0pXG4gIDwvcHJlPlxuPC90ZW1wbGF0ZT4ifQ==).
6076

6177
## :wrench: Options
6278

lib/rules/prefer-true-attribute-shorthand.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const utils = require('../utils')
1616

1717
module.exports = {
1818
meta: {
19-
type: 'problem',
19+
type: 'suggestion',
2020
docs: {
2121
description:
22-
'require shorthand form attribute when `v-bind` value is `true`.',
22+
'require shorthand form attribute when `v-bind` value is `true`',
2323
categories: undefined,
2424
url: 'https://eslint.vuejs.org/rules/prefer-true-attribute-shorthand.html'
2525
},
@@ -34,8 +34,6 @@ module.exports = {
3434
},
3535
/** @param {RuleContext} context */
3636
create(context) {
37-
// ...
38-
3937
return utils.defineTemplateBodyVisitor(context, {
4038
/** @param {VDirective} node */
4139
"VAttribute[directive=true][key.name.name='bind']"(node) {

0 commit comments

Comments
 (0)