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

Add vue/template-curly-spacing rule #1142

Merged
merged 1 commit into from May 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -300,6 +300,7 @@ For example:
| [vue/space-infix-ops](./space-infix-ops.md) | require spacing around infix operators | :wrench: |
| [vue/space-unary-ops](./space-unary-ops.md) | enforce consistent spacing before or after unary operators | :wrench: |
| [vue/static-class-names-order](./static-class-names-order.md) | enforce static class names order | :wrench: |
| [vue/template-curly-spacing](./template-curly-spacing.md) | require or disallow spacing around embedded expressions of template strings | :wrench: |
| [vue/v-on-function-call](./v-on-function-call.md) | enforce or forbid parentheses after method calls without arguments in `v-on` directives | :wrench: |

## Deprecated
Expand Down
23 changes: 23 additions & 0 deletions docs/rules/template-curly-spacing.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/template-curly-spacing
description: require or disallow spacing around embedded expressions of template strings
---
# vue/template-curly-spacing
> require or disallow spacing around embedded expressions of template strings

- :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 [template-curly-spacing] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [template-curly-spacing]

[template-curly-spacing]: https://eslint.org/docs/rules/template-curly-spacing

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/template-curly-spacing.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/template-curly-spacing.js)
3 changes: 2 additions & 1 deletion lib/configs/no-layout-rules.js
Expand Up @@ -32,6 +32,7 @@ module.exports = {
'vue/script-indent': 'off',
'vue/singleline-html-element-content-newline': 'off',
'vue/space-infix-ops': 'off',
'vue/space-unary-ops': 'off'
'vue/space-unary-ops': 'off',
'vue/template-curly-spacing': 'off'
}
}
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -109,6 +109,7 @@ module.exports = {
'space-infix-ops': require('./rules/space-infix-ops'),
'space-unary-ops': require('./rules/space-unary-ops'),
'static-class-names-order': require('./rules/static-class-names-order'),
'template-curly-spacing': require('./rules/template-curly-spacing'),
'this-in-template': require('./rules/this-in-template'),
'use-v-on-exact': require('./rules/use-v-on-exact'),
'v-bind-style': require('./rules/v-bind-style'),
Expand Down
12 changes: 12 additions & 0 deletions lib/rules/template-curly-spacing.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/template-curly-spacing'),
{ skipDynamicArguments: true }
)
90 changes: 90 additions & 0 deletions tests/lib/rules/template-curly-spacing.js
@@ -0,0 +1,90 @@
/**
* @author Yosuke Ota
*/
'use strict'

const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/template-curly-spacing')

const tester = new RuleTester({
parser: require.resolve('vue-eslint-parser'),
parserOptions: { ecmaVersion: 2020 }
})

tester.run('template-curly-spacing', rule, {
valid: [
`
<template>
<div :class="[\`foo-\${bar}\`]" />
</template>
`,
`
<template>
<div :[\`foo\${bar}\`]="value" />
</template>
`,
{
code: `
<template>
<div :class="[\`foo-\${ bar }\`]" />
</template>
`,
options: ['always']
},
{
code: `
<template>
<div :[\`foo\${bar}\`]="value" />
</template>
`,
options: ['always']
}
],
invalid: [
{
code: `
<template>
<div :class="[\`foo-\${ bar }\`]" />
</template>
`,
output: `
<template>
<div :class="[\`foo-\${bar}\`]" />
</template>
`,
errors: [
{
message: "Unexpected space(s) after '${'.",
line: 3
},
{
message: "Unexpected space(s) before '}'.",
line: 3
}
]
},
{
code: `
<template>
<div :class="[\`foo-\${bar}\`]" />
</template>
`,
options: ['always'],
output: `
<template>
<div :class="[\`foo-\${ bar }\`]" />
</template>
`,
errors: [
{
message: "Expected space(s) after '${'.",
line: 3
},
{
message: "Expected space(s) before '}'.",
line: 3
}
]
}
]
})