Skip to content

Commit 56db72e

Browse files
committed
Support propWrapperFunctions for bool-prop-naming
1 parent 6829c5c commit 56db72e

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

lib/rules/boolean-prop-naming.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module.exports = {
4646
const config = context.options[0] || {};
4747
const rule = config.rule ? new RegExp(config.rule) : null;
4848
const propTypeNames = config.propTypeNames || ['bool'];
49+
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
4950

5051
// Remembers all Flowtype object definitions
5152
const objectTypeAnnotations = new Map();
@@ -160,7 +161,12 @@ module.exports = {
160161
return;
161162
}
162163
const component = utils.getRelatedComponent(node);
163-
if (!component || !node.parent.right.properties) {
164+
if (!component || !node.parent.right) {
165+
return;
166+
}
167+
const right = node.parent.right;
168+
if (right.type === 'CallExpression' && propWrapperFunctions.has(sourceCode.getText(right.callee))) {
169+
right.arguments.filter(arg => arg.type === 'ObjectExpression').forEach(object => validatePropNaming(component.node, object.properties));
164170
return;
165171
}
166172
validatePropNaming(component.node, node.parent.right.properties);

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,18 @@ ruleTester.run('boolean-prop-naming', rule, {
295295
rule: '^is[A-Z]([A-Za-z0-9]?)+'
296296
}],
297297
parser: 'babel-eslint'
298+
}, {
299+
// No propWrapperFunctions setting
300+
code: `
301+
function Card(props) {
302+
return <div>{props.showScore ? 'yeh' : 'no'}</div>;
303+
}
304+
Card.propTypes = merge({}, Card.propTypes, {
305+
showScore: PropTypes.bool
306+
});`,
307+
options: [{
308+
rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+'
309+
}]
298310
}],
299311

300312
invalid: [{
@@ -515,5 +527,56 @@ ruleTester.run('boolean-prop-naming', rule, {
515527
}, {
516528
message: 'Prop name (somethingElse) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
517529
}]
530+
}, {
531+
code: `
532+
function Card(props) {
533+
return <div>{props.showScore ? 'yeh' : 'no'}</div>;
534+
}
535+
Card.propTypes = merge({}, Card.propTypes, {
536+
showScore: PropTypes.bool
537+
});`,
538+
settings: {
539+
propWrapperFunctions: ['merge']
540+
},
541+
options: [{
542+
rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+'
543+
}],
544+
errors: [{
545+
message: 'Prop name (showScore) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)'
546+
}]
547+
}, {
548+
code: `
549+
function Card(props) {
550+
return <div>{props.showScore ? 'yeh' : 'no'}</div>;
551+
}
552+
Card.propTypes = Object.assign({}, Card.propTypes, {
553+
showScore: PropTypes.bool
554+
});`,
555+
settings: {
556+
propWrapperFunctions: ['Object.assign']
557+
},
558+
options: [{
559+
rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+'
560+
}],
561+
errors: [{
562+
message: 'Prop name (showScore) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)'
563+
}]
564+
}, {
565+
code: `
566+
function Card(props) {
567+
return <div>{props.showScore ? 'yeh' : 'no'}</div>;
568+
}
569+
Card.propTypes = _.assign({}, Card.propTypes, {
570+
showScore: PropTypes.bool
571+
});`,
572+
settings: {
573+
propWrapperFunctions: ['_.assign']
574+
},
575+
options: [{
576+
rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+'
577+
}],
578+
errors: [{
579+
message: 'Prop name (showScore) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)'
580+
}]
518581
}]
519582
});

0 commit comments

Comments
 (0)