Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
vue/operator-linebreak
rule (#1200)
* Add `vue/operator-linebreak` rule * fix
- Loading branch information
Showing
6 changed files
with
166 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,25 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/operator-linebreak | ||
description: enforce consistent linebreak style for operators | ||
--- | ||
# vue/operator-linebreak | ||
> enforce consistent linebreak style for operators | ||
- :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 [operator-linebreak] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further reading | ||
|
||
- [operator-linebreak] | ||
|
||
[operator-linebreak]: https://eslint.org/docs/rules/operator-linebreak | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/operator-linebreak.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/operator-linebreak.js) | ||
|
||
<sup>Taken with ❤️ [from ESLint core](https://eslint.org/docs/rules/operator-linebreak)</sup> |
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 no-invalid-meta, no-invalid-meta-docs-categories | ||
module.exports = wrapCoreRule(require('eslint/lib/rules/operator-linebreak')) |
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,129 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/operator-linebreak') | ||
|
||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { ecmaVersion: 2020 } | ||
}) | ||
|
||
tester.run('operator-linebreak', rule, { | ||
valid: [ | ||
` | ||
<template> | ||
<div :foo="1 + 2" /> | ||
</template> | ||
`, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="1 + 2" /> | ||
</template> | ||
`, | ||
options: ['before'] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="1 + 2" /> | ||
</template> | ||
`, | ||
options: ['none'] | ||
}, | ||
` | ||
<template> | ||
<div :[foo+bar]="value" /> | ||
</template> | ||
`, | ||
{ | ||
code: ` | ||
<template> | ||
<div :[foo+bar]="value" /> | ||
</template> | ||
`, | ||
options: ['before'] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :[foo+bar]="value" /> | ||
</template> | ||
`, | ||
options: ['none'] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="1 | ||
+ 2" /> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div :foo="1 + | ||
2" /> | ||
</template> | ||
`, | ||
errors: [ | ||
{ | ||
message: "'+' should be placed at the end of the line.", | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="1 + | ||
2" /> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div :foo="1 | ||
+ 2" /> | ||
</template> | ||
`, | ||
options: ['before'], | ||
errors: [ | ||
{ | ||
message: "'+' should be placed at the beginning of the line.", | ||
line: 3 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="1 + | ||
2" /> | ||
<div :foo="1 | ||
+ 2" /> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div :foo="1 + 2" /> | ||
<div :foo="1 + 2" /> | ||
</template> | ||
`, | ||
options: ['none'], | ||
errors: [ | ||
{ | ||
message: "There should be no line break before or after '+'.", | ||
line: 3 | ||
}, | ||
{ | ||
message: "There should be no line break before or after '+'.", | ||
line: 6 | ||
} | ||
] | ||
} | ||
] | ||
}) |