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: v5.0.0-beta.2
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: v5.0.0-beta.3
Choose a head ref
  • 8 commits
  • 79 files changed
  • 2 contributors

Commits on Aug 13, 2018

  1. (implements #414) Add "no-unused-components" rule (#545)

    * Add "no-unused-components" rule
    
    * Handle case with Literal in :is binding expression, update docs
    
    * Update no-unused-components.md
    michalsnik authored Aug 13, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8673fc3 View commit details
  2. (implements #323) Add require-prop-type-constructor rule (#546)

    * Add no-string-prop-type rule - basic implementation
    
    * Rename rule
    
    * Add more tests, update docs
    michalsnik authored Aug 13, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    47cc8d3 View commit details
  3. Copy the full SHA
    ab624da View commit details
  4. ⭐️New: Add vue/no-spaces-around-equal-signs-in-attribute (#542)

    * Add `vue/no-spaces-around-equal-signs-in-attribute` rule
    
    * Add check that error message location is correct.
    
    * Fix rule URL
    ota-meshi authored and michalsnik committed Aug 13, 2018
    Copy the full SHA
    bf7c2b7 View commit details
  5. [New] Add vue/multiline-html-element-content-newline rule (#551)

    * [New] Add `vue/multiline-html-element-content-newline` rule
    
    * Update `ignoreNames` -> `ignores` and report messages
    ota-meshi authored and michalsnik committed Aug 13, 2018
    Copy the full SHA
    e53bfd3 View commit details
  6. Update script-indent.md

    michalsnik authored Aug 13, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a7d0b3c View commit details
  7. [New] Add vue/singleline-html-element-content-newline rule (#552)

    * [New] Add `vue/singleline-html-element-content-newline` rule
    
    * Update `strict` -> `ignoreWhenNoAttributes`, `ignoreNames` -> `ignores` and report messages
    ota-meshi authored and michalsnik committed Aug 13, 2018
    Copy the full SHA
    cae7d51 View commit details

Commits on Aug 14, 2018

  1. 5.0.0-beta.3

    michalsnik committed Aug 14, 2018
    Copy the full SHA
    3f5d41e View commit details
Showing with 2,759 additions and 69 deletions.
  1. +5 −0 README.md
  2. +87 −0 docs/rules/multiline-html-element-content-newline.md
  3. +25 −0 docs/rules/no-spaces-around-equal-signs-in-attribute.md
  4. +67 −0 docs/rules/no-unused-components.md
  5. +61 −0 docs/rules/require-prop-type-constructor.md
  6. +18 −0 docs/rules/script-indent.md
  7. +101 −0 docs/rules/singleline-html-element-content-newline.md
  8. +2 −0 lib/configs/essential.js
  9. +5 −0 lib/index.js
  10. +1 −1 lib/rules/attribute-hyphenation.js
  11. +1 −1 lib/rules/attributes-order.js
  12. +1 −1 lib/rules/comment-directive.js
  13. +1 −1 lib/rules/component-name-in-template-casing.js
  14. +1 −1 lib/rules/html-closing-bracket-newline.js
  15. +1 −1 lib/rules/html-closing-bracket-spacing.js
  16. +1 −1 lib/rules/html-end-tags.js
  17. +1 −1 lib/rules/html-indent.js
  18. +1 −1 lib/rules/html-quotes.js
  19. +1 −1 lib/rules/html-self-closing.js
  20. +1 −1 lib/rules/jsx-uses-vars.js
  21. +1 −1 lib/rules/max-attributes-per-line.js
  22. +157 −0 lib/rules/multiline-html-element-content-newline.js
  23. +1 −1 lib/rules/mustache-interpolation-spacing.js
  24. +1 −1 lib/rules/name-property-casing.js
  25. +1 −1 lib/rules/no-async-in-computed-properties.js
  26. +1 −1 lib/rules/no-confusing-v-for-v-if.js
  27. +1 −1 lib/rules/no-dupe-keys.js
  28. +1 −1 lib/rules/no-duplicate-attributes.js
  29. +1 −1 lib/rules/no-multi-spaces.js
  30. +1 −1 lib/rules/no-parsing-error.js
  31. +1 −1 lib/rules/no-reserved-keys.js
  32. +1 −1 lib/rules/no-shared-component-data.js
  33. +1 −1 lib/rules/no-side-effects-in-computed-properties.js
  34. +54 −0 lib/rules/no-spaces-around-equal-signs-in-attribute.js
  35. +1 −1 lib/rules/no-template-key.js
  36. +1 −1 lib/rules/no-template-shadow.js
  37. +1 −1 lib/rules/no-textarea-mustache.js
  38. +91 −0 lib/rules/no-unused-components.js
  39. +1 −1 lib/rules/no-unused-vars.js
  40. +1 −1 lib/rules/no-use-v-if-with-v-for.js
  41. +1 −1 lib/rules/no-v-html.js
  42. +1 −1 lib/rules/order-in-components.js
  43. +1 −1 lib/rules/prop-name-casing.js
  44. +1 −1 lib/rules/require-component-is.js
  45. +1 −1 lib/rules/require-default-prop.js
  46. +98 −0 lib/rules/require-prop-type-constructor.js
  47. +1 −1 lib/rules/require-prop-types.js
  48. +1 −1 lib/rules/require-render-return.js
  49. +1 −1 lib/rules/require-v-for-key.js
  50. +1 −1 lib/rules/require-valid-default-prop.js
  51. +1 −1 lib/rules/return-in-computed-property.js
  52. +1 −1 lib/rules/script-indent.js
  53. +152 −0 lib/rules/singleline-html-element-content-newline.js
  54. +1 −1 lib/rules/this-in-template.js
  55. +1 −1 lib/rules/v-bind-style.js
  56. +1 −1 lib/rules/v-on-style.js
  57. +1 −1 lib/rules/valid-template-root.js
  58. +1 −1 lib/rules/valid-v-bind.js
  59. +1 −1 lib/rules/valid-v-cloak.js
  60. +1 −1 lib/rules/valid-v-else-if.js
  61. +1 −1 lib/rules/valid-v-else.js
  62. +1 −1 lib/rules/valid-v-for.js
  63. +1 −1 lib/rules/valid-v-html.js
  64. +1 −1 lib/rules/valid-v-if.js
  65. +1 −1 lib/rules/valid-v-model.js
  66. +1 −1 lib/rules/valid-v-on.js
  67. +1 −1 lib/rules/valid-v-once.js
  68. +1 −1 lib/rules/valid-v-pre.js
  69. +1 −1 lib/rules/valid-v-show.js
  70. +1 −1 lib/rules/valid-v-text.js
  71. +6 −1 lib/utils/casing.js
  72. +59 −11 lib/utils/index.js
  73. +1 −1 package.json
  74. +499 −0 tests/lib/rules/multiline-html-element-content-newline.js
  75. +234 −0 tests/lib/rules/no-spaces-around-equal-signs-in-attribute.js
  76. +369 −0 tests/lib/rules/no-unused-components.js
  77. +134 −0 tests/lib/rules/require-prop-type-constructor.js
  78. +439 −0 tests/lib/rules/singleline-html-element-content-newline.js
  79. +39 −0 tests/lib/utils/index.js
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -156,9 +156,11 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
| | [vue/no-side-effects-in-computed-properties](./docs/rules/no-side-effects-in-computed-properties.md) | disallow side effects in computed properties |
| | [vue/no-template-key](./docs/rules/no-template-key.md) | disallow `key` attribute on `<template>` |
| | [vue/no-textarea-mustache](./docs/rules/no-textarea-mustache.md) | disallow mustaches in `<textarea>` |
| | [vue/no-unused-components](./docs/rules/no-unused-components.md) | disallow registering components that are not used inside templates |
| | [vue/no-unused-vars](./docs/rules/no-unused-vars.md) | disallow unused variable definitions of v-for directives or scope attributes |
| | [vue/no-use-v-if-with-v-for](./docs/rules/no-use-v-if-with-v-for.md) | disallow use v-if on the same element as v-for |
| | [vue/require-component-is](./docs/rules/require-component-is.md) | require `v-bind:is` of `<component>` elements |
| :wrench: | [vue/require-prop-type-constructor](./docs/rules/require-prop-type-constructor.md) | require prop type to be a constructor |
| | [vue/require-render-return](./docs/rules/require-render-return.md) | enforce render function to always return value |
| | [vue/require-v-for-key](./docs/rules/require-v-for-key.md) | require `v-bind:key` with `v-for` directives |
| | [vue/require-valid-default-prop](./docs/rules/require-valid-default-prop.md) | enforce props default values to be valid |
@@ -230,7 +232,10 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
| | Rule ID | Description |
|:---|:--------|:------------|
| :wrench: | [vue/component-name-in-template-casing](./docs/rules/component-name-in-template-casing.md) | enforce specific casing for the component naming style in template |
| :wrench: | [vue/multiline-html-element-content-newline](./docs/rules/multiline-html-element-content-newline.md) | require a line break before and after the contents of a multiline element |
| :wrench: | [vue/no-spaces-around-equal-signs-in-attribute](./docs/rules/no-spaces-around-equal-signs-in-attribute.md) | disallow spaces around equal signs in attribute |
| :wrench: | [vue/script-indent](./docs/rules/script-indent.md) | enforce consistent indentation in `<script>` |
| :wrench: | [vue/singleline-html-element-content-newline](./docs/rules/singleline-html-element-content-newline.md) | require a line break before and after the contents of a singleline element |

### Deprecated

87 changes: 87 additions & 0 deletions docs/rules/multiline-html-element-content-newline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# require a line break before and after the contents of a multiline element (vue/multiline-html-element-content-newline)

- :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.

## :book: Rule Details

This rule enforces a line break before and after the contents of a multiline element.


:-1: Examples of **incorrect** code:

```html
<div>multiline
content</div>

<div
attr
>multiline start tag</div>

<tr><td>multiline</td>
<td>children</td></tr>

<div><!-- multiline
comment --></div>

<div
></div>
```

:+1: Examples of **correct** code:

```html
<div>
multiline
content
</div>

<div
attr
>
multiline start tag
</div>

<tr>
<td>multiline</td>
<td>children</td>
</tr>

<div>
<!-- multiline
comment -->
</div>

<div
>
</div>

<div attr>singleline element</div>
```


## :wrench: Options

```json
{
"vue/multiline-html-element-content-newline": ["error", {
"ignores": ["pre", "textarea"]
}]
}
```

- `ignores` ... the configuration for element names to ignore line breaks style.
default `["pre", "textarea"]`


:+1: Examples of **correct** code:

```html
/* eslint vue/multiline-html-element-content-newline: ["error", { "ignores": ["VueComponent", "pre", "textarea"]}] */

<VueComponent>multiline
content</VueComponent>

<VueComponent><span
class="bold">For example,</span>
Defines the Vue component that accepts preformatted text.</VueComponent>
```
25 changes: 25 additions & 0 deletions docs/rules/no-spaces-around-equal-signs-in-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# disallow spaces around equal signs in attribute (vue/no-spaces-around-equal-signs-in-attribute)

- :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.

This rule disallow spaces around equal signs in attribute.

HTML5 allows spaces around equal signs. But space-less is easier to read, and groups entities better together.

## :book: Rule Details

:-1: Examples of **incorrect** code for this rule:

```html
<div class = "item">
```

:+1: Examples of **correct** code for this rule:

```html
<div class="item">
```

## Further Reading

* [HTML5 Style Guide - W3Schools *Spaces and Equal Signs*](https://www.w3schools.com/html/html5_syntax.asp)
67 changes: 67 additions & 0 deletions docs/rules/no-unused-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# disallow registering components that are not used inside templates (vue/no-unused-components)

- :gear: This rule is included in all of `"plugin:vue/essential"`, `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.

This rule reports components that haven't been used in the template.

## :book: Rule Details

:-1: Examples of **incorrect** code for this rule:

```html
<template>
<div>
<h2>Lorem ipsum</h2>
<TheModal />
</div>
</template>

<script>
import TheButton from 'components/TheButton.vue'
import TheModal from 'components/TheModal.vue'
export default {
components: {
TheButton // Unused component
'the-modal': TheModal // Unused component
}
}
</script>
```

Note that components registered under other than `PascalCase` name have to be called directly under the specified name, whereas if you register it using `PascalCase` you can call it however you like, except using `snake_case`.

:+1: Examples of **correct** code for this rule:

```html
<template>
<div>
<h2>Lorem ipsum</h2>
<the-modal>
<component is="TheInput" />
<component :is="'TheDropdown'" />
<TheButton>CTA</TheButton>
</the-modal>
</div>
</template>

<script>
import TheButton from 'components/TheButton.vue'
import TheModal from 'components/TheModal.vue'
import TheInput from 'components/TheInput.vue'
import TheDropdown from 'components/TheDropdown.vue'
export default {
components: {
TheButton,
TheModal,
TheInput,
TheDropdown,
}
}
</script>
```

## :wrench: Options

Nothing.
61 changes: 61 additions & 0 deletions docs/rules/require-prop-type-constructor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# require prop type to be a constructor (vue/require-prop-type-constructor)

- :gear: This rule is included in all of `"plugin:vue/essential"`, `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
- :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.

This rule reports prop types that can't be presumed as constructors.

It's impossible to catch every possible case and know whether the prop type is a constructor or not, hence this rule black list few types of nodes, instead of white-listing correct ones.

The following types are forbidden and will be reported:

- Literal
- TemplateLiteral
- BinaryExpression
- UpdateExpression

It will catch most commonly made mistakes which are using strings instead of constructors.

## Rule Details

Examples of **incorrect** code for this rule:

```js
export default {
props: {
myProp: "Number",
anotherProp: ["Number", "String"],
myFieldWithBadType: {
type: "Object",
default: function() {
return {}
},
},
myOtherFieldWithBadType: {
type: "Number",
default: 1,
},
}
}
```

Examples of **correct** code for this rule:

```js
export default {
props: {
myProp: Number,
anotherProp: [Number, String],
myFieldWithBadType: {
type: Object,
default: function() {
return {}
},
},
myOtherFieldWithBadType: {
type: Number,
default: 1,
},
}
}
```
18 changes: 18 additions & 0 deletions docs/rules/script-indent.md
Original file line number Diff line number Diff line change
@@ -79,6 +79,24 @@ const d = {
</script>
```

## Important note

This rule only checks `.vue` files and does not interfere with other `.js` files. Unfortunately the default `indent` rule when turned on will try to lint both, so in order to make them complementary you can use `overrides` setting and disable `indent` rule on `.vue` files:

```
"rules": {
"vue/script-indent": ["error", 4, { "baseIndent": 1 }]
},
"overrides": [
{
"files": ["*.vue"],
"rules": {
"indent": "off"
}
}
]
```

## Related rules

- [indent](https://eslint.org/docs/rules/indent)
101 changes: 101 additions & 0 deletions docs/rules/singleline-html-element-content-newline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# require a line break before and after the contents of a singleline element (vue/singleline-html-element-content-newline)

- :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.

## :book: Rule Details

This rule enforces a line break before and after the contents of a singleline element.


:-1: Examples of **incorrect** code:

```html
<div attr>content</div>

<tr attr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>

<div attr><!-- comment --></div>
```

:+1: Examples of **correct** code:

```html
<div attr>
content
</div>

<tr attr>
<td>
{{ data1 }}
</td>
<td>
{{ data2 }}
</td>
</tr>

<div attr>
<!-- comment -->
</div>
```

## :wrench: Options

```json
{
"vue/singleline-html-element-content-newline": ["error", {
"ignoreWhenNoAttributes": true,
"ignores": ["pre", "textarea"]
}]
}
```

- `ignoreWhenNoAttributes` ... allows having contents in one line, when given element has no attributes.
default `true`
- `ignores` ... the configuration for element names to ignore line breaks style.
default `["pre", "textarea"]`

:-1: Examples of **incorrect** code for `{ignoreWhenNoAttributes: false}`:

```html
/* eslint vue/singleline-html-element-content-newline: ["error", { "ignoreWhenNoAttributes": false}] */

<div>content</div>

<tr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>

<div><!-- comment --></div>
```

:+1: Examples of **correct** code for `{ignoreWhenNoAttributes: true}` (default):

```html
/* eslint vue/singleline-html-element-content-newline: ["error", { "ignoreWhenNoAttributes": true}] */

<div>content</div>

<tr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>

<div><!-- comment --></div>
```

:-1: Examples of **incorrect** code for `{ignoreWhenNoAttributes: true}` (default):

```html
/* eslint vue/singleline-html-element-content-newline: ["error", { "ignoreWhenNoAttributes": true}] */

<div attr>content</div>

<tr attr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>

<div attr><!-- comment --></div>
```

:+1: Examples of **correct** code for `ignores`:

```html
/* eslint vue/singleline-html-element-content-newline: ["error", { "ignores": ["VueComponent", "pre", "textarea"]}] */

<VueComponent>content</VueComponent>

<VueComponent attr><span>content</span></VueComponent>
```
Loading