Skip to content

Commit 28843f7

Browse files
committed
[Fix] boolean-prop-naming: add missing default config
This might be semver-major, since the rule has never had any default behavior previously. Fixes #1551.
1 parent df6ec46 commit 28843f7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/rules/boolean-prop-naming.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const docsUrl = require('../util/docsUrl');
1313
// Rule Definition
1414
// ------------------------------------------------------------------------------
1515

16+
const ruleDefault = '^(is|has)[A-Z]([A-Za-z0-9]?)+';
17+
1618
module.exports = {
1719
meta: {
1820
docs: {
@@ -34,7 +36,7 @@ module.exports = {
3436
uniqueItems: true
3537
},
3638
rule: {
37-
default: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
39+
default: ruleDefault,
3840
minLength: 1,
3941
type: 'string'
4042
},
@@ -50,7 +52,8 @@ module.exports = {
5052
create: Components.detect((context, components, utils) => {
5153
const sourceCode = context.getSourceCode();
5254
const config = context.options[0] || {};
53-
const rule = config.rule ? new RegExp(config.rule) : null;
55+
const pattern = config.rule || ruleDefault;
56+
const rule = pattern ? new RegExp(pattern) : null;
5457
const propTypeNames = config.propTypeNames || ['bool'];
5558
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
5659

@@ -146,7 +149,7 @@ module.exports = {
146149
data: {
147150
component: propName,
148151
propName: propName,
149-
pattern: config.rule
152+
pattern: pattern
150153
}
151154
});
152155
});

tests/lib/rules/boolean-prop-naming.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ ruleTester.run('boolean-prop-naming', rule, {
351351
}],
352352

353353
invalid: [{
354+
// createReactClass components with PropTypes, default config
355+
code: `
356+
var Hello = createReactClass({
357+
propTypes: {something: PropTypes.bool},
358+
render: function() { return <div />; }
359+
});
360+
`,
361+
errors: [{
362+
message: 'Prop name (something) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)'
363+
}]
364+
}, {
354365
// createReactClass components with PropTypes
355366
code: `
356367
var Hello = createReactClass({

0 commit comments

Comments
 (0)