Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/eslint-plugin-vue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.8.0
Choose a base ref
...
head repository: vuejs/eslint-plugin-vue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.9.0
Choose a head ref
  • 5 commits
  • 15 files changed
  • 5 contributors

Commits on Apr 12, 2021

  1. feat(max-attributes-per-line): singleline.allowFirstLine option (#1465)

    * feat(max-attributes-per-line): allow max attribues 0 for singleline
    
    * feat(max-attributes-per-line): allowFirstLine option
    
    * docs(max-attributes-per-line): updated options and added example
    privatenumber authored Apr 12, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8bdb2a9 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    26d9920 View commit details
  3. New: Add vue/no-invalid-model-keys rule (#1466)

    * added no-invalid-model-keys rule
    
    * added no-invalid-model-keys to rules list
    
    * added no-invalid-model-keys tests
    
    * removed unused
    
    * added docs for no-invalid-model-keys
    
    * Update docs/rules/no-invalid-model-keys.md
    
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    
    * Update docs/rules/no-invalid-model-keys.md
    
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    
    * Update docs/rules/no-invalid-model-keys.md
    
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    
    * Update docs/rules/no-invalid-model-keys.md
    
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    
    * Update lib/rules/no-invalid-model-keys.js
    
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    
    * Update lib/rules/no-invalid-model-keys.js
    
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    
    * Update docs/rules/no-invalid-model-keys.md
    
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    
    * Update no-invalid-model-keys.md
    
    * Update no-invalid-model-keys.js
    
    * Update no-invalid-model-keys.js
    
    * Update no-invalid-model-keys.js
    
    * Update no-invalid-model-keys.js
    
    Co-authored-by: Alex Sokolov <4497128+Alex-Sokolov@users.noreply.github.com>
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    3 people authored Apr 12, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    084bfe3 View commit details
  4. Add vue/no-unused-refs rule (#1474)

    * Add `vue/no-unused-refs` rule
    
    * update doc
    ota-meshi authored Apr 12, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    238de1b View commit details
  5. 7.9.0

    ota-meshi committed Apr 12, 2021
    Copy the full SHA
    01d1e45 View commit details
4 changes: 3 additions & 1 deletion docs/rules/README.md
Original file line number Diff line number Diff line change
@@ -300,6 +300,7 @@ For example:
| [vue/no-boolean-default](./no-boolean-default.md) | disallow boolean defaults | :wrench: |
| [vue/no-duplicate-attr-inheritance](./no-duplicate-attr-inheritance.md) | enforce `inheritAttrs` to be set to `false` when using `v-bind="$attrs"` | |
| [vue/no-empty-component-block](./no-empty-component-block.md) | disallow the `<template>` `<script>` `<style>` block to be empty | |
| [vue/no-invalid-model-keys](./no-invalid-model-keys.md) | require valid keys in model option | |
| [vue/no-multiple-objects-in-class](./no-multiple-objects-in-class.md) | disallow to pass multiple objects into array to class | |
| [vue/no-potential-component-option-typo](./no-potential-component-option-typo.md) | disallow a potential typo in your component property | |
| [vue/no-reserved-component-names](./no-reserved-component-names.md) | disallow the use of reserved names in component definitions | |
@@ -315,6 +316,7 @@ For example:
| [vue/no-unregistered-components](./no-unregistered-components.md) | disallow using components that are not registered inside templates | |
| [vue/no-unsupported-features](./no-unsupported-features.md) | disallow unsupported Vue.js syntax on the specified version | :wrench: |
| [vue/no-unused-properties](./no-unused-properties.md) | disallow unused properties | |
| [vue/no-unused-refs](./no-unused-refs.md) | disallow unused refs | |
| [vue/no-useless-mustaches](./no-useless-mustaches.md) | disallow unnecessary mustache interpolations | :wrench: |
| [vue/no-useless-v-bind](./no-useless-v-bind.md) | disallow unnecessary `v-bind` directives | :wrench: |
| [vue/padding-line-between-blocks](./padding-line-between-blocks.md) | require or disallow padding lines between blocks | :wrench: |
@@ -357,7 +359,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
| [vue/no-restricted-syntax](./no-restricted-syntax.md) | disallow specified syntax | |
| [vue/no-sparse-arrays](./no-sparse-arrays.md) | disallow sparse arrays | |
| [vue/no-useless-concat](./no-useless-concat.md) | disallow unnecessary concatenation of literals or template literals | |
| [vue/object-curly-newline](./object-curly-newline.md) | enforce consistent line breaks inside braces | :wrench: |
| [vue/object-curly-newline](./object-curly-newline.md) | enforce consistent line breaks after opening and before closing braces | :wrench: |
| [vue/object-curly-spacing](./object-curly-spacing.md) | enforce consistent spacing inside braces | :wrench: |
| [vue/object-property-newline](./object-property-newline.md) | enforce placing object properties on separate lines | :wrench: |
| [vue/operator-linebreak](./operator-linebreak.md) | enforce consistent linebreak style for operators | :wrench: |
26 changes: 24 additions & 2 deletions docs/rules/max-attributes-per-line.md
Original file line number Diff line number Diff line change
@@ -57,7 +57,10 @@ There is a configurable number of attributes that are acceptable in one-line cas
```json
{
"vue/max-attributes-per-line": ["error", {
"singleline": 1,
"singleline": {
"max": 1,
"allowFirstLine": true
},
"multiline": {
"max": 1,
"allowFirstLine": false
@@ -66,7 +69,8 @@ There is a configurable number of attributes that are acceptable in one-line cas
}
```

- `singleline` (`number`) ... The number of maximum attributes per line when the opening tag is in a single line. Default is `1`.
- `singleline.max` (`number`) ... The number of maximum attributes per line when the opening tag is in a single line. Default is `1`.
- `singleline.allowFirstLine` (`boolean`) ... If `true`, it allows attributes on the same line as that tag name. Default is `true`.
- `multiline.max` (`number`) ... The max number of attributes per line when the opening tag is in multiple lines. Default is `1`. This can be `{ multiline: 1 }` instead of `{ multiline: { max: 1 }}` if you don't configure `allowFirstLine` property.
- `multiline.allowFirstLine` (`boolean`) ... If `true`, it allows attributes on the same line as that tag name. Default is `false`.

@@ -86,6 +90,24 @@ There is a configurable number of attributes that are acceptable in one-line cas

</eslint-code-block>

### `"singleline": 1, "allowFirstLine": false`

<eslint-code-block fix :rules="{'vue/max-attributes-per-line': ['error', {singleline: { allowFirstLine: false }}]}">

```vue
<template>
<!-- ✓ GOOD -->
<MyComponent
lorem="1"
/>
<!-- ✗ BAD -->
<MyComponent lorem="1" />
</template>
```

</eslint-code-block>

### `"multiline": 2`

<eslint-code-block fix :rules="{'vue/max-attributes-per-line': ['error', {multiline: 2}]}">
119 changes: 119 additions & 0 deletions docs/rules/no-invalid-model-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/no-invalid-model-keys
description: require valid keys in model option
since: v7.9.0
---
# vue/no-invalid-model-keys

> require valid keys in model option
## :book: Rule Details

This rule is aimed at preventing invalid keys in model option.

<eslint-code-block :rules="{'vue/no-invalid-model-keys': ['error']}">

```vue
<script>
/* ✓ GOOD */
export default {
model: {
prop: 'list',
}
}
</script>
```

</eslint-code-block>

<eslint-code-block :rules="{'vue/no-invalid-model-keys': ['error']}">

```vue
<script>
/* ✓ GOOD */
export default {
model: {
event: 'update'
}
}
</script>
```

</eslint-code-block>

<eslint-code-block :rules="{'vue/no-invalid-model-keys': ['error']}">

```vue
<script>
/* ✓ GOOD */
export default {
model: {
prop: 'list',
event: 'update'
}
}
</script>
```

</eslint-code-block>

<eslint-code-block :rules="{'vue/no-invalid-model-keys': ['error']}">

```vue
<script>
/* ✗ BAD */
export default {
model: {
prop: 'list',
events: 'update'
}
}
</script>
```

</eslint-code-block>

<eslint-code-block :rules="{'vue/no-invalid-model-keys': ['error']}">

```vue
<script>
/* ✗ BAD */
export default {
model: {
props: 'list',
events: 'update'
}
}
</script>
```

</eslint-code-block>

<eslint-code-block :rules="{'vue/no-invalid-model-keys': ['error']}">

```vue
<script>
/* ✗ BAD */
export default {
model: {
name: 'checked',
props: 'list',
event: 'update'
}
}
</script>
```

</eslint-code-block>


## :rocket: Version

This rule was introduced in eslint-plugin-vue v7.9.0

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-invalid-model-keys.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-invalid-model-keys.js)
53 changes: 53 additions & 0 deletions docs/rules/no-unused-refs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/no-unused-refs
description: disallow unused refs
since: v7.9.0
---
# vue/no-unused-refs

> disallow unused refs
## :book: Rule Details

This rule is aimed at eliminating unused refs.
This rule reports refs that are defined using the `ref` attribute in `<template>` but are not used via `$refs`.

::: warning Note
This rule cannot be checked for use in other components (e.g. `mixins`, Access via `$refs.x.$refs`).
:::

<eslint-code-block :rules="{'vue/no-unused-refs': ['error']}">

```vue
<template>
<!-- ✓ GOOD -->
<input ref="foo" />
<!-- ✗ BAD (`bar` is not used) -->
<input ref="bar" />
</template>
<script>
export default {
mounted() {
this.$refs.foo.value = 'foo'
}
}
</script>
```

</eslint-code-block>

## :wrench: Options

Nothing.

## :rocket: Version

This rule was introduced in eslint-plugin-vue v7.9.0

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-unused-refs.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-unused-refs.js)
4 changes: 2 additions & 2 deletions docs/rules/object-curly-newline.md
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@
pageClass: rule-details
sidebarDepth: 0
title: vue/object-curly-newline
description: enforce consistent line breaks inside braces
description: enforce consistent line breaks after opening and before closing braces
since: v7.0.0
---
# vue/object-curly-newline

> enforce consistent line breaks inside braces
> enforce consistent line breaks after opening and before closing braces
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.

2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ module.exports = {
'no-empty-component-block': require('./rules/no-empty-component-block'),
'no-empty-pattern': require('./rules/no-empty-pattern'),
'no-extra-parens': require('./rules/no-extra-parens'),
'no-invalid-model-keys': require('./rules/no-invalid-model-keys'),
'no-irregular-whitespace': require('./rules/no-irregular-whitespace'),
'no-lifecycle-after-await': require('./rules/no-lifecycle-after-await'),
'no-lone-template': require('./rules/no-lone-template'),
@@ -116,6 +117,7 @@ module.exports = {
'no-unsupported-features': require('./rules/no-unsupported-features'),
'no-unused-components': require('./rules/no-unused-components'),
'no-unused-properties': require('./rules/no-unused-properties'),
'no-unused-refs': require('./rules/no-unused-refs'),
'no-unused-vars': require('./rules/no-unused-vars'),
'no-use-v-if-with-v-for': require('./rules/no-use-v-if-with-v-for'),
'no-useless-concat': require('./rules/no-useless-concat'),
45 changes: 32 additions & 13 deletions lib/rules/max-attributes-per-line.js
Original file line number Diff line number Diff line change
@@ -34,6 +34,9 @@ module.exports = {
max: {
type: 'number',
minimum: 1
},
allowFirstLine: {
type: 'boolean'
}
},
additionalProperties: false
@@ -72,7 +75,8 @@ module.exports = {
const configuration = parseOptions(context.options[0])
const multilineMaximum = configuration.multiline
const singlelinemMaximum = configuration.singleline
const canHaveFirstLine = configuration.allowFirstLine
const canHaveSinglelineFirstLine = configuration.singlelineAllowFirstLine
const canHaveMultilineFirstLine = configuration.multilineAllowFirstLine
const template =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
@@ -83,16 +87,22 @@ module.exports = {

if (!numberOfAttributes) return

if (
utils.isSingleLine(node) &&
numberOfAttributes > singlelinemMaximum
) {
showErrors(node.attributes.slice(singlelinemMaximum))
if (utils.isSingleLine(node)) {
if (
!canHaveSinglelineFirstLine &&
node.attributes[0].loc.start.line === node.loc.start.line
) {
showErrors([node.attributes[0]])
}

if (numberOfAttributes > singlelinemMaximum) {
showErrors(node.attributes.slice(singlelinemMaximum))
}
}

if (!utils.isSingleLine(node)) {
if (
!canHaveFirstLine &&
!canHaveMultilineFirstLine &&
node.attributes[0].loc.start.line === node.loc.start.line
) {
showErrors([node.attributes[0]])
@@ -114,27 +124,36 @@ module.exports = {
function parseOptions(options) {
const defaults = {
singleline: 1,
singlelineAllowFirstLine: true,
multiline: 1,
allowFirstLine: false
multilineAllowFirstLine: false
}

if (options) {
if (typeof options.singleline === 'number') {
defaults.singleline = options.singleline
} else if (options.singleline && options.singleline.max) {
defaults.singleline = options.singleline.max
} else if (typeof options.singleline === 'object') {
if (typeof options.singleline.max === 'number') {
defaults.singleline = options.singleline.max
}

if (typeof options.singleline.allowFirstLine === 'boolean') {
defaults.singlelineAllowFirstLine =
options.singleline.allowFirstLine
}
}

if (options.multiline) {
if (typeof options.multiline === 'number') {
defaults.multiline = options.multiline
} else if (typeof options.multiline === 'object') {
if (options.multiline.max) {
if (typeof options.multiline.max === 'number') {
defaults.multiline = options.multiline.max
}

if (options.multiline.allowFirstLine) {
defaults.allowFirstLine = options.multiline.allowFirstLine
if (typeof options.multiline.allowFirstLine === 'boolean') {
defaults.multilineAllowFirstLine =
options.multiline.allowFirstLine
}
}
}
Loading