Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default settings in html-closing-bracket-newline #539

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions docs/rules/html-closing-bracket-newline.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This rule enforces a line break (or no line break) before tag's closing brackets
{
"vue/html-closing-bracket-newline": ["error", {
"singleline": "never",
"multiline": "never"
"multiline": "always"
}]
}
```
Expand All @@ -34,63 +34,53 @@ This rule enforces a line break (or no line break) before tag's closing brackets
- `"never"` ... disallow line breaks before the closing bracket. This is the default.
- `"always"` ... require one line break before the closing bracket.
- `multiline` ... the configuration for multiline elements. It's a multiline element if the last attribute is not on the same line of the opening bracket.
- `"never"` ... disallow line breaks before the closing bracket. This is the default.
- `"always"` ... require one line break before the closing bracket.
- `"never"` ... disallow line breaks before the closing bracket.
- `"always"` ... require one line break before the closing bracket. This is the default.

Plus, you can use [`vue/html-indent`](./html-indent.md) rule to enforce indent-level of the closing brackets.

:-1: Examples of **incorrect** code for this rule:

```html
/*eslint html-closing-bracket-newline: "error"*/
<!-- eslint html-closing-bracket-newline: "error" -->

<div id="foo" class="bar"
>

<div
id="foo"
class="bar"
>
<div
id="foo"
class="bar"
>
class="bar">
```

:+1: Examples of **correct** code for this rule:

```html
/*eslint html-closing-bracket-newline: "error"*/
<!-- eslint html-closing-bracket-newline: "error" -->

<div id="foo" class="bar">
<div
id="foo"
class="bar">
class="bar"
>
```

:-1: Examples of **incorrect** code for `{ "multiline": "always" }`:
:-1: Examples of **incorrect** code for `{ "multiline": "never" }`:

```html
/*eslint html-closing-bracket-newline: ["error", { multiline: always }]*/
<!-- eslint html-closing-bracket-newline: ["error", { multiline: never }] -->

<div id="foo" class="bar"
>
<div
id="foo"
class="bar">
class="bar"
>
```

:+1: Examples of **correct** code for `{ "multiline": "always" }`:
:+1: Examples of **correct** code for `{ "multiline": "never" }`:

```html
/*eslint html-closing-bracket-newline: ["error", { multiline: always }]*/
<!-- html-closing-bracket-newline: ["error", { multiline: never }] -->

<div id="foo" class="bar">
<div
id="foo"
class="bar"
>
<div
id="foo"
class="bar"
>
class="bar">
```
5 changes: 4 additions & 1 deletion lib/rules/html-closing-bracket-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ module.exports = {
},

create (context) {
const options = context.options[0] || {}
const options = Object.assign({}, {
singleline: 'never',
multiline: 'always'
}, context.options[0] || {})
const template = context.parserServices.getTemplateBodyTokenStore && context.parserServices.getTemplateBodyTokenStore()

return utils.defineTemplateBodyVisitor(context, {
Expand Down
11 changes: 6 additions & 5 deletions tests/lib/rules/html-closing-bracket-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ tester.run('html-closing-bracket-newline', rule, {
`
<template>
<div
id="">
id=""
>
</div>
</template>
`,
Expand Down Expand Up @@ -144,20 +145,20 @@ tester.run('html-closing-bracket-newline', rule, {
code: `
<template>
<div
id=""
>
id="">
</div>
</template>
`,
output: `
<template>
<div
id="">
id=""
>
</div>
</template>
`,
errors: [
'Expected no line breaks before closing bracket, but 1 line break found.'
'Expected 1 line break before closing bracket, but no line breaks found.'
]
},
{
Expand Down