Skip to content

Commit ebd07e6

Browse files
mysticateamichalsnik
authored andcommitted
New: some core rules for <template> (#680)
* 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
1 parent 5dd07bf commit ebd07e6

25 files changed

+566
-13
lines changed

Diff for: docs/rules/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,22 @@ For example:
132132
```json
133133
{
134134
"rules": {
135-
"vue/component-name-in-template-casing": "error"
135+
"vue/array-bracket-spacing": "error"
136136
}
137137
}
138138
```
139139

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

146152
## Deprecated
147153

Diff for: docs/rules/array-bracket-spacing.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/array-bracket-spacing
5+
description: enforce consistent spacing inside array brackets
6+
---
7+
# vue/array-bracket-spacing
8+
> enforce consistent spacing inside array brackets
9+
10+
- :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.
11+
12+
This rule is the same rule as core [array-bracket-spacing] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [array-bracket-spacing]
17+
18+
[array-bracket-spacing]: https://eslint.org/docs/rules/array-bracket-spacing
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/array-bracket-spacing.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/array-bracket-spacing.js)

Diff for: docs/rules/eqeqeq.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/eqeqeq
5+
description: require the use of `===` and `!==`
6+
---
7+
# vue/eqeqeq
8+
> require the use of `===` and `!==`
9+
10+
- :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.
11+
12+
This rule is the same rule as core [eqeqeq] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [eqeqeq]
17+
18+
[eqeqeq]: https://eslint.org/docs/rules/eqeqeq
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/eqeqeq.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/eqeqeq.js)

Diff for: docs/rules/key-spacing.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/key-spacing
5+
description: enforce consistent spacing between keys and values in object literal properties
6+
---
7+
# vue/key-spacing
8+
> enforce consistent spacing between keys and values in object literal properties
9+
10+
- :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.
11+
12+
This rule is the same rule as core [key-spacing] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [key-spacing]
17+
18+
[key-spacing]: https://eslint.org/docs/rules/key-spacing
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/key-spacing.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/key-spacing.js)

Diff for: docs/rules/object-curly-spacing.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/object-curly-spacing
5+
description: enforce consistent spacing inside braces
6+
---
7+
# vue/object-curly-spacing
8+
> enforce consistent spacing inside braces
9+
10+
- :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.
11+
12+
This rule is the same rule as core [object-curly-spacing] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [object-curly-spacing]
17+
18+
[object-curly-spacing]: https://eslint.org/docs/rules/object-curly-spacing
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/object-curly-spacing.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/object-curly-spacing.js)

Diff for: docs/rules/space-infix-ops.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/space-infix-ops
5+
description: require spacing around infix operators
6+
---
7+
# vue/space-infix-ops
8+
> require spacing around infix operators
9+
10+
- :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.
11+
12+
This rule is the same rule as core [space-infix-ops] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [space-infix-ops]
17+
18+
[space-infix-ops]: https://eslint.org/docs/rules/space-infix-ops
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/space-infix-ops.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/space-infix-ops.js)

Diff for: docs/rules/space-unary-ops.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/space-unary-ops
5+
description: enforce consistent spacing before or after unary operators
6+
---
7+
# vue/space-unary-ops
8+
> enforce consistent spacing before or after unary operators
9+
10+
- :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.
11+
12+
This rule is the same rule as core [space-unary-ops] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [space-unary-ops]
17+
18+
[space-unary-ops]: https://eslint.org/docs/rules/space-unary-ops
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/space-unary-ops.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/space-unary-ops.js)

Diff for: eslint-internal-rules/consistent-docs-description.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ const ALLOWED_FIRST_WORDS = [
2323
* @returns {ASTNode} The Property node or null if not found.
2424
*/
2525
function getPropertyFromObject (property, node) {
26-
const properties = node.properties
26+
if (node && node.type === 'ObjectExpression') {
27+
const properties = node.properties
2728

28-
for (let i = 0; i < properties.length; i++) {
29-
if (properties[i].key.name === property) {
30-
return properties[i]
29+
for (let i = 0; i < properties.length; i++) {
30+
if (properties[i].key.name === property) {
31+
return properties[i]
32+
}
3133
}
3234
}
33-
3435
return null
3536
}
3637

@@ -128,7 +129,8 @@ module.exports = {
128129
node.right &&
129130
node.left.type === 'MemberExpression' &&
130131
node.left.object.name === 'module' &&
131-
node.left.property.name === 'exports') {
132+
node.left.property.name === 'exports' &&
133+
node.right.type === 'ObjectExpression') {
132134
checkMetaDocsDescription(context, node.right)
133135
}
134136
}

Diff for: eslint-internal-rules/no-invalid-meta.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
* @returns {ASTNode} The Property node or null if not found.
1818
*/
1919
function getPropertyFromObject (property, node) {
20-
const properties = node.properties
20+
if (node && node.type === 'ObjectExpression') {
21+
const properties = node.properties
2122

22-
for (let i = 0; i < properties.length; i++) {
23-
if (properties[i].key.name === property) {
24-
return properties[i]
23+
for (let i = 0; i < properties.length; i++) {
24+
if (properties[i].key.name === property) {
25+
return properties[i]
26+
}
2527
}
2628
}
27-
2829
return null
2930
}
3031

Diff for: lib/configs/no-layout-rules.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55
*/
66
module.exports = {
77
rules: {
8+
'vue/array-bracket-spacing': 'off',
89
'vue/html-closing-bracket-newline': 'off',
910
'vue/html-closing-bracket-spacing': 'off',
1011
'vue/html-indent': 'off',
1112
'vue/html-quotes': 'off',
1213
'vue/html-self-closing': 'off',
14+
'vue/key-spacing': 'off',
1315
'vue/max-attributes-per-line': 'off',
1416
'vue/multiline-html-element-content-newline': 'off',
1517
'vue/mustache-interpolation-spacing': 'off',
1618
'vue/no-multi-spaces': 'off',
1719
'vue/no-spaces-around-equal-signs-in-attribute': 'off',
20+
'vue/object-curly-spacing': 'off',
1821
'vue/script-indent': 'off',
19-
'vue/singleline-html-element-content-newline': 'off'
22+
'vue/singleline-html-element-content-newline': 'off',
23+
'vue/space-infix-ops': 'off',
24+
'vue/space-unary-ops': 'off'
2025
}
2126
}

Diff for: lib/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77

88
module.exports = {
99
rules: {
10+
'array-bracket-spacing': require('./rules/array-bracket-spacing'),
1011
'attribute-hyphenation': require('./rules/attribute-hyphenation'),
1112
'attributes-order': require('./rules/attributes-order'),
1213
'comment-directive': require('./rules/comment-directive'),
1314
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
15+
'eqeqeq': require('./rules/eqeqeq'),
1416
'html-closing-bracket-newline': require('./rules/html-closing-bracket-newline'),
1517
'html-closing-bracket-spacing': require('./rules/html-closing-bracket-spacing'),
1618
'html-end-tags': require('./rules/html-end-tags'),
1719
'html-indent': require('./rules/html-indent'),
1820
'html-quotes': require('./rules/html-quotes'),
1921
'html-self-closing': require('./rules/html-self-closing'),
2022
'jsx-uses-vars': require('./rules/jsx-uses-vars'),
23+
'key-spacing': require('./rules/key-spacing'),
2124
'match-component-file-name': require('./rules/match-component-file-name'),
2225
'max-attributes-per-line': require('./rules/max-attributes-per-line'),
2326
'multiline-html-element-content-newline': require('./rules/multiline-html-element-content-newline'),
@@ -40,6 +43,7 @@ module.exports = {
4043
'no-unused-vars': require('./rules/no-unused-vars'),
4144
'no-use-v-if-with-v-for': require('./rules/no-use-v-if-with-v-for'),
4245
'no-v-html': require('./rules/no-v-html'),
46+
'object-curly-spacing': require('./rules/object-curly-spacing'),
4347
'order-in-components': require('./rules/order-in-components'),
4448
'prop-name-casing': require('./rules/prop-name-casing'),
4549
'require-component-is': require('./rules/require-component-is'),
@@ -52,6 +56,8 @@ module.exports = {
5256
'return-in-computed-property': require('./rules/return-in-computed-property'),
5357
'script-indent': require('./rules/script-indent'),
5458
'singleline-html-element-content-newline': require('./rules/singleline-html-element-content-newline'),
59+
'space-infix-ops': require('./rules/space-infix-ops'),
60+
'space-unary-ops': require('./rules/space-unary-ops'),
5561
'this-in-template': require('./rules/this-in-template'),
5662
'use-v-on-exact': require('./rules/use-v-on-exact'),
5763
'v-bind-style': require('./rules/v-bind-style'),

Diff for: lib/rules/array-bracket-spacing.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Toru Nagashima
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/array-bracket-spacing'))

Diff for: lib/rules/eqeqeq.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Toru Nagashima
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/eqeqeq'))

Diff for: lib/rules/key-spacing.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Toru Nagashima
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/key-spacing'))

Diff for: lib/rules/object-curly-spacing.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Toru Nagashima
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/object-curly-spacing'))

Diff for: lib/rules/space-infix-ops.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Toru Nagashima
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/space-infix-ops'))

Diff for: lib/rules/space-unary-ops.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Toru Nagashima
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/space-unary-ops'))

0 commit comments

Comments
 (0)