Skip to content

Commit

Permalink
⭐️New: Add vue/comma-dangle rule (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored and michalsnik committed Jan 29, 2019
1 parent fa26414 commit a8b2ca0
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -144,6 +144,7 @@ For example:
| [vue/block-spacing](./block-spacing.md) | disallow or enforce spaces inside of blocks after opening block and before closing block | :wrench: |
| [vue/brace-style](./brace-style.md) | enforce consistent brace style for blocks | :wrench: |
| [vue/camelcase](./camelcase.md) | enforce camelcase naming convention | |
| [vue/comma-dangle](./comma-dangle.md) | require or disallow trailing commas | :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: |
Expand Down
23 changes: 23 additions & 0 deletions docs/rules/comma-dangle.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/comma-dangle
description: require or disallow trailing commas
---
# vue/comma-dangle
> require or disallow trailing commas
- :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 [comma-dangle] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [comma-dangle]

[comma-dangle]: https://eslint.org/docs/rules/comma-dangle

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/comma-dangle.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/comma-dangle.js)
1 change: 1 addition & 0 deletions lib/configs/no-layout-rules.js
Expand Up @@ -9,6 +9,7 @@ module.exports = {
'vue/arrow-spacing': 'off',
'vue/block-spacing': 'off',
'vue/brace-style': 'off',
'vue/comma-dangle': 'off',
'vue/html-closing-bracket-newline': 'off',
'vue/html-closing-bracket-spacing': 'off',
'vue/html-indent': 'off',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -14,6 +14,7 @@ module.exports = {
'block-spacing': require('./rules/block-spacing'),
'brace-style': require('./rules/brace-style'),
'camelcase': require('./rules/camelcase'),
'comma-dangle': require('./rules/comma-dangle'),
'comment-directive': require('./rules/comment-directive'),
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
'eqeqeq': require('./rules/eqeqeq'),
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/comma-dangle.js
@@ -0,0 +1,9 @@
/**
* @author Yosuke Ota
*/
'use strict'

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

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/comma-dangle'))
108 changes: 108 additions & 0 deletions tests/lib/rules/comma-dangle.js
@@ -0,0 +1,108 @@
/**
* @author Yosuke Ota
*/
'use strict'

const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/comma-dangle')

const tester = new RuleTester({
parser: 'vue-eslint-parser',
parserOptions: { ecmaVersion: 2018 }
})

tester.run('comma-dangle', rule, {
valid: [
`<template>
<button @click="() => fn([a, b])" ></button>
</template>`,
{
code: `
<template>
<CustomButton @click="($event) => fn()" />
</template>`,
options: [{
'functions': 'never'
}]
},
{
code: `
<template>
<button @click="() => fn([a, b, ])" ></button>
</template>`,
options: [{
'arrays': 'ignore'
}]
}
],
invalid: [
{
code: `
<template>
<button @click="() => fn([a, b,])" ></button>
</template>`,
output: `
<template>
<button @click="() => fn([a, b])" ></button>
</template>`,
errors: [
{
message: 'Unexpected trailing comma.',
line: 3
}
]
},
{
code: `
<template>
<CustomButton @click="($event, ) => fn()" />
</template>`,
options: [{
'functions': 'never'
}],
output: `
<template>
<CustomButton @click="($event ) => fn()" />
</template>`,
errors: [
{
message: 'Unexpected trailing comma.',
line: 3
}
]
},
{
code: `
<template>
<button @click="() => {
fn([a, b, ])
fn([
a,
b
])
}"></button>
</template>`,
options: ['always-multiline'],
output: `
<template>
<button @click="() => {
fn([a, b ])
fn([
a,
b,
])
}"></button>
</template>`,
errors: [
{
message: 'Unexpected trailing comma.',
line: 4
},
{
message: 'Missing trailing comma.',
line: 7
}
]
}
]
})

0 comments on commit a8b2ca0

Please sign in to comment.