From d626ec1b589559507637a3e5617ae88fafe0c27f Mon Sep 17 00:00:00 2001 From: arrudaje Date: Sun, 18 Oct 2020 15:14:25 +0200 Subject: [PATCH 01/11] Make rule vue/no-unregistered-components ignore recursive components (#1305) * Add tests * Modify rule to include `ignoreRecursive` argument * Modify docs * Address PR comments * empty commit * Refactor no-unregistered-components to always bypass recursive components * Update docs Co-authored-by: Joao Elias Arruda --- lib/rules/no-unregistered-components.js | 9 +++ tests/lib/rules/no-unregistered-components.js | 65 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/lib/rules/no-unregistered-components.js b/lib/rules/no-unregistered-components.js index be892a6e6..7ec74e503 100644 --- a/lib/rules/no-unregistered-components.js +++ b/lib/rules/no-unregistered-components.js @@ -181,6 +181,15 @@ module.exports = { }, utils.executeOnVue(context, (obj) => { registeredComponents.push(...utils.getRegisteredComponents(obj)) + + const nameProperty = utils.findProperty(obj, 'name') + + if (nameProperty) { + registeredComponents.push({ + node: nameProperty, + name: nameProperty.value.value + }) + } }) ) } diff --git a/tests/lib/rules/no-unregistered-components.js b/tests/lib/rules/no-unregistered-components.js index da9e37ee2..367026909 100644 --- a/tests/lib/rules/no-unregistered-components.js +++ b/tests/lib/rules/no-unregistered-components.js @@ -393,6 +393,71 @@ tester.run('no-unregistered-components', rule, { } ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` } ], invalid: [ From 9932d13c37fdd7d0af1120d71209d107dddb4489 Mon Sep 17 00:00:00 2001 From: devTeaa Date: Sun, 18 Oct 2020 20:18:17 +0700 Subject: [PATCH 02/11] added options for events that ignore custom-event-name-casing (#1321) * added options for custom-event-name-casing * add test case to close #1260 * update docs for custom-event-name-casing * Update test case event name with regex Co-authored-by: Yosuke Ota * Update docs/rules/custom-event-name-casing.md for better description Co-authored-by: Yosuke Ota * updated custom-event-name-casing readme with ignores options * added custom-event-name-casing invalid test cases Co-authored-by: Yosuke Ota --- docs/rules/custom-event-name-casing.md | 42 ++++++- lib/rules/custom-event-name-casing.js | 21 +++- tests/lib/rules/custom-event-name-casing.js | 122 ++++++++++++++++++++ 3 files changed, 182 insertions(+), 3 deletions(-) diff --git a/docs/rules/custom-event-name-casing.md b/docs/rules/custom-event-name-casing.md index b4faacfbd..2b3dfb089 100644 --- a/docs/rules/custom-event-name-casing.md +++ b/docs/rules/custom-event-name-casing.md @@ -49,7 +49,47 @@ export default { ## :wrench: Options -Nothing. + +```json +{ + "vue/custom-event-name-casing": ["error", { + "ignores": [] + }] +} +``` +- `ignores` (`string[]`) ... The event names to ignore. Sets the event name to allow. For example, custom event names, Vue components event with special name, or Vue library component event name. You can set the regexp by writing it like `"/^name/"` or `click:row` or `fooBar`. + +### `"ignores": ["fooBar", "/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u"]` + + + +```vue + + +``` + + + ## :books: Further Reading diff --git a/lib/rules/custom-event-name-casing.js b/lib/rules/custom-event-name-casing.js index 6c5f072c3..7ed9335a2 100644 --- a/lib/rules/custom-event-name-casing.js +++ b/lib/rules/custom-event-name-casing.js @@ -11,6 +11,7 @@ const { findVariable } = require('eslint-utils') const utils = require('../utils') const { isKebabCase } = require('../utils/casing') +const { toRegExp } = require('../utils/regexp') // ------------------------------------------------------------------------------ // Helpers @@ -72,7 +73,20 @@ module.exports = { url: 'https://eslint.vuejs.org/rules/custom-event-name-casing.html' }, fixable: null, - schema: [], + schema: [ + { + type: 'object', + properties: { + ignores: { + type: 'array', + items: { type: 'string' }, + uniqueItems: true, + additionalItems: false + } + }, + additionalProperties: false + } + ], messages: { unexpected: "Custom event name '{{name}}' must be kebab-case." } @@ -80,13 +94,16 @@ module.exports = { /** @param {RuleContext} context */ create(context) { const setupContexts = new Map() + const options = context.options[0] || {} + /** @type {RegExp[]} */ + const ignores = (options.ignores || []).map(toRegExp) /** * @param { Literal & { value: string } } nameLiteralNode */ function verify(nameLiteralNode) { const name = nameLiteralNode.value - if (isValidEventName(name)) { + if (ignores.some((re) => re.test(name)) || isValidEventName(name)) { return } context.report({ diff --git a/tests/lib/rules/custom-event-name-casing.js b/tests/lib/rules/custom-event-name-casing.js index 934bb079f..ed0ba0eb5 100644 --- a/tests/lib/rules/custom-event-name-casing.js +++ b/tests/lib/rules/custom-event-name-casing.js @@ -166,6 +166,66 @@ tester.run('custom-event-name-casing', rule, { } ` + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [{ ignores: ['fooBar', 'barBaz', 'bazQux'] }] + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [{ ignores: ['/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u'] }] } ], invalid: [ @@ -276,6 +336,68 @@ tester.run('custom-event-name-casing', rule, { "Custom event name 'barBaz' must be kebab-case.", "Custom event name 'bazQux' must be kebab-case." ] + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [{ ignores: ['/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u'] }], + errors: [ + "Custom event name 'input/update' must be kebab-case.", + "Custom event name 'search/update' must be kebab-case.", + "Custom event name 'click/row' must be kebab-case." + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [{ ignores: ['input:update', 'search:update', 'click:row'] }], + errors: [ + "Custom event name 'input/update' must be kebab-case.", + "Custom event name 'search/update' must be kebab-case.", + "Custom event name 'click/row' must be kebab-case." + ] } ] }) From 0e1a05af34d054ae4c47b3a8f584b8af8a943aec Mon Sep 17 00:00:00 2001 From: nokazn <41154684+nokazn@users.noreply.github.com> Date: Sun, 18 Oct 2020 22:22:59 +0900 Subject: [PATCH 03/11] Add allowModifiers option to valid-v-slot (#1330) * add allowModifiers option to valid-v-slot * update doc * fix for missing cases & improve code * add test cases * revert option in test --- docs/rules/valid-v-slot.md | 38 ++++++++++++++- lib/rules/valid-v-slot.js | 40 +++++++++++++--- tests/lib/rules/valid-v-slot.js | 85 +++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 7 deletions(-) diff --git a/docs/rules/valid-v-slot.md b/docs/rules/valid-v-slot.md index 2a9183926..f0810cc75 100644 --- a/docs/rules/valid-v-slot.md +++ b/docs/rules/valid-v-slot.md @@ -100,7 +100,43 @@ This rule does not check syntax errors in directives because it's checked by [vu ## :wrench: Options -Nothing. +```json +{ + "vue/valid-v-slot": ["error", { + "allowModifiers": false + }] +} +``` + +- `allowModifiers` (`boolean`) ... allows having modifiers in the argument of `v-slot` directives. Modifiers just after `v-slot` are still disallowed. E.g. `