Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐️New: Add
vue/comma-dangle
rule (#773)
- Loading branch information
1 parent
fa26414
commit a8b2ca0
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
] | ||
}) |