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/func-call-spacing rule #1201

Merged
merged 3 commits into from Jun 7, 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 @@ -322,6 +322,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
| [vue/dot-location](./dot-location.md) | enforce consistent newlines before and after dots | :wrench: |
| [vue/dot-notation](./dot-notation.md) | enforce dot notation whenever possible | :wrench: |
| [vue/eqeqeq](./eqeqeq.md) | require the use of `===` and `!==` | :wrench: |
| [vue/func-call-spacing](./func-call-spacing.md) | require or disallow spacing between function identifiers and their invocations | :wrench: |
| [vue/key-spacing](./key-spacing.md) | enforce consistent spacing between keys and values in object literal properties | :wrench: |
| [vue/keyword-spacing](./keyword-spacing.md) | enforce consistent spacing before and after keywords | :wrench: |
| [vue/max-len](./max-len.md) | enforce a maximum line length | |
Expand Down
25 changes: 25 additions & 0 deletions docs/rules/func-call-spacing.md
@@ -0,0 +1,25 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/func-call-spacing
description: require or disallow spacing between function identifiers and their invocations
---
# vue/func-call-spacing
> require or disallow spacing between function identifiers and their invocations

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

## :books: Further reading

- [func-call-spacing]

[func-call-spacing]: https://eslint.org/docs/rules/func-call-spacing

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/func-call-spacing.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/func-call-spacing.js)

<sup>Taken with ❤️ [from ESLint core](https://eslint.org/docs/rules/func-call-spacing)</sup>
1 change: 1 addition & 0 deletions lib/configs/no-layout-rules.js
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'vue/comma-spacing': 'off',
'vue/comma-style': 'off',
'vue/dot-location': 'off',
'vue/func-call-spacing': 'off',
'vue/html-closing-bracket-newline': 'off',
'vue/html-closing-bracket-spacing': 'off',
'vue/html-comment-content-newline': 'off',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -25,6 +25,7 @@ module.exports = {
'dot-location': require('./rules/dot-location'),
'dot-notation': require('./rules/dot-notation'),
eqeqeq: require('./rules/eqeqeq'),
'func-call-spacing': require('./rules/func-call-spacing'),
'html-closing-bracket-newline': require('./rules/html-closing-bracket-newline'),
'html-closing-bracket-spacing': require('./rules/html-closing-bracket-spacing'),
'html-comment-content-newline': require('./rules/html-comment-content-newline'),
Expand Down
11 changes: 11 additions & 0 deletions lib/rules/func-call-spacing.js
@@ -0,0 +1,11 @@
/**
* @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/func-call-spacing'), {
skipDynamicArguments: true
})
85 changes: 85 additions & 0 deletions tests/lib/rules/func-call-spacing.js
@@ -0,0 +1,85 @@
/**
* @author Yosuke Ota
*/
'use strict'

const { RuleTester, CLIEngine } = require('eslint')
const semver = require('semver')
const rule = require('../../../lib/rules/func-call-spacing')

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

tester.run('func-call-spacing', rule, {
valid: [
`
<template>
<div :foo="foo()" />
</template>
`,
{
code: `
<template>
<div :foo="foo ()" />
</template>
`,
options: ['always']
},
`
<template>
<div :[foo()]="value" />
</template>
`,
{
code: `
<template>
<div :[foo()]="value" />
</template>
`,
options: ['always']
}
],
invalid: [
{
code: `
<template>
<div :foo="foo ()" />
</template>
`,
output: `
<template>
<div :foo="foo()" />
</template>
`,
errors: [
{
message: semver.lt(CLIEngine.version, '7.0.0')
? 'Unexpected newline between function name and paren.'
: 'Unexpected whitespace between function name and paren.',
line: 3
}
]
},
{
code: `
<template>
<div :foo="foo()" />
</template>
`,
options: ['always'],
output: `
<template>
<div :foo="foo ()" />
</template>
`,
errors: [
{
message: 'Missing space between function name and paren.',
line: 3
}
]
}
]
})