Skip to content

Commit fa26414

Browse files
ota-meshimichalsnik
authored andcommitted
⭐️New: Add vue/camelcase rule (#772)
1 parent 94e4f0b commit fa26414

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ For example:
143143
| [vue/arrow-spacing](./arrow-spacing.md) | enforce consistent spacing before and after the arrow in arrow functions | :wrench: |
144144
| [vue/block-spacing](./block-spacing.md) | disallow or enforce spaces inside of blocks after opening block and before closing block | :wrench: |
145145
| [vue/brace-style](./brace-style.md) | enforce consistent brace style for blocks | :wrench: |
146+
| [vue/camelcase](./camelcase.md) | enforce camelcase naming convention | |
146147
| [vue/component-name-in-template-casing](./component-name-in-template-casing.md) | enforce specific casing for the component naming style in template | :wrench: |
147148
| [vue/eqeqeq](./eqeqeq.md) | require the use of `===` and `!==` | :wrench: |
148149
| [vue/key-spacing](./key-spacing.md) | enforce consistent spacing between keys and values in object literal properties | :wrench: |

docs/rules/camelcase.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/camelcase
5+
description: enforce camelcase naming convention
6+
---
7+
# vue/camelcase
8+
> enforce camelcase naming convention
9+
10+
This rule is the same rule as core [camelcase] rule but it applies to the expressions in `<template>`.
11+
12+
## :books: Further reading
13+
14+
- [camelcase]
15+
16+
[camelcase]: https://eslint.org/docs/rules/camelcase
17+
18+
## :mag: Implementation
19+
20+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/camelcase.js)
21+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/camelcase.js)

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
'attributes-order': require('./rules/attributes-order'),
1414
'block-spacing': require('./rules/block-spacing'),
1515
'brace-style': require('./rules/brace-style'),
16+
'camelcase': require('./rules/camelcase'),
1617
'comment-directive': require('./rules/comment-directive'),
1718
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
1819
'eqeqeq': require('./rules/eqeqeq'),

lib/rules/camelcase.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Yosuke Ota
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/camelcase'))

tests/lib/rules/camelcase.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @author Yosuke Ota
3+
*/
4+
'use strict'
5+
6+
const RuleTester = require('eslint').RuleTester
7+
const rule = require('../../../lib/rules/camelcase')
8+
9+
const tester = new RuleTester({
10+
parser: 'vue-eslint-parser',
11+
parserOptions: { ecmaVersion: 2015 }
12+
})
13+
14+
tester.run('camelcase', rule, {
15+
valid: [
16+
`<template>
17+
<div :attr="{ myPref: 1 }" />
18+
</template>`,
19+
{
20+
code: `
21+
<template>
22+
<div @click="($event) => {
23+
const { my_pref } = $event
24+
}" />
25+
</template>`,
26+
options: [{ ignoreDestructuring: true }]
27+
}
28+
],
29+
invalid: [
30+
{
31+
code: `
32+
<template>
33+
<div :attr="{ my_pref: 1 }" />
34+
</template>`,
35+
errors: [
36+
{
37+
message: 'Identifier \'my_pref\' is not in camel case.',
38+
line: 3
39+
}
40+
]
41+
},
42+
{
43+
code: `
44+
<template>
45+
<div @click="($event) => {
46+
const { my_pref } = $event
47+
}" />
48+
</template>`,
49+
errors: [
50+
{
51+
message: 'Identifier \'my_pref\' is not in camel case.',
52+
line: 4
53+
}
54+
]
55+
}
56+
]
57+
})

0 commit comments

Comments
 (0)