From 39de5406b40b17a5a423a09ce15781dc6b700f57 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Fri, 12 Jan 2018 18:00:06 +0900 Subject: [PATCH 0001/1157] Fix: indent bug about semicolons --- lib/utils/indent-common.js | 25 +++++++++++++------ .../fixtures/script-indent/if-statement-04.js | 4 +++ .../fixtures/script-indent/if-statement-05.js | 6 +++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 tests/fixtures/script-indent/if-statement-04.js create mode 100644 tests/fixtures/script-indent/if-statement-05.js diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index 1d02ba11b..a6b50867b 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -1419,14 +1419,25 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti // Process semicolons. ':statement' (node) { const info = offsets.get(tokenStore.getFirstToken(node)) - const prevToken = tokenStore.getTokenBefore(node) - const lastToken = tokenStore.getLastToken(node) - - if (info != null && isSemicolon(prevToken)) { - offsets.set(prevToken, info) + if (info == null) { + return } - if (info != null && isSemicolon(lastToken)) { - offsets.set(lastToken, info) + + // Set to the semicolon of the previous token for semicolon-free style. + // E.g., + // foo + // ;[1,2,3].forEach(f) + const tokens = [ + tokenStore.getTokenBefore(node), + tokenStore.getLastToken(node) + ].filter(isSemicolon) + + // Set offsets if the semicolon is at beginning of line. + for (const token of tokens) { + const prevToken = tokenStore.getTokenBefore(token) + if (prevToken == null || token.loc.end.line !== prevToken.loc.start.line) { + offsets.set(token, info) + } } }, diff --git a/tests/fixtures/script-indent/if-statement-04.js b/tests/fixtures/script-indent/if-statement-04.js new file mode 100644 index 000000000..41831505e --- /dev/null +++ b/tests/fixtures/script-indent/if-statement-04.js @@ -0,0 +1,4 @@ +/*{}*/ +if (a) + b; +c diff --git a/tests/fixtures/script-indent/if-statement-05.js b/tests/fixtures/script-indent/if-statement-05.js new file mode 100644 index 000000000..4e9af67f4 --- /dev/null +++ b/tests/fixtures/script-indent/if-statement-05.js @@ -0,0 +1,6 @@ +/*{}*/ +function wrap() { + if (x) + this.doSomething(); + foo +} From 26ab87a465a89214522df9be11ed4fa85317bb2b Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Fri, 12 Jan 2018 20:03:57 +0900 Subject: [PATCH 0002/1157] Fix: indent bug about shorthand properties --- lib/utils/indent-common.js | 2 +- .../script-indent/object-expression-02.vue | 8 +++++ tests/fixtures/script-indent/property-01.vue | 32 ------------------- tests/fixtures/script-indent/property-02.vue | 14 ++++++++ tests/fixtures/script-indent/property-03.vue | 12 +++++++ tests/fixtures/script-indent/property-04.vue | 10 ++++++ tests/fixtures/script-indent/property-05.vue | 14 ++++++++ tests/fixtures/script-indent/property-06.vue | 7 ++++ 8 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 tests/fixtures/script-indent/object-expression-02.vue create mode 100644 tests/fixtures/script-indent/property-02.vue create mode 100644 tests/fixtures/script-indent/property-03.vue create mode 100644 tests/fixtures/script-indent/property-04.vue create mode 100644 tests/fixtures/script-indent/property-05.vue create mode 100644 tests/fixtures/script-indent/property-06.vue diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index a6b50867b..704e8726c 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -1270,7 +1270,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti const leftParenToken = tokenStore.getTokenAfter(lastKeyToken) setOffset(leftParenToken, 1, lastKeyToken) - } else { + } else if (!node.shorthand) { const colonToken = tokenStore.getTokenAfter(lastKeyToken) const valueToken = tokenStore.getTokenAfter(colonToken) diff --git a/tests/fixtures/script-indent/object-expression-02.vue b/tests/fixtures/script-indent/object-expression-02.vue new file mode 100644 index 000000000..5ff0e46c2 --- /dev/null +++ b/tests/fixtures/script-indent/object-expression-02.vue @@ -0,0 +1,8 @@ + + diff --git a/tests/fixtures/script-indent/property-01.vue b/tests/fixtures/script-indent/property-01.vue index 6bc2a8e94..0f1a45071 100644 --- a/tests/fixtures/script-indent/property-01.vue +++ b/tests/fixtures/script-indent/property-01.vue @@ -4,37 +4,5 @@ aaa : 1 - , - bbb - ( - a - , - b - ) - { - ; - } - , - get - ccc - ( - ) - { - ; - }, - [ - d - ] - : - 1, - get - [ - e - ] - ( - ) - { - ; - } } diff --git a/tests/fixtures/script-indent/property-02.vue b/tests/fixtures/script-indent/property-02.vue new file mode 100644 index 000000000..b1f4d933f --- /dev/null +++ b/tests/fixtures/script-indent/property-02.vue @@ -0,0 +1,14 @@ + + diff --git a/tests/fixtures/script-indent/property-03.vue b/tests/fixtures/script-indent/property-03.vue new file mode 100644 index 000000000..4ebc00e9a --- /dev/null +++ b/tests/fixtures/script-indent/property-03.vue @@ -0,0 +1,12 @@ + + diff --git a/tests/fixtures/script-indent/property-04.vue b/tests/fixtures/script-indent/property-04.vue new file mode 100644 index 000000000..a28cfaad7 --- /dev/null +++ b/tests/fixtures/script-indent/property-04.vue @@ -0,0 +1,10 @@ + + diff --git a/tests/fixtures/script-indent/property-05.vue b/tests/fixtures/script-indent/property-05.vue new file mode 100644 index 000000000..73ec6cd17 --- /dev/null +++ b/tests/fixtures/script-indent/property-05.vue @@ -0,0 +1,14 @@ + + diff --git a/tests/fixtures/script-indent/property-06.vue b/tests/fixtures/script-indent/property-06.vue new file mode 100644 index 000000000..acf1644a2 --- /dev/null +++ b/tests/fixtures/script-indent/property-06.vue @@ -0,0 +1,7 @@ + + From 095ef4fb01e0ee96b616f2898946050b16e7769b Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Thu, 18 Jan 2018 12:57:34 +0900 Subject: [PATCH 0003/1157] Chore: add `require-meta-docs-url` internal rule (#341) * Chore: move `create` function into object literal I found that `eslint-plugin-eslint-plugin` rules are using `create` function to detect ESLint rule files. If `create` is not a method (includes a variable reference), `eslint-plugin-eslint-plugin` rules don't work properly. * Chore: add require-meta-docs-url rule * Chore: update meta.docs.url * Chore: add version script for meta.docs.url * Fix: apply require-meta-docs-url rule --- .eslintrc.js | 19 +- .../require-meta-docs-url.js | 244 ++++++++++++++++++ lib/rules/.eslintrc.json | 6 - lib/rules/attribute-hyphenation.js | 90 ++++--- lib/rules/comment-directive.js | 55 ++-- lib/rules/html-closing-bracket-newline.js | 87 +++---- lib/rules/html-closing-bracket-spacing.js | 2 +- lib/rules/html-end-tags.js | 75 +++--- lib/rules/html-indent.js | 2 +- lib/rules/html-quotes.js | 92 +++---- lib/rules/html-self-closing.js | 125 +++++---- lib/rules/jsx-uses-vars.js | 2 +- lib/rules/max-attributes-per-line.js | 2 +- lib/rules/mustache-interpolation-spacing.js | 2 +- lib/rules/name-property-casing.js | 68 +++-- lib/rules/no-async-in-computed-properties.js | 167 ++++++------ lib/rules/no-confusing-v-for-v-if.js | 43 ++- lib/rules/no-dupe-keys.js | 62 ++--- lib/rules/no-duplicate-attributes.js | 99 ++++--- lib/rules/no-multi-spaces.js | 2 +- lib/rules/no-parsing-error.js | 71 +++-- lib/rules/no-reserved-keys.js | 68 +++-- lib/rules/no-shared-component-data.js | 74 +++--- .../no-side-effects-in-computed-properties.js | 102 ++++---- lib/rules/no-template-key.js | 43 ++- lib/rules/no-textarea-mustache.js | 47 ++-- lib/rules/no-unused-vars.js | 53 ++-- lib/rules/order-in-components.js | 77 +++--- lib/rules/require-component-is.js | 43 ++- lib/rules/require-default-prop.js | 2 +- lib/rules/require-prop-types.js | 140 +++++----- lib/rules/require-render-return.js | 62 +++-- lib/rules/require-v-for-key.js | 72 +++--- lib/rules/require-valid-default-prop.js | 2 +- lib/rules/return-in-computed-property.js | 70 +++-- lib/rules/script-indent.js | 8 +- lib/rules/this-in-template.js | 2 +- lib/rules/v-bind-style.js | 59 ++--- lib/rules/v-on-style.js | 61 ++--- lib/rules/valid-template-root.js | 177 ++++++------- lib/rules/valid-v-bind.js | 61 ++--- lib/rules/valid-v-cloak.js | 71 +++-- lib/rules/valid-v-else-if.js | 117 ++++----- lib/rules/valid-v-else.js | 117 ++++----- lib/rules/valid-v-for.js | 165 ++++++------ lib/rules/valid-v-html.js | 71 +++-- lib/rules/valid-v-if.js | 103 ++++---- lib/rules/valid-v-model.js | 144 +++++------ lib/rules/valid-v-on.js | 59 ++--- lib/rules/valid-v-once.js | 71 +++-- lib/rules/valid-v-pre.js | 71 +++-- lib/rules/valid-v-show.js | 71 +++-- lib/rules/valid-v-text.js | 71 +++-- package.json | 3 +- tests/lib/rules/no-shared-component-data.js | 6 +- 55 files changed, 1819 insertions(+), 1859 deletions(-) create mode 100644 eslint-internal-rules/require-meta-docs-url.js delete mode 100644 lib/rules/.eslintrc.json diff --git a/.eslintrc.js b/.eslintrc.js index 0d0779434..4b8396bec 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,7 @@ +'use strict' + +const version = require('./package.json').version + module.exports = { root: true, parserOptions: { @@ -15,8 +19,19 @@ module.exports = { 'eslint-plugin' ], rules: { - 'eslint-plugin/report-message-format': ['error', '^[A-Z].*\\.$'], + 'eslint-plugin/report-message-format': ['error', '^[A-Z`\'].*\\.$'], 'eslint-plugin/prefer-placeholders': 'error', 'eslint-plugin/consistent-output': 'error' - } + }, + + overrides: [{ + files: ['lib/rules/*.js'], + rules: { + "consistent-docs-description": "error", + "no-invalid-meta": "error", + "require-meta-docs-url": ["error", { + "pattern": `https://github.com/vuejs/eslint-plugin-vue/blob/v${version}/docs/rules/{{name}}.md` + }] + } + }] } diff --git a/eslint-internal-rules/require-meta-docs-url.js b/eslint-internal-rules/require-meta-docs-url.js new file mode 100644 index 000000000..1eb9d9ffb --- /dev/null +++ b/eslint-internal-rules/require-meta-docs-url.js @@ -0,0 +1,244 @@ +/** + * @author Toru Nagashima + * @author Teddy Katz + * + * Three functions `isNormalFunctionExpression`, `getKeyName`, and `getRuleInfo` + * are copied from https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/lib/utils.js + * + * I have a plan to send this rule to that plugin: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/55 + */ + +'use strict' + +// ----------------------------------------------------------------------------- +// Requirements +// ----------------------------------------------------------------------------- + +const path = require('path') + +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +/** +* Determines whether a node is a 'normal' (i.e. non-async, non-generator) function expression. +* @param {ASTNode} node The node in question +* @returns {boolean} `true` if the node is a normal function expression +*/ +function isNormalFunctionExpression (node) { + return (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') && !node.generator && !node.async +} + +/** + * Gets the key name of a Property, if it can be determined statically. + * @param {ASTNode} node The `Property` node + * @returns {string|null} The key name, or `null` if the name cannot be determined statically. + */ +function getKeyName (property) { + if (!property.computed && property.key.type === 'Identifier') { + return property.key.name + } + if (property.key.type === 'Literal') { + return '' + property.key.value + } + if (property.key.type === 'TemplateLiteral' && property.key.quasis.length === 1) { + return property.key.quasis[0].value.cooked + } + return null +} + +/** +* Performs static analysis on an AST to try to determine the final value of `module.exports`. +* @param {ASTNode} ast The `Program` AST node +* @returns {Object} An object with keys `meta`, `create`, and `isNewStyle`. `meta` and `create` correspond to the AST nodes +for the final values of `module.exports.meta` and `module.exports.create`. `isNewStyle` will be `true` if `module.exports` +is an object, and `false` if module.exports is just the `create` function. If no valid ESLint rule info can be extracted +from the file, the return value will be `null`. +*/ +function getRuleInfo (ast) { + const INTERESTING_KEYS = new Set(['create', 'meta']) + let exportsVarOverridden = false + let exportsIsFunction = false + + const exportNodes = ast.body + .filter(statement => statement.type === 'ExpressionStatement') + .map(statement => statement.expression) + .filter(expression => expression.type === 'AssignmentExpression') + .filter(expression => expression.left.type === 'MemberExpression') + .reduce((currentExports, node) => { + if ( + node.left.object.type === 'Identifier' && node.left.object.name === 'module' && + node.left.property.type === 'Identifier' && node.left.property.name === 'exports' + ) { + exportsVarOverridden = true + + if (isNormalFunctionExpression(node.right)) { + // Check `module.exports = function () {}` + + exportsIsFunction = true + return { create: node.right, meta: null } + } else if (node.right.type === 'ObjectExpression') { + // Check `module.exports = { create: function () {}, meta: {} }` + + exportsIsFunction = false + return node.right.properties.reduce((parsedProps, prop) => { + const keyValue = getKeyName(prop) + if (INTERESTING_KEYS.has(keyValue)) { + parsedProps[keyValue] = prop.value + } + return parsedProps + }, {}) + } + return {} + } else if ( + !exportsIsFunction && + node.left.object.type === 'MemberExpression' && + node.left.object.object.type === 'Identifier' && node.left.object.object.name === 'module' && + node.left.object.property.type === 'Identifier' && node.left.object.property.name === 'exports' && + node.left.property.type === 'Identifier' && INTERESTING_KEYS.has(node.left.property.name) + ) { + // Check `module.exports.create = () => {}` + + currentExports[node.left.property.name] = node.right + } else if ( + !exportsVarOverridden && + node.left.object.type === 'Identifier' && node.left.object.name === 'exports' && + node.left.property.type === 'Identifier' && INTERESTING_KEYS.has(node.left.property.name) + ) { + // Check `exports.create = () => {}` + + currentExports[node.left.property.name] = node.right + } + return currentExports + }, {}) + + return Object.prototype.hasOwnProperty.call(exportNodes, 'create') && isNormalFunctionExpression(exportNodes.create) + ? Object.assign({ isNewStyle: !exportsIsFunction, meta: null }, exportNodes) + : null +} + +// ----------------------------------------------------------------------------- +// Rule Definition +// ----------------------------------------------------------------------------- + +module.exports = { + meta: { + docs: { + description: 'require rules to implement a meta.docs.url property', + category: 'Rules', + recommended: false + }, + fixable: 'code', + schema: [{ + type: 'object', + properties: { + pattern: { type: 'string' } + }, + additionalProperties: false + }] + }, + + /** + * Creates AST event handlers for require-meta-docs-url. + * @param {RuleContext} context - The rule context. + * @returns {Object} AST event handlers. + */ + create (context) { + const options = context.options[0] || {} + const sourceCode = context.getSourceCode() + const filename = context.getFilename() + const ruleName = filename === '' ? undefined : path.basename(filename, '.js') + const expectedUrl = !options.pattern || !ruleName + ? undefined + : options.pattern.replace(/{{\s*name\s*}}/g, ruleName) + + /** + * Check whether a given node is the expected URL. + * @param {Node} node The node of property value to check. + * @returns {boolean} `true` if the node is the expected URL. + */ + function isExpectedUrl (node) { + return Boolean( + node && + node.type === 'Literal' && + typeof node.value === 'string' && + ( + expectedUrl === undefined || + node.value === expectedUrl + ) + ) + } + + /** + * Insert a given property into a given object literal. + * @param {SourceCodeFixer} fixer The fixer. + * @param {Node} node The ObjectExpression node to insert a property. + * @param {string} propertyText The property code to insert. + * @returns {void} + */ + function insertProperty (fixer, node, propertyText) { + if (node.properties.length === 0) { + return fixer.replaceText(node, `{\n${propertyText}\n}`) + } + return fixer.insertTextAfter( + sourceCode.getLastToken(node.properties[node.properties.length - 1]), + `,\n${propertyText}` + ) + } + + return { + Program (node) { + const info = getRuleInfo(node) + if (!info) { + return + } + const metaNode = info.meta + const docsPropNode = + metaNode && + metaNode.properties && + metaNode.properties.find(p => p.type === 'Property' && getKeyName(p) === 'docs') + const urlPropNode = + docsPropNode && + docsPropNode.value.properties && + docsPropNode.value.properties.find(p => p.type === 'Property' && getKeyName(p) === 'url') + + if (isExpectedUrl(urlPropNode && urlPropNode.value)) { + return + } + + context.report({ + loc: + (urlPropNode && urlPropNode.value.loc) || + (docsPropNode && docsPropNode.value.loc) || + (metaNode && metaNode.loc) || + node.loc.start, + + message: + !urlPropNode ? 'Rules should export a `meta.docs.url` property.' + : !expectedUrl ? '`meta.docs.url` property must be a string.' + /* otherwise */ : '`meta.docs.url` property must be `{{expectedUrl}}`.', + + data: { + expectedUrl + }, + + fix (fixer) { + if (expectedUrl) { + const urlString = JSON.stringify(expectedUrl) + if (urlPropNode) { + return fixer.replaceText(urlPropNode.value, urlString) + } + if (docsPropNode && docsPropNode.value.type === 'ObjectExpression') { + return insertProperty(fixer, docsPropNode.value, `url: ${urlString}`) + } + if (!docsPropNode && metaNode && metaNode.type === 'ObjectExpression') { + return insertProperty(fixer, metaNode, `docs: {\nurl: ${urlString}\n}`) + } + } + return null + } + }) + } + } + } +} diff --git a/lib/rules/.eslintrc.json b/lib/rules/.eslintrc.json deleted file mode 100644 index 936029a17..000000000 --- a/lib/rules/.eslintrc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "rules": { - "consistent-docs-description": "error", - "no-invalid-meta": "error" - } -} diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js index 5dec55b99..c428f0fd5 100644 --- a/lib/rules/attribute-hyphenation.js +++ b/lib/rules/attribute-hyphenation.js @@ -11,56 +11,12 @@ const casing = require('../utils/casing') // Rule Definition // ------------------------------------------------------------------------------ -function create (context) { - const sourceCode = context.getSourceCode() - const options = context.options[0] - const useHyphenated = options !== 'never' - - const caseConverter = casing.getConverter(useHyphenated ? 'kebab-case' : 'camelCase') - - function reportIssue (node, name) { - const text = sourceCode.getText(node.key) - - context.report({ - node: node.key, - loc: node.loc, - message: useHyphenated ? "Attribute '{{text}}' must be hyphenated." : "Attribute '{{text}}' cann't be hyphenated.", - data: { - text - }, - fix: fixer => fixer.replaceText(node.key, text.replace(name, caseConverter(name))) - }) - } - - function isIgnoredAttribute (value) { - if (value.indexOf('data-') !== -1 || value.indexOf('aria-') !== -1) { - return true - } - return useHyphenated ? value.toLowerCase() === value : !/-/.test(value) - } - - // ---------------------------------------------------------------------- - // Public - // ---------------------------------------------------------------------- - - return utils.defineTemplateBodyVisitor(context, { - VAttribute (node) { - if (!utils.isCustomComponent(node.parent.parent)) return - - const name = !node.directive ? node.key.rawName : node.key.name === 'bind' ? node.key.raw.argument : false - if (!name || isIgnoredAttribute(name)) return - - reportIssue(node, name) - } - }) -} - module.exports = { meta: { docs: { description: 'enforce attribute naming style in template', category: 'strongly-recommended', - url: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/attribute-hyphenation.md' + url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v4.2.0/docs/rules/attribute-hyphenation.md' }, fixable: 'code', schema: [ @@ -70,5 +26,47 @@ module.exports = { ] }, - create + create (context) { + const sourceCode = context.getSourceCode() + const options = context.options[0] + const useHyphenated = options !== 'never' + + const caseConverter = casing.getConverter(useHyphenated ? 'kebab-case' : 'camelCase') + + function reportIssue (node, name) { + const text = sourceCode.getText(node.key) + + context.report({ + node: node.key, + loc: node.loc, + message: useHyphenated ? "Attribute '{{text}}' must be hyphenated." : "Attribute '{{text}}' cann't be hyphenated.", + data: { + text + }, + fix: fixer => fixer.replaceText(node.key, text.replace(name, caseConverter(name))) + }) + } + + function isIgnoredAttribute (value) { + if (value.indexOf('data-') !== -1 || value.indexOf('aria-') !== -1) { + return true + } + return useHyphenated ? value.toLowerCase() === value : !/-/.test(value) + } + + // ---------------------------------------------------------------------- + // Public + // ---------------------------------------------------------------------- + + return utils.defineTemplateBodyVisitor(context, { + VAttribute (node) { + if (!utils.isCustomComponent(node.parent.parent)) return + + const name = !node.directive ? node.key.rawName : node.key.name === 'bind' ? node.key.raw.argument : false + if (!name || isIgnoredAttribute(name)) return + + reportIssue(node, name) + } + }) + } } diff --git a/lib/rules/comment-directive.js b/lib/rules/comment-directive.js index 2189d0892..69d381ff8 100644 --- a/lib/rules/comment-directive.js +++ b/lib/rules/comment-directive.js @@ -1,6 +1,7 @@ /** * @author Toru Nagashima */ +/* eslint-disable eslint-plugin/report-message-format, consistent-docs-description */ 'use strict' @@ -99,33 +100,6 @@ function processLine (context, comment) { } } -/** - * The implementation of `vue/comment-directive` rule. - * @param {Program} node The program node to parse. - * @returns {Object} The visitor of this rule. - */ -function create (context) { - return { - Program (node) { - if (!node.templateBody) { - return - } - - // Send directives to the post-process. - for (const comment of node.templateBody.comments) { - processBlock(context, comment) - processLine(context, comment) - } - - // Send a clear mark to the post-process. - context.report({ - loc: node.templateBody.loc.end, - message: 'clear' - }) - } - } -} - // ----------------------------------------------------------------------------- // Rule Definition // ----------------------------------------------------------------------------- @@ -133,11 +107,32 @@ function create (context) { module.exports = { meta: { docs: { - description: 'support comment-directives in ` `, - errors: [{ - message: "'.sync' modifiers cannot update the iteration variable 'x' itself.", - line: 4, - column: 26, - endColumn: 39 - }] + errors: [ + { + message: + "'.sync' modifiers cannot update the iteration variable 'x' itself.", + line: 4, + column: 26, + endColumn: 39 + } + ] }, { filename: 'test.vue', @@ -230,12 +263,15 @@ tester.run('valid-v-bind-sync', rule, { `, - errors: [{ - message: "'.sync' modifiers cannot update the iteration variable 'e' itself.", - line: 4, - column: 26, - endColumn: 45 - }] + errors: [ + { + message: + "'.sync' modifiers cannot update the iteration variable 'e' itself.", + line: 4, + column: 26, + endColumn: 45 + } + ] }, { filename: 'test.vue', @@ -250,10 +286,13 @@ tester.run('valid-v-bind-sync', rule, { `, - errors: [{ - message: "'.sync' modifiers cannot update the iteration variable 'e1' itself.", - line: 6 - }] + errors: [ + { + message: + "'.sync' modifiers cannot update the iteration variable 'e1' itself.", + line: 6 + } + ] }, { filename: 'test.vue', @@ -264,10 +303,13 @@ tester.run('valid-v-bind-sync', rule, { `, - errors: [{ - message: "'.sync' modifiers cannot update the iteration variable 'index' itself.", - line: 4 - }] + errors: [ + { + message: + "'.sync' modifiers cannot update the iteration variable 'index' itself.", + line: 4 + } + ] }, { filename: 'test.vue', @@ -276,17 +318,23 @@ tester.run('valid-v-bind-sync', rule, {
`, - errors: ["'.sync' modifiers aren't supported on
non Vue-components."] + errors: [ + "'.sync' modifiers aren't supported on
non Vue-components." + ] }, { filename: 'test.vue', code: '', - errors: ["'.sync' modifiers require the attribute value which is valid as LHS."] + errors: [ + "'.sync' modifiers require the attribute value which is valid as LHS." + ] }, { filename: 'test.vue', code: '', - errors: ["'.sync' modifiers require the attribute value which is valid as LHS."] + errors: [ + "'.sync' modifiers require the attribute value which is valid as LHS." + ] } ] }) diff --git a/tests/lib/rules/valid-v-else-if.js b/tests/lib/rules/valid-v-else-if.js index b0c18093f..778d07339 100644 --- a/tests/lib/rules/valid-v-else-if.js +++ b/tests/lib/rules/valid-v-else-if.js @@ -29,11 +29,13 @@ tester.run('valid-v-else-if', rule, { }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', @@ -43,57 +45,82 @@ tester.run('valid-v-else-if', rule, { invalid: [ { filename: 'test.vue', - code: '', - errors: ["'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + code: + '', + errors: [ + "'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', code: '', - errors: ["'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + errors: [ + "'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', code: '', - errors: ["'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + errors: [ + "'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + code: + '', + errors: [ + "'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + code: + '', + errors: [ + "'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + code: + '', + errors: [ + "'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else-if' and 'v-if' directives can't exist on the same element."] + code: + '', + errors: [ + "'v-else-if' and 'v-if' directives can't exist on the same element." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else-if' and 'v-else' directives can't exist on the same element."] + code: + '', + errors: [ + "'v-else-if' and 'v-else' directives can't exist on the same element." + ] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["'v-else-if' directives require no argument."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["'v-else-if' directives require no modifier."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["'v-else-if' directives require that attribute value."] } ] diff --git a/tests/lib/rules/valid-v-else.js b/tests/lib/rules/valid-v-else.js index 7825e4dfb..1e235f9b5 100644 --- a/tests/lib/rules/valid-v-else.js +++ b/tests/lib/rules/valid-v-else.js @@ -29,11 +29,13 @@ tester.run('valid-v-else', rule, { }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', @@ -44,56 +46,79 @@ tester.run('valid-v-else', rule, { { filename: 'test.vue', code: '', - errors: ["'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + errors: [ + "'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', code: '', - errors: ["'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + errors: [ + "'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', code: '', - errors: ["'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + errors: [ + "'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', code: '', - errors: ["'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + errors: [ + "'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + code: + '', + errors: [ + "'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."] + code: + '', + errors: [ + "'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else' and 'v-if' directives can't exist on the same element. You may want 'v-else-if' directives."] + code: + '', + errors: [ + "'v-else' and 'v-if' directives can't exist on the same element. You may want 'v-else-if' directives." + ] }, { filename: 'test.vue', - code: '', - errors: ["'v-else' and 'v-else-if' directives can't exist on the same element."] + code: + '', + errors: [ + "'v-else' and 'v-else-if' directives can't exist on the same element." + ] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["'v-else' directives require no argument."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["'v-else' directives require no modifier."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["'v-else' directives require no attribute value."] } ] diff --git a/tests/lib/rules/valid-v-for.js b/tests/lib/rules/valid-v-for.js index d83b634a3..74a1ea614 100644 --- a/tests/lib/rules/valid-v-for.js +++ b/tests/lib/rules/valid-v-for.js @@ -37,55 +37,68 @@ tester.run('valid-v-for', rule, { }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', - code: '' + code: + '' }, { filename: 'test.vue', @@ -134,92 +147,123 @@ tester.run('valid-v-for', rule, { }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Invalid alias ''."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Invalid alias ''."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Invalid alias ''."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Invalid alias '{b,c}'."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Invalid alias '{c,d}'."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Custom elements in iteration require 'v-bind:key' directives."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Custom elements in iteration require 'v-bind:key' directives."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Custom elements in iteration require 'v-bind:key' directives."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Custom elements in iteration require 'v-bind:key' directives."] }, { filename: 'test.vue', - code: '', - errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."] + code: + '', + errors: [ + "Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."] + code: + '', + errors: [ + "Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."] + code: + '', + errors: [ + "Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."] + code: + '', + errors: [ + "Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive." + ] }, { filename: 'test.vue', - code: '', - errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."] + code: + '', + errors: [ + "Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive." + ] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["Custom elements in iteration require 'v-bind:key' directives."] }, { filename: 'test.vue', - code: '', + code: + '', errors: ["'v-for' directives require that attribute value."] }, { filename: 'test.vue', - code: '', - errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."] + code: + '', + errors: [ + "Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive." + ] }, { filename: 'test.vue', - errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."], + errors: [ + "Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive." + ], code: ` ` + }, + // empty value + { + filename: 'empty-value.vue', + code: '', + errors: ["'v-for' directives require that attribute value."] } ] }) diff --git a/tests/lib/rules/valid-v-html.js b/tests/lib/rules/valid-v-html.js index 9a30bcf48..afb312f74 100644 --- a/tests/lib/rules/valid-v-html.js +++ b/tests/lib/rules/valid-v-html.js @@ -30,6 +30,16 @@ tester.run('valid-v-html', rule, { { filename: 'test.vue', code: '' + }, + // parsing error + { + filename: 'parsing-error.vue', + code: '' + }, + // comment value (parsing error) + { + filename: 'comment-value.vue', + code: '' } ], invalid: [ @@ -47,6 +57,12 @@ tester.run('valid-v-html', rule, { filename: 'test.vue', code: '', errors: ["'v-html' directives require that attribute value."] + }, + // empty value + { + filename: 'empty-value.vue', + code: '', + errors: ["'v-html' directives require that attribute value."] } ] }) diff --git a/tests/lib/rules/valid-v-if.js b/tests/lib/rules/valid-v-if.js index effe04836..d3afe5780 100644 --- a/tests/lib/rules/valid-v-if.js +++ b/tests/lib/rules/valid-v-if.js @@ -30,6 +30,16 @@ tester.run('valid-v-if', rule, { { filename: 'test.vue', code: '' + }, + // parsing error + { + filename: 'parsing-error.vue', + code: '' + }, + // comment value (parsing error) + { + filename: 'comment-value.vue', + code: '' } ], invalid: [ @@ -62,6 +72,12 @@ tester.run('valid-v-if', rule, { filename: 'test.vue', code: '', errors: ["'v-if' directives require that attribute value."] + }, + // empty value + { + filename: 'empty-value.vue', + code: '', + errors: ["'v-if' directives require that attribute value."] } ] }) diff --git a/tests/lib/rules/valid-v-model.js b/tests/lib/rules/valid-v-model.js index c9c28585a..9e78ef47a 100644 --- a/tests/lib/rules/valid-v-model.js +++ b/tests/lib/rules/valid-v-model.js @@ -150,6 +150,16 @@ tester.run('valid-v-model', rule, { filename: 'test.vue', code: '' + }, + // parsing error + { + filename: 'parsing-error.vue', + code: '' + }, + // comment value (parsing error) + { + filename: 'comment-value.vue', + code: '' } ], invalid: [ @@ -216,6 +226,12 @@ tester.run('valid-v-model', rule, { errors: [ "'v-model' directives cannot update the iteration variable 'e' itself." ] + }, + // empty value + { + filename: 'empty-value.vue', + code: '', + errors: ["'v-model' directives require that attribute value."] } ] }) diff --git a/tests/lib/rules/valid-v-on.js b/tests/lib/rules/valid-v-on.js index 911039ea5..6f162e1df 100644 --- a/tests/lib/rules/valid-v-on.js +++ b/tests/lib/rules/valid-v-on.js @@ -96,6 +96,33 @@ tester.run('valid-v-on', rule, { filename: 'test.vue', code: '', options: [{ modifiers: ['bar', 'aaa'] }] + }, + // parsing error + { + filename: 'parsing-error.vue', + code: '' + }, + // comment value (valid) + { + filename: 'comment-value.vue', + code: '' + }, + { + filename: 'comment-value.vue', + code: '' + }, + { + filename: 'comment-value.vue', + code: '' + }, + { + filename: 'comment-value.vue', + code: '' + }, + // empty value + { + filename: 'empty-value.vue', + code: '' } ], invalid: [ @@ -139,6 +166,14 @@ tester.run('valid-v-on', rule, { filename: 'test.vue', code: '', errors: ['Avoid using JavaScript keyword as "v-on" value: "delete".'] + }, + // empty value + { + filename: 'empty-value.vue', + code: '', + errors: [ + "'v-on' directives require a value or verb modifier (like 'stop' or 'prevent')." + ] } ] }) diff --git a/tests/lib/rules/valid-v-once.js b/tests/lib/rules/valid-v-once.js index 0c6a71a20..c9f3750c3 100644 --- a/tests/lib/rules/valid-v-once.js +++ b/tests/lib/rules/valid-v-once.js @@ -47,6 +47,24 @@ tester.run('valid-v-once', rule, { filename: 'test.vue', code: '', errors: ["'v-once' directives require no attribute value."] + }, + // parsing error + { + filename: 'parsing-error.vue', + code: '', + errors: ["'v-once' directives require no attribute value."] + }, + // comment value + { + filename: 'comment-value.vue', + code: '', + errors: ["'v-once' directives require no attribute value."] + }, + // empty value + { + filename: 'comment-value.vue', + code: '', + errors: ["'v-once' directives require no attribute value."] } ] }) diff --git a/tests/lib/rules/valid-v-pre.js b/tests/lib/rules/valid-v-pre.js index ae9d38e6f..3d9c9d883 100644 --- a/tests/lib/rules/valid-v-pre.js +++ b/tests/lib/rules/valid-v-pre.js @@ -47,6 +47,24 @@ tester.run('valid-v-pre', rule, { filename: 'test.vue', code: '', errors: ["'v-pre' directives require no attribute value."] + }, + // parsing error + { + filename: 'parsing-error.vue', + code: '', + errors: ["'v-pre' directives require no attribute value."] + }, + // comment value + { + filename: 'comment-value.vue', + code: '', + errors: ["'v-pre' directives require no attribute value."] + }, + // empty value + { + filename: 'empty-value.vue', + code: '', + errors: ["'v-pre' directives require no attribute value."] } ] }) diff --git a/tests/lib/rules/valid-v-show.js b/tests/lib/rules/valid-v-show.js index 0471ccd9f..4220e8749 100644 --- a/tests/lib/rules/valid-v-show.js +++ b/tests/lib/rules/valid-v-show.js @@ -30,6 +30,16 @@ tester.run('valid-v-show', rule, { { filename: 'test.vue', code: '' + }, + // parsing error + { + filename: 'parsing-error.vue', + code: '' + }, + // comment value (parsing error) + { + filename: 'comment-value.vue', + code: '' } ], invalid: [ @@ -48,8 +58,9 @@ tester.run('valid-v-show', rule, { code: '', errors: ["'v-show' directives require that attribute value."] }, + // empty value { - filename: 'test.vue', + filename: 'empty-value.vue', code: '', errors: ["'v-show' directives require that attribute value."] } diff --git a/tests/lib/rules/valid-v-slot.js b/tests/lib/rules/valid-v-slot.js index ab8307fed..0043756f1 100644 --- a/tests/lib/rules/valid-v-slot.js +++ b/tests/lib/rules/valid-v-slot.js @@ -83,7 +83,13 @@ tester.run('valid-v-slot', rule, { - ` + `, + // parsing error + { + filename: 'parsing-error.vue', + code: + '' + } ], invalid: [ // Verify location. @@ -294,6 +300,26 @@ tester.run('valid-v-slot', rule, { `, errors: [{ messageId: 'requireAttributeValue' }] + }, + // comment value + { + filename: 'comment-value1.vue', + code: + '', + errors: [{ messageId: 'requireAttributeValue' }] + }, + { + filename: 'comment-value2.vue', + code: + '', + errors: [{ messageId: 'requireAttributeValue' }] + }, + // empty value + { + filename: 'empty-value.vue', + code: + '', + errors: [{ messageId: 'requireAttributeValue' }] } ] }) diff --git a/tests/lib/rules/valid-v-text.js b/tests/lib/rules/valid-v-text.js index 3956462ce..611b1a31a 100644 --- a/tests/lib/rules/valid-v-text.js +++ b/tests/lib/rules/valid-v-text.js @@ -34,6 +34,16 @@ tester.run('valid-v-text', rule, { { filename: 'test.vue', code: '' + }, + // parsing error + { + filename: 'parsing-error.vue', + code: '' + }, + // comment value (parsing error) + { + filename: 'parsing-error.vue', + code: '' } ], invalid: [ @@ -51,6 +61,12 @@ tester.run('valid-v-text', rule, { filename: 'test.vue', code: '', errors: ["'v-text' directives require that attribute value."] + }, + // empty value + { + filename: 'empty-value.vue', + code: '', + errors: ["'v-text' directives require that attribute value."] } ] }) From e5c835eb957340b153ea2047e3ba274b88ba01bb Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 5 Jun 2020 14:29:35 +0900 Subject: [PATCH 0381/1157] Add `vue/no-bare-strings-in-template` rule (#1185) --- docs/rules/README.md | 1 + docs/rules/no-bare-strings-in-template.md | 88 ++++++ lib/index.js | 1 + lib/rules/no-bare-strings-in-template.js | 279 +++++++++++++++++ lib/utils/regexp.js | 14 +- package.json | 2 + .../lib/rules/no-bare-strings-in-template.js | 290 ++++++++++++++++++ 7 files changed, 673 insertions(+), 2 deletions(-) create mode 100644 docs/rules/no-bare-strings-in-template.md create mode 100644 lib/rules/no-bare-strings-in-template.js create mode 100644 tests/lib/rules/no-bare-strings-in-template.js diff --git a/docs/rules/README.md b/docs/rules/README.md index f3e2bfdf6..55b3c4e0d 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -282,6 +282,7 @@ For example: | [vue/html-comment-content-spacing](./html-comment-content-spacing.md) | enforce unified spacing in HTML comments | :wrench: | | [vue/html-comment-indent](./html-comment-indent.md) | enforce consistent indentation in HTML comments | :wrench: | | [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | | +| [vue/no-bare-strings-in-template](./no-bare-strings-in-template.md) | disallow the use of bare strings in ` `, - options: [{ ignoreWhenEmpty: false, ignoreWhenNoAttributes: false }], output: ` `, + options: [{ ignoreWhenEmpty: false, ignoreWhenNoAttributes: false }], errors: [ 'Expected 1 line break after opening tag (`
`), but no line breaks found.' ] @@ -473,13 +473,13 @@ singleline element
`, - options: [{ ignoreWhenEmpty: false, ignoreWhenNoAttributes: false }], output: ` `, + options: [{ ignoreWhenEmpty: false, ignoreWhenNoAttributes: false }], errors: [ 'Expected 1 line break after opening tag (`
`), but no line breaks found.' ] diff --git a/tests/lib/rules/space-in-parens.js b/tests/lib/rules/space-in-parens.js index 8791652ed..ef6fe628e 100644 --- a/tests/lib/rules/space-in-parens.js +++ b/tests/lib/rules/space-in-parens.js @@ -94,13 +94,13 @@ tester.run('space-in-parens', rule, { @click="foo(arg)" /> `, - options: ['always'], output: ` `, + options: ['always'], errors: [ errorMessage({ messageId: 'missingOpeningSpace', @@ -143,13 +143,13 @@ tester.run('space-in-parens', rule, { :value="(1 + 2) + 3" > `, - options: ['always'], output: ` `, + options: ['always'], errors: [ errorMessage({ messageId: 'missingOpeningSpace', @@ -192,13 +192,13 @@ tester.run('space-in-parens', rule, { :[(1+2)]="(1 + 2) + 3" > `, - options: ['always'], output: ` `, + options: ['always'], errors: [ errorMessage({ messageId: 'missingOpeningSpace', diff --git a/tests/lib/rules/space-unary-ops.js b/tests/lib/rules/space-unary-ops.js index 6b3e7c25f..63539a5a7 100644 --- a/tests/lib/rules/space-unary-ops.js +++ b/tests/lib/rules/space-unary-ops.js @@ -50,8 +50,8 @@ tester.run('space-unary-ops', rule, { }, { code: '', - options: [{ nonwords: true }], output: '', + options: [{ nonwords: true }], errors: ["Unary operator '!' must be followed by whitespace."] }, diff --git a/tests/lib/rules/template-curly-spacing.js b/tests/lib/rules/template-curly-spacing.js index 6c4376969..0fe530511 100644 --- a/tests/lib/rules/template-curly-spacing.js +++ b/tests/lib/rules/template-curly-spacing.js @@ -41,14 +41,13 @@ tester.run('template-curly-spacing', rule, { }, // CSS vars injection - { - code: ` + ` ` - } + + ` ], invalid: [ { @@ -79,12 +78,12 @@ tester.run('template-curly-spacing', rule, {
`, - options: ['always'], output: ` `, + options: ['always'], errors: [ { message: "Expected space(s) after '${'.", diff --git a/tests/lib/rules/this-in-template.js b/tests/lib/rules/this-in-template.js index 904aa00c4..5686bf137 100644 --- a/tests/lib/rules/this-in-template.js +++ b/tests/lib/rules/this-in-template.js @@ -248,14 +248,14 @@ ruleTester.run('this-in-template', rule, { { code: ``, output: ``, - errors: ["Unexpected usage of 'this'."], - options: ['never'] + options: ['never'], + errors: ["Unexpected usage of 'this'."] }, { code: ``, output: ``, - errors: ["Unexpected usage of 'this'."], - options: ['never'] + options: ['never'], + errors: ["Unexpected usage of 'this'."] } ] }) diff --git a/tests/lib/rules/use-v-on-exact.js b/tests/lib/rules/use-v-on-exact.js index 73ac2408b..929fd746a 100644 --- a/tests/lib/rules/use-v-on-exact.js +++ b/tests/lib/rules/use-v-on-exact.js @@ -15,92 +15,48 @@ const ruleTester = new RuleTester({ ruleTester.run('use-v-on-exact', rule, { valid: [ - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: `` - }, - { - code: ` + ` ], invalid: [ diff --git a/tests/lib/rules/v-bind-style.js b/tests/lib/rules/v-bind-style.js index 2fd1ce7c2..0cb67f62f 100644 --- a/tests/lib/rules/v-bind-style.js +++ b/tests/lib/rules/v-bind-style.js @@ -67,44 +67,44 @@ tester.run('v-bind-style', rule, { }, { filename: 'test.vue', - options: ['shorthand'], code: '', output: '', + options: ['shorthand'], errors: ["Unexpected 'v-bind' before ':'."] }, { filename: 'test.vue', - options: ['longform'], code: '', output: '', + options: ['longform'], errors: ["Expected 'v-bind' before ':'."] }, { filename: 'test.vue', - options: ['longform'], code: '', output: '', + options: ['longform'], errors: ["Expected 'v-bind:' instead of '.'."] }, { filename: 'test.vue', - options: ['longform'], code: '', output: '', + options: ['longform'], errors: ["Expected 'v-bind:' instead of '.'."] }, { filename: 'test.vue', - options: ['longform'], code: '', output: '', + options: ['longform'], errors: ["Expected 'v-bind:' instead of '.'."] }, { filename: 'test.vue', - options: ['longform'], code: '', output: '', + options: ['longform'], errors: ["Expected 'v-bind:' instead of '.'."] } ] diff --git a/tests/lib/rules/v-for-delimiter-style.js b/tests/lib/rules/v-for-delimiter-style.js index b1500af50..23665a32c 100644 --- a/tests/lib/rules/v-for-delimiter-style.js +++ b/tests/lib/rules/v-for-delimiter-style.js @@ -94,9 +94,9 @@ tester.run('v-for-delimiter-style', rule, { }, { filename: 'test.vue', - options: ['in'], code: '', output: '', + options: ['in'], errors: [ { message: "Expected 'in' instead of 'of' in 'v-for'.", @@ -106,9 +106,9 @@ tester.run('v-for-delimiter-style', rule, { }, { filename: 'test.vue', - options: ['of'], code: '', output: '', + options: ['of'], errors: [ { message: "Expected 'of' instead of 'in' in 'v-for'.", diff --git a/tests/lib/rules/v-on-event-hyphenation.js b/tests/lib/rules/v-on-event-hyphenation.js index 087e5d00a..beaa5e3fa 100644 --- a/tests/lib/rules/v-on-event-hyphenation.js +++ b/tests/lib/rules/v-on-event-hyphenation.js @@ -73,12 +73,12 @@ tester.run('v-on-event-hyphenation', rule, { `, - options: ['always', { autofix: true }], output: ` `, + options: ['always', { autofix: true }], errors: [ { message: "v-on event '@customEvent' must be hyphenated.", @@ -95,12 +95,12 @@ tester.run('v-on-event-hyphenation', rule, { `, - options: ['never', { autofix: true }], output: ` `, + options: ['never', { autofix: true }], errors: ["v-on event 'v-on:custom-event' can't be hyphenated."] }, { @@ -110,13 +110,13 @@ tester.run('v-on-event-hyphenation', rule, { `, - options: ['always', { autofix: true }], output: ` `, + options: ['always', { autofix: true }], errors: ["v-on event '@update:modelValue' must be hyphenated."] }, { @@ -126,13 +126,13 @@ tester.run('v-on-event-hyphenation', rule, { `, - options: ['never', { autofix: true }], output: ` `, + options: ['never', { autofix: true }], errors: ["v-on event '@update:model-value' can't be hyphenated."] }, { @@ -144,7 +144,6 @@ tester.run('v-on-event-hyphenation', rule, { `, - options: ['always', { autofix: true }], output: ` `, + options: ['always', { autofix: true }], errors: [ "v-on event '@upDate:modelValue' must be hyphenated.", "v-on event '@up-date:modelValue' must be hyphenated.", @@ -168,7 +168,6 @@ tester.run('v-on-event-hyphenation', rule, { `, - options: ['never', { autofix: true }], output: ` `, + options: ['never', { autofix: true }], errors: [ "v-on event '@up-date:modelValue' can't be hyphenated.", "v-on event '@upDate:model-value' can't be hyphenated.", diff --git a/tests/lib/rules/v-on-function-call.js b/tests/lib/rules/v-on-function-call.js index d8486a448..d06bbe231 100644 --- a/tests/lib/rules/v-on-function-call.js +++ b/tests/lib/rules/v-on-function-call.js @@ -161,37 +161,37 @@ tester.run('v-on-function-call', rule, { filename: 'test.vue', code: '', output: null, + options: ['always'], errors: [ "Method calls inside of 'v-on' directives must have parentheses." - ], - options: ['always'] + ] }, { filename: 'test.vue', code: '', output: ``, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', code: '', output: ``, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', code: '', output: null, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', @@ -204,13 +204,13 @@ tester.run('v-on-function-call', rule, { ">
`, output: null, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses.", "Method calls without arguments inside of 'v-on' directives must not have parentheses.", "Method calls without arguments inside of 'v-on' directives must not have parentheses.", "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', @@ -222,10 +222,10 @@ tester.run('v-on-function-call', rule, { `, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', @@ -237,10 +237,10 @@ tester.run('v-on-function-call', rule, { `, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', @@ -254,11 +254,11 @@ tester.run('v-on-function-call', rule, {
`, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses.", "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', @@ -270,10 +270,10 @@ tester.run('v-on-function-call', rule, { `, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', @@ -285,19 +285,19 @@ tester.run('v-on-function-call', rule, { `, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', code: '', output: '', + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', @@ -319,10 +319,10 @@ tester.run('v-on-function-call', rule, { } } `, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] }, { filename: 'test.vue', @@ -344,10 +344,10 @@ tester.run('v-on-function-call', rule, { } } `, + options: ['never'], errors: [ "Method calls without arguments inside of 'v-on' directives must not have parentheses." - ], - options: ['never'] + ] } ] }) diff --git a/tests/lib/rules/v-on-handler-style.js b/tests/lib/rules/v-on-handler-style.js index e3afd05d5..314bbf8c8 100644 --- a/tests/lib/rules/v-on-handler-style.js +++ b/tests/lib/rules/v-on-handler-style.js @@ -78,12 +78,12 @@ tester.run('v-on-handler-style', rule, {