Skip to content

⭐️New: Add vue/arrow-spacing rule #767

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

Merged
merged 1 commit into from
Jan 26, 2019
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
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ For example:
| Rule ID | Description | |
|:--------|:------------|:---|
| [vue/array-bracket-spacing](./array-bracket-spacing.md) | enforce consistent spacing inside array brackets | :wrench: |
| [vue/arrow-spacing](./arrow-spacing.md) | enforce consistent spacing before and after the arrow in arrow functions | :wrench: |
| [vue/component-name-in-template-casing](./component-name-in-template-casing.md) | enforce specific casing for the component naming style in template | :wrench: |
| [vue/eqeqeq](./eqeqeq.md) | require the use of `===` and `!==` | :wrench: |
| [vue/key-spacing](./key-spacing.md) | enforce consistent spacing between keys and values in object literal properties | :wrench: |
Expand Down
23 changes: 23 additions & 0 deletions docs/rules/arrow-spacing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/arrow-spacing
description: enforce consistent spacing before and after the arrow in arrow functions
---
# vue/arrow-spacing
> enforce consistent spacing before and after the arrow in arrow functions

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

## :books: Further reading

- [arrow-spacing]

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

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/arrow-spacing.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/arrow-spacing.js)
1 change: 1 addition & 0 deletions lib/configs/no-layout-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module.exports = {
rules: {
'vue/array-bracket-spacing': 'off',
'vue/arrow-spacing': 'off',
'vue/html-closing-bracket-newline': 'off',
'vue/html-closing-bracket-spacing': 'off',
'vue/html-indent': 'off',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
module.exports = {
rules: {
'array-bracket-spacing': require('./rules/array-bracket-spacing'),
'arrow-spacing': require('./rules/arrow-spacing'),
'attribute-hyphenation': require('./rules/attribute-hyphenation'),
'attributes-order': require('./rules/attributes-order'),
'comment-directive': require('./rules/comment-directive'),
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/arrow-spacing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @author Yosuke Ota
*/
'use strict'

const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/arrow-spacing'))
125 changes: 125 additions & 0 deletions tests/lib/rules/arrow-spacing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* @author Yosuke Ota
*/
'use strict'

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

const tester = new RuleTester({
parser: 'vue-eslint-parser',
parserOptions: { ecmaVersion: 2015 }
})

tester.run('arrow-spacing', rule, {
valid: [
`<template>
<div :attr="() => a" />
</template>`,
`<template>
<div @click="() => a" />
</template>`,
`<template>
<div @click="
const fn = () => a
fn()
" />
</template>`,
{
code: `
<template>
<div :attr="()=>a" />
</template>`,
options: [{ before: false, after: false }]
}
],
invalid: [
{
code: `
<template>
<div :attr="()=>a" />
</template>`,
output: `
<template>
<div :attr="() => a" />
</template>`,
errors: [
{
message: 'Missing space before =>.',
line: 3
},
{
message: 'Missing space after =>.',
line: 3
}
]
},
{
code: `
<template>
<div @click="()=>a" />
</template>`,
output: `
<template>
<div @click="() => a" />
</template>`,
errors: [
{
message: 'Missing space before =>.',
line: 3
},
{
message: 'Missing space after =>.',
line: 3
}
]
},
{
code: `
<template>
<div @click="
const fn = ()=>a
fn()
" />
</template>`,
output: `
<template>
<div @click="
const fn = () => a
fn()
" />
</template>`,
errors: [
{
message: 'Missing space before =>.',
line: 4
},
{
message: 'Missing space after =>.',
line: 4
}
]
},
{
code: `
<template>
<div :attr="() => a" />
</template>`,
options: [{ before: false, after: false }],
output: `
<template>
<div :attr="()=>a" />
</template>`,
errors: [
{
message: 'Unexpected space before =>.',
line: 3
},
{
message: 'Unexpected space after =>.',
line: 3
}
]
}
]
})