Skip to content

Commit

Permalink
⭐️New: Add vue/camelcase rule (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored and michalsnik committed Jan 29, 2019
1 parent 94e4f0b commit fa26414
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -143,6 +143,7 @@ For example:
| [vue/arrow-spacing](./arrow-spacing.md) | enforce consistent spacing before and after the arrow in arrow functions | :wrench: |
| [vue/block-spacing](./block-spacing.md) | disallow or enforce spaces inside of blocks after opening block and before closing block | :wrench: |
| [vue/brace-style](./brace-style.md) | enforce consistent brace style for blocks | :wrench: |
| [vue/camelcase](./camelcase.md) | enforce camelcase naming convention | |
| [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
21 changes: 21 additions & 0 deletions docs/rules/camelcase.md
@@ -0,0 +1,21 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/camelcase
description: enforce camelcase naming convention
---
# vue/camelcase
> enforce camelcase naming convention
This rule is the same rule as core [camelcase] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [camelcase]

[camelcase]: https://eslint.org/docs/rules/camelcase

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/camelcase.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/camelcase.js)
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'attributes-order': require('./rules/attributes-order'),
'block-spacing': require('./rules/block-spacing'),
'brace-style': require('./rules/brace-style'),
'camelcase': require('./rules/camelcase'),
'comment-directive': require('./rules/comment-directive'),
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
'eqeqeq': require('./rules/eqeqeq'),
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/camelcase.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/camelcase'))
57 changes: 57 additions & 0 deletions tests/lib/rules/camelcase.js
@@ -0,0 +1,57 @@
/**
* @author Yosuke Ota
*/
'use strict'

const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/camelcase')

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

tester.run('camelcase', rule, {
valid: [
`<template>
<div :attr="{ myPref: 1 }" />
</template>`,
{
code: `
<template>
<div @click="($event) => {
const { my_pref } = $event
}" />
</template>`,
options: [{ ignoreDestructuring: true }]
}
],
invalid: [
{
code: `
<template>
<div :attr="{ my_pref: 1 }" />
</template>`,
errors: [
{
message: 'Identifier \'my_pref\' is not in camel case.',
line: 3
}
]
},
{
code: `
<template>
<div @click="($event) => {
const { my_pref } = $event
}" />
</template>`,
errors: [
{
message: 'Identifier \'my_pref\' is not in camel case.',
line: 4
}
]
}
]
})

0 comments on commit fa26414

Please sign in to comment.