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/keyword-spacing
rule (#795)
- Loading branch information
1 parent
66a252d
commit febc727
Showing
6 changed files
with
198 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/keyword-spacing | ||
description: enforce consistent spacing before and after keywords | ||
--- | ||
# vue/keyword-spacing | ||
> enforce consistent spacing before and after keywords | ||
- :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 [keyword-spacing] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further reading | ||
|
||
- [keyword-spacing] | ||
|
||
[keyword-spacing]: https://eslint.org/docs/rules/keyword-spacing | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/keyword-spacing.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/keyword-spacing.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,12 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const { wrapCoreRule } = require('../utils') | ||
|
||
// eslint-disable-next-line no-invalid-meta | ||
module.exports = wrapCoreRule( | ||
require('eslint/lib/rules/keyword-spacing'), | ||
{ skipDynamicArguments: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/keyword-spacing') | ||
|
||
const tester = new RuleTester({ | ||
parser: 'vue-eslint-parser', | ||
parserOptions: { ecmaVersion: 2015 } | ||
}) | ||
|
||
tester.run('keyword-spacing', rule, { | ||
valid: [ | ||
`<template> | ||
<div @event=" | ||
if (foo) { | ||
//... | ||
} else if (bar) { | ||
//... | ||
} else { | ||
//... | ||
} | ||
" /> | ||
</template>`, | ||
{ | ||
code: | ||
`<template> | ||
<div @event=" | ||
if(foo) { | ||
//... | ||
}else if(bar) { | ||
//... | ||
}else{ | ||
//... | ||
} | ||
" /> | ||
</template>`, | ||
options: [{ before: false, after: false }] | ||
}, | ||
`<template> | ||
<div :[(function(){return(1)})()]="val" /> | ||
</template>` | ||
], | ||
invalid: [ | ||
{ | ||
code: | ||
`<template> | ||
<div @event=" | ||
if(foo) { | ||
//... | ||
}else if(bar) { | ||
//... | ||
}else{ | ||
//... | ||
} | ||
" /> | ||
</template>`, | ||
output: | ||
`<template> | ||
<div @event=" | ||
if (foo) { | ||
//... | ||
} else if (bar) { | ||
//... | ||
} else { | ||
//... | ||
} | ||
" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Expected space(s) after "if".', | ||
line: 3 | ||
}, | ||
{ | ||
message: 'Expected space(s) before "else".', | ||
line: 5 | ||
}, | ||
{ | ||
message: 'Expected space(s) after "if".', | ||
line: 5 | ||
}, | ||
{ | ||
message: 'Expected space(s) before "else".', | ||
line: 7 | ||
}, | ||
{ | ||
message: 'Expected space(s) after "else".', | ||
line: 7 | ||
} | ||
] | ||
}, | ||
{ | ||
code: | ||
`<template> | ||
<div @event=" | ||
if (foo) { | ||
//... | ||
} else if (bar) { | ||
//... | ||
} else { | ||
//... | ||
} | ||
" /> | ||
</template>`, | ||
options: [{ before: false, after: false }], | ||
output: | ||
`<template> | ||
<div @event=" | ||
if(foo) { | ||
//... | ||
}else if(bar) { | ||
//... | ||
}else{ | ||
//... | ||
} | ||
" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected space(s) after "if".', | ||
line: 3 | ||
}, | ||
{ | ||
message: 'Unexpected space(s) before "else".', | ||
line: 5 | ||
}, | ||
{ | ||
message: 'Unexpected space(s) after "if".', | ||
line: 5 | ||
}, | ||
{ | ||
message: 'Unexpected space(s) before "else".', | ||
line: 7 | ||
}, | ||
{ | ||
message: 'Unexpected space(s) after "else".', | ||
line: 7 | ||
} | ||
] | ||
}, | ||
{ | ||
code: | ||
`<template> | ||
<div :[(function(){return(1)})()]="(function(){return(1)})()" /> | ||
</template>`, | ||
output: | ||
`<template> | ||
<div :[(function(){return(1)})()]="(function(){return (1)})()" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Expected space(s) after "return".', | ||
line: 2 | ||
}] | ||
} | ||
] | ||
}) |