diff --git a/lib/rules/html-end-tags.js b/lib/rules/html-end-tags.js index 852d79258..4238cca1d 100644 --- a/lib/rules/html-end-tags.js +++ b/lib/rules/html-end-tags.js @@ -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, { diff --git a/lib/rules/html-no-self-closing.js b/lib/rules/html-no-self-closing.js index daf10d111..6378686e6 100644 --- a/lib/rules/html-no-self-closing.js +++ b/lib/rules/html-no-self-closing.js @@ -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, { diff --git a/lib/rules/html-quotes.js b/lib/rules/html-quotes.js index dd66dcadb..2dd4ec45c 100644 --- a/lib/rules/html-quotes.js +++ b/lib/rules/html-quotes.js @@ -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() diff --git a/lib/rules/no-confusing-v-for-v-if.js b/lib/rules/no-confusing-v-for-v-if.js index e202a9a16..d69632243 100644 --- a/lib/rules/no-confusing-v-for-v-if.js +++ b/lib/rules/no-confusing-v-for-v-if.js @@ -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, { diff --git a/lib/rules/no-duplicate-attributes.js b/lib/rules/no-duplicate-attributes.js index 99afe50ed..65a566fb1 100644 --- a/lib/rules/no-duplicate-attributes.js +++ b/lib/rules/no-duplicate-attributes.js @@ -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() diff --git a/lib/rules/no-invalid-template-root.js b/lib/rules/no-invalid-template-root.js index c759a420c..78d55ecef 100644 --- a/lib/rules/no-invalid-template-root.js +++ b/lib/rules/no-invalid-template-root.js @@ -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() diff --git a/lib/rules/no-invalid-v-bind.js b/lib/rules/no-invalid-v-bind.js index dd8da2ddf..cd9ddc600 100644 --- a/lib/rules/no-invalid-v-bind.js +++ b/lib/rules/no-invalid-v-bind.js @@ -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, { diff --git a/lib/rules/no-invalid-v-cloak.js b/lib/rules/no-invalid-v-cloak.js index 33d3e684c..55757d122 100644 --- a/lib/rules/no-invalid-v-cloak.js +++ b/lib/rules/no-invalid-v-cloak.js @@ -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, { diff --git a/lib/rules/no-invalid-v-else-if.js b/lib/rules/no-invalid-v-else-if.js index 1f985d248..e9f007458 100644 --- a/lib/rules/no-invalid-v-else-if.js +++ b/lib/rules/no-invalid-v-else-if.js @@ -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, { diff --git a/lib/rules/no-invalid-v-else.js b/lib/rules/no-invalid-v-else.js index 1141f4db9..58eb6e763 100644 --- a/lib/rules/no-invalid-v-else.js +++ b/lib/rules/no-invalid-v-else.js @@ -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, { diff --git a/lib/rules/no-invalid-v-for.js b/lib/rules/no-invalid-v-for.js index cd18f146b..aced1b81d 100644 --- a/lib/rules/no-invalid-v-for.js +++ b/lib/rules/no-invalid-v-for.js @@ -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() diff --git a/lib/rules/no-invalid-v-html.js b/lib/rules/no-invalid-v-html.js index 8bacfdabc..8d179da0a 100644 --- a/lib/rules/no-invalid-v-html.js +++ b/lib/rules/no-invalid-v-html.js @@ -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, { diff --git a/lib/rules/no-invalid-v-if.js b/lib/rules/no-invalid-v-if.js index a4695af18..e77b15c46 100644 --- a/lib/rules/no-invalid-v-if.js +++ b/lib/rules/no-invalid-v-if.js @@ -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, { diff --git a/lib/rules/no-invalid-v-model.js b/lib/rules/no-invalid-v-model.js index aa0e543cb..59deadf5b 100644 --- a/lib/rules/no-invalid-v-model.js +++ b/lib/rules/no-invalid-v-model.js @@ -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, { diff --git a/lib/rules/no-invalid-v-on.js b/lib/rules/no-invalid-v-on.js index a271d45fa..142d849aa 100644 --- a/lib/rules/no-invalid-v-on.js +++ b/lib/rules/no-invalid-v-on.js @@ -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, { diff --git a/lib/rules/no-invalid-v-once.js b/lib/rules/no-invalid-v-once.js index bfd94acf2..36f73afb7 100644 --- a/lib/rules/no-invalid-v-once.js +++ b/lib/rules/no-invalid-v-once.js @@ -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, { diff --git a/lib/rules/no-invalid-v-pre.js b/lib/rules/no-invalid-v-pre.js index 34b2cebfc..07f2e401b 100644 --- a/lib/rules/no-invalid-v-pre.js +++ b/lib/rules/no-invalid-v-pre.js @@ -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, { diff --git a/lib/rules/no-invalid-v-show.js b/lib/rules/no-invalid-v-show.js index f3ef4c863..f2812f167 100644 --- a/lib/rules/no-invalid-v-show.js +++ b/lib/rules/no-invalid-v-show.js @@ -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, { diff --git a/lib/rules/no-invalid-v-text.js b/lib/rules/no-invalid-v-text.js index 2fe715640..6284f90a2 100644 --- a/lib/rules/no-invalid-v-text.js +++ b/lib/rules/no-invalid-v-text.js @@ -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, { diff --git a/lib/rules/no-parsing-error.js b/lib/rules/no-parsing-error.js index 98665232b..94a3b1af1 100644 --- a/lib/rules/no-parsing-error.js +++ b/lib/rules/no-parsing-error.js @@ -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] || {}) diff --git a/lib/rules/no-template-key.js b/lib/rules/no-template-key.js index 1c8444303..b9677e462 100644 --- a/lib/rules/no-template-key.js +++ b/lib/rules/no-template-key.js @@ -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, { diff --git a/lib/rules/no-textarea-mustache.js b/lib/rules/no-textarea-mustache.js index d89ec7a4a..fd637a8f4 100644 --- a/lib/rules/no-textarea-mustache.js +++ b/lib/rules/no-textarea-mustache.js @@ -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, { diff --git a/lib/rules/require-component-is.js b/lib/rules/require-component-is.js index 977c19519..e72587feb 100644 --- a/lib/rules/require-component-is.js +++ b/lib/rules/require-component-is.js @@ -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, { diff --git a/lib/rules/require-v-for-key.js b/lib/rules/require-v-for-key.js index 7033555ef..5125fc5d8 100644 --- a/lib/rules/require-v-for-key.js +++ b/lib/rules/require-v-for-key.js @@ -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, { diff --git a/lib/rules/v-bind-style.js b/lib/rules/v-bind-style.js index bff958a67..1093171dd 100644 --- a/lib/rules/v-bind-style.js +++ b/lib/rules/v-bind-style.js @@ -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' diff --git a/lib/rules/v-on-style.js b/lib/rules/v-on-style.js index 92a6453a0..fead015c7 100644 --- a/lib/rules/v-on-style.js +++ b/lib/rules/v-on-style.js @@ -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' diff --git a/lib/utils/casing.js b/lib/utils/casing.js index 15fd415ab..4069216f4 100644 --- a/lib/utils/casing.js +++ b/lib/utils/casing.js @@ -2,6 +2,11 @@ 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]) @@ -9,6 +14,11 @@ function kebabCase (str) { .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) => ( @@ -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()) @@ -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') diff --git a/lib/utils/index.js b/lib/utils/index.js index 9eafc98c7..ccf3b9157 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -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) { @@ -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') @@ -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') @@ -404,6 +403,11 @@ 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), @@ -411,6 +415,11 @@ module.exports = { ) }, + /** + * 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 @@ -423,6 +432,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 diff --git a/tests/lib/rules/name-property-casing.js b/tests/lib/rules/name-property-casing.js index 07df15089..88ede6d6d 100644 --- a/tests/lib/rules/name-property-casing.js +++ b/tests/lib/rules/name-property-casing.js @@ -15,6 +15,11 @@ const RuleTester = require('eslint').RuleTester // Tests // ------------------------------------------------------------------------------ +const parserOptions = { + ecmaVersion: 6, + sourceType: 'module' +} + const ruleTester = new RuleTester() ruleTester.run('name-property-casing', rule, { @@ -26,7 +31,7 @@ ruleTester.run('name-property-casing', rule, { } `, options: ['camelCase'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' } + parserOptions }, { filename: 'test.vue', @@ -36,7 +41,7 @@ ruleTester.run('name-property-casing', rule, { } `, options: ['camelCase'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' } + parserOptions }, { filename: 'test.vue', @@ -46,7 +51,7 @@ ruleTester.run('name-property-casing', rule, { } `, options: ['PascalCase'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' } + parserOptions }, { filename: 'test.vue', @@ -56,7 +61,7 @@ ruleTester.run('name-property-casing', rule, { } `, options: ['kebab-case'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' } + parserOptions } ], @@ -68,8 +73,13 @@ ruleTester.run('name-property-casing', rule, { name: 'foo-bar' } `, + output: ` + export default { + name: 'fooBar' + } + `, options: ['camelCase'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + parserOptions, errors: [{ message: 'Property name "foo-bar" is not camelCase.', type: 'Literal', @@ -83,8 +93,12 @@ ruleTester.run('name-property-casing', rule, { name: 'foo bar' } `, - options: ['PascalCase'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + output: ` + export default { + name: 'FooBar' + } + `, + parserOptions, errors: [{ message: 'Property name "foo bar" is not PascalCase.', type: 'Literal', @@ -98,8 +112,13 @@ ruleTester.run('name-property-casing', rule, { name: 'foo!bar' } `, + output: ` + export default { + name: 'fooBar' + } + `, options: ['camelCase'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + parserOptions, errors: [{ message: 'Property name "foo!bar" is not camelCase.', type: 'Literal', @@ -113,6 +132,11 @@ ruleTester.run('name-property-casing', rule, { name: 'foo!bar' }) `, + output: ` + new Vue({ + name: 'fooBar' + }) + `, options: ['camelCase'], parserOptions: { ecmaVersion: 6 }, errors: [{ @@ -128,8 +152,13 @@ ruleTester.run('name-property-casing', rule, { name: 'foo_bar' } `, + output: ` + export default { + name: 'foobar' + } + `, options: ['camelCase'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + parserOptions, errors: [{ message: 'Property name "foo_bar" is not camelCase.', type: 'Literal', @@ -143,8 +172,13 @@ ruleTester.run('name-property-casing', rule, { name: 'foo_bar' } `, + output: ` + export default { + name: 'Foobar' + } + `, options: ['PascalCase'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + parserOptions, errors: [{ message: 'Property name "foo_bar" is not PascalCase.', type: 'Literal', @@ -158,8 +192,13 @@ ruleTester.run('name-property-casing', rule, { name: 'foo_bar' } `, + output: ` + export default { + name: 'foo-bar' + } + `, options: ['kebab-case'], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + parserOptions, errors: [{ message: 'Property name "foo_bar" is not kebab-case.', type: 'Literal',