Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `vue/comma-style` rule * update
- Loading branch information
Showing
7 changed files
with
210 additions
and
20 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-style | ||
description: enforce consistent comma style | ||
--- | ||
# vue/comma-style | ||
> enforce consistent comma style | ||
- :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-style] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further reading | ||
|
||
- [comma-style] | ||
|
||
[comma-style]: https://eslint.org/docs/rules/comma-style | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/comma-style.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/comma-style.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,20 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const { wrapCoreRule } = require('../utils') | ||
|
||
// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories | ||
module.exports = wrapCoreRule( | ||
require('eslint/lib/rules/comma-style'), | ||
{ | ||
create (_context, { coreHandlers }) { | ||
return { | ||
VSlotScopeExpression (node) { | ||
coreHandlers.FunctionExpression(node) | ||
} | ||
} | ||
} | ||
} | ||
) |
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,124 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const { RuleTester } = require('eslint') | ||
const rule = require('../../../lib/rules/comma-style') | ||
|
||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { ecmaVersion: 2018 } | ||
}) | ||
|
||
tester.run('comma-style', rule, { | ||
valid: [ | ||
`<template> | ||
<CustomButton @click="() => fn({ | ||
a, | ||
b | ||
})" /> | ||
</template>`, | ||
{ | ||
code: ` | ||
<template> | ||
<CustomButton @click="($event, | ||
data) => fn()" /> | ||
</template>`, | ||
options: ['last', { exceptions: { ArrowFunctionExpression: false }}] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<CustomButton @click="($event | ||
, data) => fn()" /> | ||
</template>`, | ||
options: ['first', { exceptions: { ArrowFunctionExpression: false }}] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<CustomButton @click="() => fn({ | ||
a | ||
, b | ||
})" /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<CustomButton @click="() => fn({ | ||
a, | ||
b | ||
})" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: "',' should be placed last.", | ||
line: 5 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<CustomButton @click="($event | ||
, data) => fn()" /> | ||
</template>`, | ||
options: ['last', { exceptions: { ArrowFunctionExpression: false }}], | ||
output: ` | ||
<template> | ||
<CustomButton @click="($event, | ||
data) => fn()" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: "',' should be placed last.", | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<CustomButton @click="($event, | ||
data) => fn()" /> | ||
</template>`, | ||
options: ['first', { exceptions: { ArrowFunctionExpression: false }}], | ||
output: ` | ||
<template> | ||
<CustomButton @click="($event | ||
,data) => fn()" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: "',' should be placed first." | ||
// line: 3 // eslint v7.0 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<CustomButton v-slot="foo, | ||
bar" > | ||
<div/> | ||
</CustomButton> | ||
</template>`, | ||
options: ['first', { exceptions: { FunctionExpression: false }}], | ||
output: ` | ||
<template> | ||
<CustomButton v-slot="foo | ||
,bar" > | ||
<div/> | ||
</CustomButton> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: "',' should be placed first." | ||
// line: 3 // eslint v7.0 | ||
} | ||
] | ||
} | ||
] | ||
}) |