Skip to content

Commit

Permalink
New: some core rules for <template> (#680)
Browse files Browse the repository at this point in the history
* add core rule wrapper
* add `array-bracket-spacing` rule
* add `key-spacing` rule
* add `eqeqeq` rule
* add `object-curly-spacing` rule
* add `space-infix-ops` rule
* add `space-unary-ops` rule
* switch error messages for minimal version tests
  • Loading branch information
mysticatea authored and michalsnik committed Jan 5, 2019
1 parent 5dd07bf commit ebd07e6
Show file tree
Hide file tree
Showing 25 changed files with 566 additions and 13 deletions.
8 changes: 7 additions & 1 deletion docs/rules/README.md
Expand Up @@ -132,16 +132,22 @@ For example:
```json
{
"rules": {
"vue/component-name-in-template-casing": "error"
"vue/array-bracket-spacing": "error"
}
}
```

| Rule ID | Description | |
|:--------|:------------|:---|
| [vue/array-bracket-spacing](./array-bracket-spacing.md) | enforce consistent spacing inside array brackets | :wrench: |
| [vue/component-name-in-template-casing](./component-name-in-template-casing.md) | enforce specific casing for the component naming style in template | :wrench: |
| [vue/eqeqeq](./eqeqeq.md) | require the use of `===` and `!==` | :wrench: |
| [vue/key-spacing](./key-spacing.md) | enforce consistent spacing between keys and values in object literal properties | :wrench: |
| [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | |
| [vue/object-curly-spacing](./object-curly-spacing.md) | enforce consistent spacing inside braces | :wrench: |
| [vue/script-indent](./script-indent.md) | enforce consistent indentation in `<script>` | :wrench: |
| [vue/space-infix-ops](./space-infix-ops.md) | require spacing around infix operators | :wrench: |
| [vue/space-unary-ops](./space-unary-ops.md) | enforce consistent spacing before or after unary operators | :wrench: |

## Deprecated

Expand Down
23 changes: 23 additions & 0 deletions docs/rules/array-bracket-spacing.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/array-bracket-spacing
description: enforce consistent spacing inside array brackets
---
# vue/array-bracket-spacing
> enforce consistent spacing inside array brackets
- :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 is the same rule as core [array-bracket-spacing] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [array-bracket-spacing]

[array-bracket-spacing]: https://eslint.org/docs/rules/array-bracket-spacing

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/array-bracket-spacing.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/array-bracket-spacing.js)
23 changes: 23 additions & 0 deletions docs/rules/eqeqeq.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/eqeqeq
description: require the use of `===` and `!==`
---
# vue/eqeqeq
> require the use of `===` and `!==`
- :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 is the same rule as core [eqeqeq] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [eqeqeq]

[eqeqeq]: https://eslint.org/docs/rules/eqeqeq

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/eqeqeq.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/eqeqeq.js)
23 changes: 23 additions & 0 deletions docs/rules/key-spacing.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/key-spacing
description: enforce consistent spacing between keys and values in object literal properties
---
# vue/key-spacing
> enforce consistent spacing between keys and values in object literal properties
- :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 is the same rule as core [key-spacing] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [key-spacing]

[key-spacing]: https://eslint.org/docs/rules/key-spacing

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/key-spacing.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/key-spacing.js)
23 changes: 23 additions & 0 deletions docs/rules/object-curly-spacing.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/object-curly-spacing
description: enforce consistent spacing inside braces
---
# vue/object-curly-spacing
> enforce consistent spacing inside 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.

This rule is the same rule as core [object-curly-spacing] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [object-curly-spacing]

[object-curly-spacing]: https://eslint.org/docs/rules/object-curly-spacing

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/object-curly-spacing.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/object-curly-spacing.js)
23 changes: 23 additions & 0 deletions docs/rules/space-infix-ops.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/space-infix-ops
description: require spacing around infix operators
---
# vue/space-infix-ops
> require spacing around infix operators
- :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 is the same rule as core [space-infix-ops] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [space-infix-ops]

[space-infix-ops]: https://eslint.org/docs/rules/space-infix-ops

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/space-infix-ops.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/space-infix-ops.js)
23 changes: 23 additions & 0 deletions docs/rules/space-unary-ops.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/space-unary-ops
description: enforce consistent spacing before or after unary operators
---
# vue/space-unary-ops
> enforce consistent spacing before or after unary operators
- :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 is the same rule as core [space-unary-ops] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [space-unary-ops]

[space-unary-ops]: https://eslint.org/docs/rules/space-unary-ops

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/space-unary-ops.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/space-unary-ops.js)
14 changes: 8 additions & 6 deletions eslint-internal-rules/consistent-docs-description.js
Expand Up @@ -23,14 +23,15 @@ const ALLOWED_FIRST_WORDS = [
* @returns {ASTNode} The Property node or null if not found.
*/
function getPropertyFromObject (property, node) {
const properties = node.properties
if (node && node.type === 'ObjectExpression') {
const properties = node.properties

for (let i = 0; i < properties.length; i++) {
if (properties[i].key.name === property) {
return properties[i]
for (let i = 0; i < properties.length; i++) {
if (properties[i].key.name === property) {
return properties[i]
}
}
}

return null
}

Expand Down Expand Up @@ -128,7 +129,8 @@ module.exports = {
node.right &&
node.left.type === 'MemberExpression' &&
node.left.object.name === 'module' &&
node.left.property.name === 'exports') {
node.left.property.name === 'exports' &&
node.right.type === 'ObjectExpression') {
checkMetaDocsDescription(context, node.right)
}
}
Expand Down
11 changes: 6 additions & 5 deletions eslint-internal-rules/no-invalid-meta.js
Expand Up @@ -17,14 +17,15 @@
* @returns {ASTNode} The Property node or null if not found.
*/
function getPropertyFromObject (property, node) {
const properties = node.properties
if (node && node.type === 'ObjectExpression') {
const properties = node.properties

for (let i = 0; i < properties.length; i++) {
if (properties[i].key.name === property) {
return properties[i]
for (let i = 0; i < properties.length; i++) {
if (properties[i].key.name === property) {
return properties[i]
}
}
}

return null
}

Expand Down
7 changes: 6 additions & 1 deletion lib/configs/no-layout-rules.js
Expand Up @@ -5,17 +5,22 @@
*/
module.exports = {
rules: {
'vue/array-bracket-spacing': 'off',
'vue/html-closing-bracket-newline': 'off',
'vue/html-closing-bracket-spacing': 'off',
'vue/html-indent': 'off',
'vue/html-quotes': 'off',
'vue/html-self-closing': 'off',
'vue/key-spacing': 'off',
'vue/max-attributes-per-line': 'off',
'vue/multiline-html-element-content-newline': 'off',
'vue/mustache-interpolation-spacing': 'off',
'vue/no-multi-spaces': 'off',
'vue/no-spaces-around-equal-signs-in-attribute': 'off',
'vue/object-curly-spacing': 'off',
'vue/script-indent': 'off',
'vue/singleline-html-element-content-newline': 'off'
'vue/singleline-html-element-content-newline': 'off',
'vue/space-infix-ops': 'off',
'vue/space-unary-ops': 'off'
}
}
6 changes: 6 additions & 0 deletions lib/index.js
Expand Up @@ -7,17 +7,20 @@

module.exports = {
rules: {
'array-bracket-spacing': require('./rules/array-bracket-spacing'),
'attribute-hyphenation': require('./rules/attribute-hyphenation'),
'attributes-order': require('./rules/attributes-order'),
'comment-directive': require('./rules/comment-directive'),
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
'eqeqeq': require('./rules/eqeqeq'),
'html-closing-bracket-newline': require('./rules/html-closing-bracket-newline'),
'html-closing-bracket-spacing': require('./rules/html-closing-bracket-spacing'),
'html-end-tags': require('./rules/html-end-tags'),
'html-indent': require('./rules/html-indent'),
'html-quotes': require('./rules/html-quotes'),
'html-self-closing': require('./rules/html-self-closing'),
'jsx-uses-vars': require('./rules/jsx-uses-vars'),
'key-spacing': require('./rules/key-spacing'),
'match-component-file-name': require('./rules/match-component-file-name'),
'max-attributes-per-line': require('./rules/max-attributes-per-line'),
'multiline-html-element-content-newline': require('./rules/multiline-html-element-content-newline'),
Expand All @@ -40,6 +43,7 @@ module.exports = {
'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-v-html': require('./rules/no-v-html'),
'object-curly-spacing': require('./rules/object-curly-spacing'),
'order-in-components': require('./rules/order-in-components'),
'prop-name-casing': require('./rules/prop-name-casing'),
'require-component-is': require('./rules/require-component-is'),
Expand All @@ -52,6 +56,8 @@ module.exports = {
'return-in-computed-property': require('./rules/return-in-computed-property'),
'script-indent': require('./rules/script-indent'),
'singleline-html-element-content-newline': require('./rules/singleline-html-element-content-newline'),
'space-infix-ops': require('./rules/space-infix-ops'),
'space-unary-ops': require('./rules/space-unary-ops'),
'this-in-template': require('./rules/this-in-template'),
'use-v-on-exact': require('./rules/use-v-on-exact'),
'v-bind-style': require('./rules/v-bind-style'),
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/array-bracket-spacing.js
@@ -0,0 +1,9 @@
/**
* @author Toru Nagashima
*/
'use strict'

const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/array-bracket-spacing'))
9 changes: 9 additions & 0 deletions lib/rules/eqeqeq.js
@@ -0,0 +1,9 @@
/**
* @author Toru Nagashima
*/
'use strict'

const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/eqeqeq'))
9 changes: 9 additions & 0 deletions lib/rules/key-spacing.js
@@ -0,0 +1,9 @@
/**
* @author Toru Nagashima
*/
'use strict'

const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/key-spacing'))
9 changes: 9 additions & 0 deletions lib/rules/object-curly-spacing.js
@@ -0,0 +1,9 @@
/**
* @author Toru Nagashima
*/
'use strict'

const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/object-curly-spacing'))
9 changes: 9 additions & 0 deletions lib/rules/space-infix-ops.js
@@ -0,0 +1,9 @@
/**
* @author Toru Nagashima
*/
'use strict'

const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/space-infix-ops'))
9 changes: 9 additions & 0 deletions lib/rules/space-unary-ops.js
@@ -0,0 +1,9 @@
/**
* @author Toru Nagashima
*/
'use strict'

const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/space-unary-ops'))

0 comments on commit ebd07e6

Please sign in to comment.