Skip to content

⭐️New: Add vue/comma-dangle rule #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
})