Skip to content

Commit

Permalink
New: add vue/dot-location rule (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored and mysticatea committed Feb 27, 2019
1 parent 4d01589 commit 18dab15
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -146,6 +146,7 @@ For example:
| [vue/camelcase](./camelcase.md) | enforce camelcase naming convention | |
| [vue/comma-dangle](./comma-dangle.md) | require or disallow trailing commas | :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/dot-location](./dot-location.md) | enforce consistent newlines before and after dots | :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: |
| [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | |
Expand Down
23 changes: 23 additions & 0 deletions docs/rules/dot-location.md
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/dot-location
description: enforce consistent newlines before and after dots
---
# vue/dot-location
> enforce consistent newlines before and after dots
- :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 [dot-location] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [dot-location]

[dot-location]: https://eslint.org/docs/rules/dot-location

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/dot-location.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/dot-location.js)
1 change: 1 addition & 0 deletions lib/configs/no-layout-rules.js
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'vue/block-spacing': 'off',
'vue/brace-style': 'off',
'vue/comma-dangle': 'off',
'vue/dot-location': '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
Expand Up @@ -17,6 +17,7 @@ module.exports = {
'comma-dangle': require('./rules/comma-dangle'),
'comment-directive': require('./rules/comment-directive'),
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
'dot-location': require('./rules/dot-location'),
'eqeqeq': require('./rules/eqeqeq'),
'html-closing-bracket-newline': require('./rules/html-closing-bracket-newline'),
'html-closing-bracket-spacing': require('./rules/html-closing-bracket-spacing'),
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/dot-location.js
@@ -0,0 +1,9 @@
/**
* @author Yosuke Ota
*/
'use strict'

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

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/dot-location'))
80 changes: 80 additions & 0 deletions tests/lib/rules/dot-location.js
@@ -0,0 +1,80 @@
/**
* @author Yosuke Ota
*/
'use strict'

const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/dot-location')

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

tester.run('dot-location', rule, {
valid: [
`<template>
<div
:attr="foo.
bar"
/>
</template>`,
{
code: `
<template>
<div
:attr="foo
.bar"
/>
</template>`,
options: ['property']
}
],
invalid: [
{
code: `
<template>
<div
:attr="foo
.bar"
/>
</template>`,
output: `
<template>
<div
:attr="foo.
bar"
/>
</template>`,
errors: [
{
message: 'Expected dot to be on same line as object.',
line: 5
}
]
},
{
code: `
<template>
<div
:attr="foo.
bar"
/>
</template>`,
options: ['property'],
output: `
<template>
<div
:attr="foo
.bar"
/>
</template>`,
errors: [
{
message: 'Expected dot to be on same line as property.',
line: 4
}
]
}
]
})

0 comments on commit 18dab15

Please sign in to comment.