Skip to content

Commit 31a1bf9

Browse files
committed
Improve tests for name-property-casing & improve documentation
1 parent 3361366 commit 31a1bf9

30 files changed

+219
-146
lines changed

lib/rules/html-end-tags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for html-end-tags.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/html-no-self-closing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for html-no-self-closing.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/html-quotes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for html-quotes.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
const sourceCode = context.getSourceCode()

lib/rules/name-property-casing.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ function create (context) {
2121

2222
return utils.executeOnVue(context, (obj) => {
2323
const node = obj.properties
24-
.filter(item => (
24+
.find(item => (
2525
item.type === 'Property' &&
2626
item.key.name === 'name' &&
2727
item.value.type === 'Literal'
28-
))[0]
28+
))
2929

3030
if (!node) return
3131

lib/rules/no-confusing-v-for-v-if.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function isUsingIterationVar (vIf) {
3434
* Creates AST event handlers for no-confusing-v-for-v-if.
3535
*
3636
* @param {RuleContext} context - The rule context.
37-
* @returns {object} AST event handlers.
37+
* @returns {Object} AST event handlers.
3838
*/
3939
function create (context) {
4040
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-duplicate-attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function getName (attribute) {
3434
* Creates AST event handlers for no-duplicate-attributes.
3535
*
3636
* @param {RuleContext} context - The rule context.
37-
* @returns {object} AST event handlers.
37+
* @returns {Object} AST event handlers.
3838
*/
3939
function create (context) {
4040
const names = new Set()

lib/rules/no-invalid-template-root.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-template-root.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
const sourceCode = context.getSourceCode()

lib/rules/no-invalid-v-bind.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const VALID_MODIFIERS = new Set(['prop', 'camel', 'sync'])
2121
* Creates AST event handlers for no-invalid-v-bind.
2222
*
2323
* @param {RuleContext} context - The rule context.
24-
* @returns {object} AST event handlers.
24+
* @returns {Object} AST event handlers.
2525
*/
2626
function create (context) {
2727
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-cloak.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-cloak.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-else-if.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-else-if.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-else.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-else.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-for.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function checkKey (context, vFor, element) {
6666
* Creates AST event handlers for no-invalid-v-for.
6767
*
6868
* @param {RuleContext} context - The rule context.
69-
* @returns {object} AST event handlers.
69+
* @returns {Object} AST event handlers.
7070
*/
7171
function create (context) {
7272
const sourceCode = context.getSourceCode()

lib/rules/no-invalid-v-html.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-html.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-if.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-if.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function getVariable (name, leafNode) {
7777
* Creates AST event handlers for no-invalid-v-model.
7878
*
7979
* @param {RuleContext} context - The rule context.
80-
* @returns {object} AST event handlers.
80+
* @returns {Object} AST event handlers.
8181
*/
8282
function create (context) {
8383
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-on.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const VERB_MODIFIERS = new Set([
2828
* Creates AST event handlers for no-invalid-v-on.
2929
*
3030
* @param {RuleContext} context - The rule context.
31-
* @returns {object} AST event handlers.
31+
* @returns {Object} AST event handlers.
3232
*/
3333
function create (context) {
3434
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-once.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-once.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-pre.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-pre.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-show.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-show.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-text.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-parsing-error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-parsing-error.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-template-key.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-template-key.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-textarea-mustache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-textarea-mustache.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/require-component-is.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for require-component-is.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {

lib/rules/require-v-for-key.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function checkKey (context, element) {
3636
* Creates AST event handlers for require-v-for-key.
3737
*
3838
* @param {RuleContext} context - The rule context.
39-
* @returns {object} AST event handlers.
39+
* @returns {Object} AST event handlers.
4040
*/
4141
function create (context) {
4242
utils.registerTemplateBodyVisitor(context, {

lib/rules/v-bind-style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for v-bind-style.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
const shorthand = context.options[0] !== 'longform'

lib/rules/v-on-style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for v-on-style.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
const shorthand = context.options[0] !== 'longform'

lib/utils/casing.js

+20
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@ const assert = require('assert')
22

33
const invalidChars = /[^a-zA-Z0-9:]+/g
44

5+
/**
6+
* Convert text to kebab-case
7+
* @param {string} str Text to be converted
8+
* @return {string}
9+
*/
510
function kebabCase (str) {
611
return str
712
.replace(/([a-z])([A-Z])/g, match => match[0] + '-' + match[1])
813
.replace(invalidChars, '-')
914
.toLowerCase()
1015
}
1116

17+
/**
18+
* Convert text to camelCase
19+
* @param {string} str Text to be converted
20+
* @return {string} Converted string
21+
*/
1222
function camelCase (str) {
1323
return str
1424
.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => (
@@ -17,6 +27,11 @@ function camelCase (str) {
1727
.replace(invalidChars, '')
1828
}
1929

30+
/**
31+
* Convert text to PascalCase
32+
* @param {string} str Text to be converted
33+
* @return {string} Converted string
34+
*/
2035
function pascalCase (str) {
2136
return str
2237
.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => letter.toUpperCase())
@@ -36,6 +51,11 @@ module.exports = {
3651
'PascalCase'
3752
],
3853

54+
/**
55+
* Return case converter
56+
* @param {string} name type of converter to return ('camelCase', 'kebab-case', 'PascalCase')
57+
* @return {kebabCase|camelCase|pascalCase}
58+
*/
3959
getConverter (name) {
4060
assert(typeof name === 'string')
4161

0 commit comments

Comments
 (0)