From 28843f7b9b4e0375ab13b9d3f604204b5905264e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 24 Feb 2018 13:44:50 -0800 Subject: [PATCH] [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. --- lib/rules/boolean-prop-naming.js | 9 ++++++--- tests/lib/rules/boolean-prop-naming.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index ccfdf6f3bb..8dec7e02d2 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -13,6 +13,8 @@ const docsUrl = require('../util/docsUrl'); // Rule Definition // ------------------------------------------------------------------------------ +const ruleDefault = '^(is|has)[A-Z]([A-Za-z0-9]?)+'; + module.exports = { meta: { docs: { @@ -34,7 +36,7 @@ module.exports = { uniqueItems: true }, rule: { - default: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + default: ruleDefault, minLength: 1, type: 'string' }, @@ -50,7 +52,8 @@ module.exports = { create: Components.detect((context, components, utils) => { const sourceCode = context.getSourceCode(); const config = context.options[0] || {}; - const rule = config.rule ? new RegExp(config.rule) : null; + const pattern = config.rule || ruleDefault; + const rule = pattern ? new RegExp(pattern) : null; const propTypeNames = config.propTypeNames || ['bool']; const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []); @@ -146,7 +149,7 @@ module.exports = { data: { component: propName, propName: propName, - pattern: config.rule + pattern: pattern } }); }); diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index f83c8dd999..aa1cdd542b 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -351,6 +351,17 @@ ruleTester.run('boolean-prop-naming', rule, { }], invalid: [{ + // createReactClass components with PropTypes, default config + code: ` + var Hello = createReactClass({ + propTypes: {something: PropTypes.bool}, + render: function() { return
; } + }); + `, + errors: [{ + message: 'Prop name (something) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)' + }] + }, { // createReactClass components with PropTypes code: ` var Hello = createReactClass({