Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
vue/space-in-parens
rule (#1157)
* ⭐️New: Add `vue/space-in-parens` rule * update * update * update
- Loading branch information
Showing
5 changed files
with
248 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/space-in-parens | ||
description: enforce consistent spacing inside parentheses | ||
--- | ||
# vue/space-in-parens | ||
> enforce consistent spacing inside parentheses | ||
- :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 [space-in-parens] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further reading | ||
|
||
- [space-in-parens] | ||
|
||
[space-in-parens]: https://eslint.org/docs/rules/space-in-parens | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/space-in-parens.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/space-in-parens.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @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/space-in-parens'), | ||
{ skipDynamicArguments: true, skipDynamicArgumentsReport: true } | ||
) |
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,205 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const { RuleTester, CLIEngine } = require('eslint') | ||
const semver = require('semver') | ||
const rule = require('../../../lib/rules/space-in-parens') | ||
|
||
const errorMessage = semver.lt(CLIEngine.version, '6.4.0') | ||
? (obj) => { | ||
const messageId = obj.messageId | ||
delete obj.messageId | ||
obj.message = messageId.startsWith('missing') ? 'There must be a space inside this paren.' : 'There should be no spaces inside this paren.' | ||
return obj | ||
} | ||
: obj => obj | ||
|
||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { ecmaVersion: 2015 } | ||
}) | ||
|
||
tester.run('space-in-parens', rule, { | ||
valid: [ | ||
`<template> | ||
<button | ||
@click="foo(arg)" | ||
/> | ||
</template>`, | ||
{ | ||
code: ` | ||
<template> | ||
<button | ||
@click="foo( arg )" | ||
/> | ||
</template>`, | ||
options: ['always'] | ||
}, | ||
` | ||
<template> | ||
<button | ||
:[foo(arg)]="foo(arg)" | ||
/> | ||
</template>`, | ||
{ | ||
code: ` | ||
<template> | ||
<button | ||
:[foo(arg)]="foo( arg )" | ||
/> | ||
</template>`, | ||
options: ['always'] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<button | ||
@click="foo( arg )" | ||
/> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<button | ||
@click="foo(arg)" | ||
/> | ||
</template>`, | ||
errors: [ | ||
errorMessage({ | ||
messageId: 'rejectedOpeningSpace', | ||
line: 4 | ||
}), | ||
errorMessage({ | ||
messageId: 'rejectedClosingSpace', | ||
line: 4 | ||
}) | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<button | ||
@click="foo(arg)" | ||
/> | ||
</template>`, | ||
options: ['always'], | ||
output: ` | ||
<template> | ||
<button | ||
@click="foo( arg )" | ||
/> | ||
</template>`, | ||
errors: [ | ||
errorMessage({ | ||
messageId: 'missingOpeningSpace', | ||
line: 4 | ||
}), | ||
errorMessage({ | ||
messageId: 'missingClosingSpace', | ||
line: 4 | ||
}) | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<input | ||
:value="( 1 + 2 ) + 3" | ||
> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<input | ||
:value="(1 + 2) + 3" | ||
> | ||
</template>`, | ||
errors: [ | ||
errorMessage({ | ||
messageId: 'rejectedOpeningSpace', | ||
line: 4 | ||
}), | ||
errorMessage({ | ||
messageId: 'rejectedClosingSpace', | ||
line: 4 | ||
}) | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<input | ||
:value="(1 + 2) + 3" | ||
> | ||
</template>`, | ||
options: ['always'], | ||
output: ` | ||
<template> | ||
<input | ||
:value="( 1 + 2 ) + 3" | ||
> | ||
</template>`, | ||
errors: [ | ||
errorMessage({ | ||
messageId: 'missingOpeningSpace', | ||
line: 4 | ||
}), | ||
errorMessage({ | ||
messageId: 'missingClosingSpace', | ||
line: 4 | ||
}) | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<input | ||
:[(1+2)]="( 1 + 2 ) + 3" | ||
> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<input | ||
:[(1+2)]="(1 + 2) + 3" | ||
> | ||
</template>`, | ||
errors: [ | ||
errorMessage({ | ||
messageId: 'rejectedOpeningSpace', | ||
line: 4 | ||
}), | ||
errorMessage({ | ||
messageId: 'rejectedClosingSpace', | ||
line: 4 | ||
}) | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<input | ||
:[(1+2)]="(1 + 2) + 3" | ||
> | ||
</template>`, | ||
options: ['always'], | ||
output: ` | ||
<template> | ||
<input | ||
:[(1+2)]="( 1 + 2 ) + 3" | ||
> | ||
</template>`, | ||
errors: [ | ||
errorMessage({ | ||
messageId: 'missingOpeningSpace', | ||
line: 4 | ||
}), | ||
errorMessage({ | ||
messageId: 'missingClosingSpace', | ||
line: 4 | ||
}) | ||
] | ||
} | ||
] | ||
}) |