Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
vue/object-curly-newline
rule (#1194)
- Loading branch information
Showing
6 changed files
with
188 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/object-curly-newline | ||
description: enforce consistent line breaks inside braces | ||
--- | ||
# vue/object-curly-newline | ||
> enforce consistent line breaks inside braces | ||
- :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 [object-curly-newline] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further reading | ||
|
||
- [object-curly-newline] | ||
|
||
[object-curly-newline]: https://eslint.org/docs/rules/object-curly-newline | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/object-curly-newline.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/object-curly-newline.js) | ||
|
||
<sup>Taken with ❤️ [from ESLint core](https://eslint.org/docs/rules/object-curly-newline)</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,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/object-curly-newline'), | ||
{ 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,148 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/object-curly-newline') | ||
|
||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { ecmaVersion: 2020 } | ||
}) | ||
|
||
tester.run('object-curly-newline', rule, { | ||
valid: [ | ||
` | ||
<template> | ||
<div :foo="{a: 1}" /> | ||
</template> | ||
`, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="{a: 1}" /> | ||
</template> | ||
`, | ||
options: ['never'] | ||
}, | ||
` | ||
<template> | ||
<div :foo="{ | ||
a: 1 | ||
}" /> | ||
</template> | ||
`, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="{ | ||
a: 1 | ||
}" /> | ||
</template> | ||
`, | ||
options: ['always'] | ||
}, | ||
` | ||
<template> | ||
<div :[{a:1}]="value" /> | ||
</template> | ||
`, | ||
{ | ||
code: ` | ||
<template> | ||
<div :[{a:1}]="value" /> | ||
</template> | ||
`, | ||
options: ['always'] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :[{a:1}]="value" /> | ||
</template> | ||
`, | ||
options: ['never'] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="{a: 1 | ||
}" /> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div :foo="{a: 1}" /> | ||
</template> | ||
`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected line break before this closing brace.', | ||
line: 4, | ||
column: 9 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="{ | ||
a: 1}" /> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div :foo="{a: 1}" /> | ||
</template> | ||
`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected line break after this opening brace.', | ||
line: 3, | ||
column: 20 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="{a: 1}" /> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div :foo="{ | ||
a: 1 | ||
}" /> | ||
</template> | ||
`, | ||
options: ['always'], | ||
errors: [ | ||
'Expected a line break after this opening brace.', | ||
'Expected a line break before this closing brace.' | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo="{ | ||
a: 1 | ||
}" /> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div :foo="{a: 1}" /> | ||
</template> | ||
`, | ||
options: ['never'], | ||
errors: [ | ||
'Unexpected line break after this opening brace.', | ||
'Unexpected line break before this closing brace.' | ||
] | ||
} | ||
] | ||
}) |