Skip to content

Commit

Permalink
[Fix] boolean-prop-naming: improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 8, 2024
1 parent 48291e8 commit a920463
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const report = require('../util/report');
// ------------------------------------------------------------------------------

const messages = {
patternMismatch: 'Prop name ({{propName}}) doesn\'t match rule ({{pattern}})',
patternMismatch: 'Prop name `{{propName}}` doesnt match rule `{{pattern}}`',
};

module.exports = {
Expand Down
84 changes: 68 additions & 16 deletions tests/lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,12 +1106,16 @@ ruleTester.run('boolean-prop-naming', rule, {
enabled: boolean
}
const HelloNew = (props: TestConstType) => { return <div /> };
`,
`,
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
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]?)+',
},
},
],
},
Expand All @@ -1121,12 +1125,16 @@ ruleTester.run('boolean-prop-naming', rule, {
enabled: boolean
}
const HelloNew = (props: TestFNType) => { return <div /> };
`,
`,
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
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]?)+',
},
},
],
},
Expand All @@ -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]?)+',
},
},
],
},
Expand All @@ -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]?)+',
},
},
],
},
Expand All @@ -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]?)+',
},
},
],
},
Expand All @@ -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]?)+',
},
},
],
},
Expand All @@ -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]?)+',
},
},
],
},
Expand All @@ -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]?)+',
},
},
],
},
Expand All @@ -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]?)+',
},
},
],
},
Expand All @@ -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]?)+',
},
},
],
},
Expand All @@ -1272,17 +1316,25 @@ ruleTester.run('boolean-prop-naming', rule, {
type BaseProps = {
semi: boolean
}
const Hello = (props: Props & BaseProps) => <div />;
`,
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]?)+',
},
},
],
},
Expand Down

0 comments on commit a920463

Please sign in to comment.