diff --git a/docs/rules/jsx-pascal-case.md b/docs/rules/jsx-pascal-case.md index 92430bfc27..14fcda99a8 100644 --- a/docs/rules/jsx-pascal-case.md +++ b/docs/rules/jsx-pascal-case.md @@ -46,7 +46,7 @@ Examples of **correct** code for this rule: * `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0. * `allowAllCaps`: optional boolean set to `true` to allow components name in all caps (default to `false`). -* `ignore`: optional string-array of component names to ignore during validation. +* `ignore`: optional string-array of component names to ignore during validation (supports [minimatch](https://github.com/isaacs/minimatch)-style globs). ### `allowAllCaps` @@ -59,4 +59,4 @@ Examples of **correct** code for this rule, when `allowAllCaps` is `true`: ## When Not To Use It -If you are not using JSX. \ No newline at end of file +If you are not using JSX. diff --git a/lib/rules/jsx-pascal-case.js b/lib/rules/jsx-pascal-case.js index d2ee51d4ea..14ceec4b2a 100644 --- a/lib/rules/jsx-pascal-case.js +++ b/lib/rules/jsx-pascal-case.js @@ -6,6 +6,7 @@ 'use strict'; const elementType = require('jsx-ast-utils/elementType'); +const minimatch = require('minimatch'); const docsUrl = require('../util/docsUrl'); const jsxUtil = require('../util/jsx'); @@ -79,7 +80,14 @@ module.exports = { type: 'boolean' }, ignore: { - type: 'array' + items: [ + { + type: 'string' + } + ], + minItems: 0, + type: 'array', + uniqueItems: true } }, additionalProperties: false @@ -109,7 +117,9 @@ module.exports = { const isPascalCase = testPascalCase(name); const isAllowedAllCaps = allowAllCaps && testAllCaps(name); - const isIgnored = ignore.indexOf(name) !== -1; + const isIgnored = ignore.some( + (entry) => name === entry || minimatch(name, entry, {noglobstar: true}) + ); if (!isPascalCase && !isAllowedAllCaps && !isIgnored) { let message = `Imported JSX component ${name} must be in PascalCase`; diff --git a/package.json b/package.json index 2870cbedb3..3df2769688 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "doctrine": "^2.1.0", "has": "^1.0.3", "jsx-ast-utils": "^2.4.1 || ^3.0.0", + "minimatch": "^3.0.4", "object.entries": "^1.1.2", "object.fromentries": "^2.0.2", "object.values": "^1.1.1", diff --git a/tests/lib/rules/jsx-pascal-case.js b/tests/lib/rules/jsx-pascal-case.js index e7bdc5af75..adb5ef8b3f 100644 --- a/tests/lib/rules/jsx-pascal-case.js +++ b/tests/lib/rules/jsx-pascal-case.js @@ -76,6 +76,12 @@ ruleTester.run('jsx-pascal-case', rule, { }, { code: '', options: [{ignore: ['IGNORED']}] + }, { + code: '', + options: [{ignore: ['*_D*D']}] + }, { + code: '', + options: [{ignore: ['*_+(DEPRECATED|IGNORED)']}] }, { code: '<$ />' }, { @@ -110,5 +116,9 @@ ruleTester.run('jsx-pascal-case', rule, { }, { code: '<$a />', errors: [{message: 'Imported JSX component $a must be in PascalCase'}] + }, { + code: '', + options: [{ignore: ['*_FOO']}], + errors: [{message: 'Imported JSX component Foo_DEPRECATED must be in PascalCase'}] }] });