Skip to content

Commit e26e595

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 b7665b7 commit e26e595

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

@@ -141,7 +144,7 @@ module.exports = {
141144
data: {
142145
component: propName,
143146
propName: propName,
144-
pattern: config.rule
147+
pattern: pattern
145148
}
146149
});
147150
});

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

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

312312
invalid: [{
313+
// createReactClass components with PropTypes, default config
314+
code: `
315+
var Hello = createReactClass({
316+
propTypes: {something: PropTypes.bool},
317+
render: function() { return <div />; }
318+
});
319+
`,
320+
errors: [{
321+
message: 'Prop name (something) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)'
322+
}]
323+
}, {
313324
// createReactClass components with PropTypes
314325
code: `
315326
var Hello = createReactClass({

0 commit comments

Comments
 (0)