Skip to content

Add documentation for some internal function #115

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
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
2 changes: 1 addition & 1 deletion lib/rules/html-end-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for html-end-tags.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/html-no-self-closing.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for html-no-self-closing.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/html-quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for html-quotes.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
const sourceCode = context.getSourceCode()
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/name-property-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ function create (context) {

return utils.executeOnVue(context, (obj) => {
const node = obj.properties
.filter(item => (
.find(item => (
item.type === 'Property' &&
item.key.name === 'name' &&
item.value.type === 'Literal'
))[0]
))

if (!node) return

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-confusing-v-for-v-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function isUsingIterationVar (vIf) {
* Creates AST event handlers for no-confusing-v-for-v-if.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-duplicate-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getName (attribute) {
* Creates AST event handlers for no-duplicate-attributes.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
const names = new Set()
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-template-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-template-root.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
const sourceCode = context.getSourceCode()
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const VALID_MODIFIERS = new Set(['prop', 'camel', 'sync'])
* Creates AST event handlers for no-invalid-v-bind.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-cloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-cloak.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-else-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-else-if.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-else.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-else.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function checkKey (context, vFor, element) {
* Creates AST event handlers for no-invalid-v-for.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
const sourceCode = context.getSourceCode()
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-html.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-if.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function getVariable (name, leafNode) {
* Creates AST event handlers for no-invalid-v-model.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-on.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const VERB_MODIFIERS = new Set([
* Creates AST event handlers for no-invalid-v-on.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-once.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-pre.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-show.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-show.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-v-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-invalid-v-text.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-parsing-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const DEFAULT_OPTIONS = Object.freeze(Object.assign(Object.create(null), {
* Creates AST event handlers for no-parsing-error.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
const options = Object.assign({}, DEFAULT_OPTIONS, context.options[0] || {})
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-template-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-template-key.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-textarea-mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for no-textarea-mustache.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-component-is.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for require-component-is.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-v-for-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function checkKey (context, element) {
* Creates AST event handlers for require-v-for-key.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
utils.registerTemplateBodyVisitor(context, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/v-bind-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for v-bind-style.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
const shorthand = context.options[0] !== 'longform'
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/v-on-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const utils = require('../utils')
* Creates AST event handlers for v-on-style.
*
* @param {RuleContext} context - The rule context.
* @returns {object} AST event handlers.
* @returns {Object} AST event handlers.
*/
function create (context) {
const shorthand = context.options[0] !== 'longform'
Expand Down
20 changes: 20 additions & 0 deletions lib/utils/casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ const assert = require('assert')

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

/**
* Convert text to kebab-case
* @param {string} str Text to be converted
* @return {string}
*/
function kebabCase (str) {
return str
.replace(/([a-z])([A-Z])/g, match => match[0] + '-' + match[1])
.replace(invalidChars, '-')
.toLowerCase()
}

/**
* Convert text to camelCase
* @param {string} str Text to be converted
* @return {string} Converted string
*/
function camelCase (str) {
return str
.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => (
Expand All @@ -17,6 +27,11 @@ function camelCase (str) {
.replace(invalidChars, '')
}

/**
* Convert text to PascalCase
* @param {string} str Text to be converted
* @return {string} Converted string
*/
function pascalCase (str) {
return str
.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => letter.toUpperCase())
Expand All @@ -36,6 +51,11 @@ module.exports = {
'PascalCase'
],

/**
* Return case converter
* @param {string} name type of converter to return ('camelCase', 'kebab-case', 'PascalCase')
* @return {kebabCase|camelCase|pascalCase}
*/
getConverter (name) {
assert(typeof name === 'string')

Expand Down
42 changes: 28 additions & 14 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ module.exports = {
* this generates a warning.
*
* @param {RuleContext} context The rule context to use parser services.
* @param {object} visitor The visitor.
* @returns {void}
* @param {Object} visitor The visitor.
*/
registerTemplateBodyVisitor (context, visitor) {
if (context.parserServices.registerTemplateBodyVisitor == null) {
Expand Down Expand Up @@ -175,11 +174,11 @@ module.exports = {
)
},

/**
* Check whether the previous sibling element has `if` or `else-if` directive.
* @param {ASTNode} node The element node to check.
* @returns {boolean} `true` if the previous sibling element has `if` or `else-if` directive.
*/
/**
* Check whether the previous sibling element has `if` or `else-if` directive.
* @param {ASTNode} node The element node to check.
* @returns {boolean} `true` if the previous sibling element has `if` or `else-if` directive.
*/
prevElementHasIf (node) {
assert(node && node.type === 'VElement')

Expand All @@ -193,11 +192,11 @@ module.exports = {
)
},

/**
* Check whether the given node is a custom component or not.
* @param {ASTNode} node The start tag node to check.
* @returns {boolean} `true` if the node is a custom component.
*/
/**
* Check whether the given node is a custom component or not.
* @param {ASTNode} node The start tag node to check.
* @returns {boolean} `true` if the node is a custom component.
*/
isCustomComponent (node) {
assert(node && node.type === 'VElement')

Expand Down Expand Up @@ -278,11 +277,11 @@ module.exports = {
*/
getComputedProperties (componentObject) {
const computedPropertiesNode = componentObject.properties
.filter(p =>
.find(p =>
p.key.type === 'Identifier' &&
p.key.name === 'computed' &&
p.value.type === 'ObjectExpression'
)[0]
)

if (!computedPropertiesNode) { return [] }

Expand Down Expand Up @@ -362,13 +361,23 @@ module.exports = {
node.arguments[0].type === 'ObjectExpression'
},

/**
* Check if current file is a Vue instance or component and call callback
* @param {RuleContext} context The ESLint rule context object.
* @param {Function} cb Callback function
*/
executeOnVue (context, cb) {
return Object.assign(
this.executeOnVueComponent(context, cb),
this.executeOnVueInstance(context, cb)
)
},

/**
* Check if current file is a Vue instance (new Vue) and call callback
* @param {RuleContext} context The ESLint rule context object.
* @param {Function} cb Callback function
*/
executeOnVueInstance (context, cb) {
const _this = this

Expand All @@ -381,6 +390,11 @@ module.exports = {
}
},

/**
* Check if current file is a Vue component and call callback
* @param {RuleContext} context The ESLint rule context object.
* @param {Function} cb Callback function
*/
executeOnVueComponent (context, cb) {
const filePath = context.getFilename()
const _this = this
Expand Down
Loading