diff --git a/CHANGELOG.md b/CHANGELOG.md index 937ded5283..e307437ab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`boolean-prop-naming`]: literalType error fix ([#3704][] @developer-bandi) * [`boolean-prop-naming`]: allow TSIntersectionType ([#3705][] @developer-bandi) +### Changed +* [`boolean-prop-naming`]: improve error message (@ljharb) + [#3705]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3705 [#3704]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3704 [#3701]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3701 diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index 2ed70cbfde..6d63feb17e 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -19,7 +19,7 @@ const report = require('../util/report'); // ------------------------------------------------------------------------------ const messages = { - patternMismatch: 'Prop name ({{propName}}) doesn\'t match rule ({{pattern}})', + patternMismatch: 'Prop name `{{propName}}` doesn’t match rule `{{pattern}}`', }; module.exports = { diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index 18932bb215..a09a6b3fce 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -1111,7 +1111,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['ts', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^is[A-Z]([A-Za-z0-9]?)+', + } }, ], }, @@ -1126,7 +1130,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['ts', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^is[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1142,7 +1150,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['types', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^is[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1160,7 +1172,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['types', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1176,7 +1192,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['types', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^is[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1194,7 +1214,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['types', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1212,7 +1236,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['types', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1232,10 +1260,18 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['types', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + }, }, { - message: 'Prop name (lol) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'lol', + pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1250,7 +1286,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['ts', 'no-babel'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^is[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1260,7 +1300,11 @@ ruleTester.run('boolean-prop-naming', rule, { features: ['ts', 'no-babel'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + }, }, ], }, @@ -1272,17 +1316,25 @@ ruleTester.run('boolean-prop-naming', rule, { type BaseProps = { semi: boolean } - + const Hello = (props: Props & BaseProps) =>
; `, options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }], features: ['ts', 'no-babel', 'no-ts-old'], errors: [ { - message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'enabled', + pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + }, }, { - message: 'Prop name (semi) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)', + messageId: 'patternMismatch', + data: { + propName: 'semi', + pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + }, }, ], },