Skip to content

Commit

Permalink
Add vue/object-curly-newline rule (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jun 7, 2020
1 parent c3ec794 commit ad07d62
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -330,6 +330,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
| [vue/no-irregular-whitespace](./no-irregular-whitespace.md) | disallow irregular whitespace | |
| [vue/no-restricted-syntax](./no-restricted-syntax.md) | disallow specified syntax | |
| [vue/no-useless-concat](./no-useless-concat.md) | disallow unnecessary concatenation of literals or template literals | |
| [vue/object-curly-newline](./object-curly-newline.md) | enforce consistent line breaks inside braces | :wrench: |
| [vue/object-curly-spacing](./object-curly-spacing.md) | enforce consistent spacing inside braces | :wrench: |
| [vue/object-property-newline](./object-property-newline.md) | enforce placing object properties on separate lines | :wrench: |
| [vue/prefer-template](./prefer-template.md) | require template literals instead of string concatenation | :wrench: |
Expand Down
25 changes: 25 additions & 0 deletions docs/rules/object-curly-newline.md
@@ -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>
1 change: 1 addition & 0 deletions lib/configs/no-layout-rules.js
Expand Up @@ -30,6 +30,7 @@ module.exports = {
'vue/no-extra-parens': 'off',
'vue/no-multi-spaces': 'off',
'vue/no-spaces-around-equal-signs-in-attribute': 'off',
'vue/object-curly-newline': 'off',
'vue/object-curly-spacing': 'off',
'vue/object-property-newline': 'off',
'vue/padding-line-between-blocks': 'off',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -104,6 +104,7 @@ module.exports = {
'no-v-html': require('./rules/no-v-html'),
'no-v-model-argument': require('./rules/no-v-model-argument'),
'no-watch-after-await': require('./rules/no-watch-after-await'),
'object-curly-newline': require('./rules/object-curly-newline'),
'object-curly-spacing': require('./rules/object-curly-spacing'),
'object-property-newline': require('./rules/object-property-newline'),
'one-component-per-file': require('./rules/one-component-per-file'),
Expand Down
12 changes: 12 additions & 0 deletions lib/rules/object-curly-newline.js
@@ -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 }
)
148 changes: 148 additions & 0 deletions tests/lib/rules/object-curly-newline.js
@@ -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.'
]
}
]
})

0 comments on commit ad07d62

Please sign in to comment.