Skip to content

[Fix] boolean-prop-naming: add missing default config #1702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -34,7 +36,7 @@ module.exports = {
uniqueItems: true
},
rule: {
default: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
default: ruleDefault,
minLength: 1,
type: 'string'
},
Expand All @@ -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 || []);

Expand Down Expand Up @@ -146,7 +149,7 @@ module.exports = {
data: {
component: propName,
propName: propName,
pattern: config.rule
pattern: pattern
}
});
});
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <div />; }
});
`,
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({
Expand Down