diff --git a/docs/rules/component-name-in-template-casing.md b/docs/rules/component-name-in-template-casing.md index c2bd52900..5f73bdc4a 100644 --- a/docs/rules/component-name-in-template-casing.md +++ b/docs/rules/component-name-in-template-casing.md @@ -20,7 +20,8 @@ This rule aims to warn the tag names other than the configured casing in Vue.js ```json { - "vue/component-name-in-template-casing": ["error", "PascalCase" | "kebab-case", { + "vue/component-name-in-template-casing": ["error", "PascalCase" | "kebab-case", { + "registeredComponentsOnly": true, "ignores": [] }] } @@ -28,22 +29,40 @@ This rule aims to warn the tag names other than the configured casing in Vue.js - `"PascalCase"` (default) ... enforce tag names to pascal case. E.g. ``. This is consistent with the JSX practice. - `"kebab-case"` ... enforce tag names to kebab case: E.g. ``. This is consistent with the HTML practice which is case-insensitive originally. -- `ignores` (`string[]`) ... The element names to ignore. Sets the element name to allow. For example, a custom element or a non-Vue component. +- `registeredComponentsOnly` ... If `true`, only registered components (in PascalCase) are checked. If `false`, check all. + default `true` +- `ignores` (`string[]`) ... The element names to ignore. Sets the element name to allow. For example, custom elements or Vue components with special name. You can set the regexp by writing it like `"/^name/"`. -### `"PascalCase"` +### `"PascalCase", { registeredComponentsOnly: true }` (default) ```vue + ``` @@ -55,28 +74,64 @@ This rule aims to warn the tag names other than the configured casing in Vue.js ```vue + ``` +### `"PascalCase", { registeredComponentsOnly: false }` + + + +```vue + + +``` + + -### `"PascalCase", { ignores: ["custom-element"] }` +### `"PascalCase", { ignores: ["/^custom-/"], registeredComponentsOnly: false }` - + ```vue + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "the-component" is not PascalCase.'] }, @@ -109,13 +275,25 @@ tester.run('component-name-in-template-casing', rule, { content + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "the-component" is not PascalCase.'] }, @@ -124,11 +302,23 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "the-component" is not PascalCase.'] }, @@ -139,7 +329,13 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', options: ['kebab-case'], output: ` + `, errors: ['Component name "TheComponent" is not kebab-case.'] }, @@ -156,7 +357,7 @@ tester.run('component-name-in-template-casing', rule, { `, - options: ['kebab-case'], + options: ['kebab-case', { registeredComponentsOnly: false }], output: ` + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "the-component" is not PascalCase.'] }, @@ -184,11 +397,23 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "the-component" is not PascalCase.'] }, @@ -197,11 +422,23 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "the-component" is not PascalCase.'] }, @@ -210,11 +447,23 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "theComponent" is not PascalCase.'] }, @@ -223,12 +472,23 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', options: ['kebab-case'], output: ` + `, errors: ['Component name "theComponent" is not kebab-case.'] }, @@ -237,11 +497,23 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "The-component" is not PascalCase.'] }, @@ -250,12 +522,23 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', options: ['kebab-case'], output: ` + `, errors: ['Component name "The-component" is not kebab-case.'] }, @@ -265,7 +548,7 @@ tester.run('component-name-in-template-casing', rule, { `, - options: ['kebab-case'], + options: ['kebab-case', { registeredComponentsOnly: false }], output: ` + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "the-component" is not PascalCase.'] }, @@ -306,11 +613,23 @@ tester.run('component-name-in-template-casing', rule, { + `, + filename: 'test.vue', + options: ['PascalCase'], output: ` + `, errors: ['Component name "the-component" is not PascalCase.'] }, @@ -319,18 +638,28 @@ tester.run('component-name-in-template-casing', rule, { { code: ` `, output: ` `, - options: ['PascalCase', { ignores: ['custom-element'] }], - errors: ['Component name "the-component" is not PascalCase.'] + options: ['PascalCase', { + ignores: ['custom-element1', 'custom-element2'], + registeredComponentsOnly: false + }], + errors: [ + 'Component name "the-component" is not PascalCase.', + 'Component name "the-component" is not PascalCase.' + ] }, { code: ` @@ -349,7 +678,10 @@ tester.run('component-name-in-template-casing', rule, { `, - options: ['PascalCase', { ignores: ['custom-element1', 'custom-element2'] }], + options: ['PascalCase', { + ignores: ['/^custom-element/'], + registeredComponentsOnly: false + }], errors: [ 'Component name "the-component" is not PascalCase.', 'Component name "the-component" is not PascalCase.' diff --git a/tests/lib/utils/regexp.js b/tests/lib/utils/regexp.js new file mode 100644 index 000000000..8e38a9687 --- /dev/null +++ b/tests/lib/utils/regexp.js @@ -0,0 +1,40 @@ +'use strict' + +const { escape, toRegExp } = require('../../../lib/utils/regexp') +const chai = require('chai') + +const assert = chai.assert + +const ESCAPED = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\' +const UNESCAPED = '^$.*+?()[]{}|\\' + +describe('escape()', () => { + it('should escape values', () => { + assert.strictEqual(escape(UNESCAPED), ESCAPED) + assert.strictEqual(escape(UNESCAPED + UNESCAPED), ESCAPED + ESCAPED) + }) + + it('should handle strings with nothing to escape', () => { + assert.strictEqual(escape('abc'), 'abc') + }) + + it('should return an empty string for empty values', () => { + assert.strictEqual(escape(null), null) + assert.strictEqual(escape(undefined), undefined) + assert.strictEqual(escape(''), '') + }) +}) + +describe('toRegExp()', () => { + it('should be convert to RegExp', () => { + assert.deepEqual(toRegExp('foo'), /^foo$/) + assert.deepEqual(toRegExp(UNESCAPED), new RegExp(`^${ESCAPED}$`)) + }) + + it('RegExp like string should be convert to RegExp', () => { + assert.deepEqual(toRegExp('/^foo/i'), /^foo/i) + assert.deepEqual(toRegExp('/.*/iu'), /.*/iu) + assert.deepEqual(toRegExp(`${/^bar/i}`), /^bar/i) + assert.deepEqual(toRegExp(`${/[\sA-Z]+/u}`), /[\sA-Z]+/u) + }) +})