Skip to content

Commit

Permalink
Merge pull request #953 from everdimension/default-skipshapeprops-enable
Browse files Browse the repository at this point in the history
skipShapeProps should be enabled by default until it works properly
  • Loading branch information
ljharb authored Nov 12, 2016
2 parents 9921674 + 2cd6e91 commit 1df6118
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ module.exports = {

create: Components.detect(function(context, components, utils) {

var defaults = {skipShapeProps: true};
var sourceCode = context.getSourceCode();
var configuration = context.options[0] || {};
var skipShapeProps = configuration.skipShapeProps || false;
var configuration = Object.assign({}, defaults, context.options[0] || {});
var skipShapeProps = configuration.skipShapeProps;
var customValidators = configuration.customValidators || [];
// Used to track the type annotations in scope.
// Necessary because babel's scopes do not track type annotations.
Expand Down
22 changes: 17 additions & 5 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' b: React.PropTypes.string',
'});'
].join('\n'),
options: [{skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand All @@ -274,6 +275,7 @@ ruleTester.run('no-unused-prop-types', rule, {
'};',
'Hello.propTypes.a.b.c = React.PropTypes.number;'
].join('\n'),
options: [{skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand All @@ -295,6 +297,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' )',
'};'
].join('\n'),
options: [{skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand All @@ -318,6 +321,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' )',
'};'
].join('\n'),
options: [{skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand Down Expand Up @@ -358,6 +362,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' ])',
'};'
].join('\n'),
options: [{skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand Down Expand Up @@ -458,6 +463,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' )',
'};'
].join('\n'),
options: [{skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand Down Expand Up @@ -490,6 +496,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' })',
'};'
].join('\n'),
options: [{skipShapeProps: false}],
parser: 'babel-eslint'
}, {
code: [
Expand Down Expand Up @@ -540,7 +547,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' }',
'});'
].join('\n'),
options: [{customValidators: ['CustomValidator']}],
options: [{customValidators: ['CustomValidator'], skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand All @@ -555,7 +562,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' }',
'});'
].join('\n'),
options: [{customValidators: ['CustomValidator']}],
options: [{customValidators: ['CustomValidator'], skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand All @@ -570,7 +577,7 @@ ruleTester.run('no-unused-prop-types', rule, {
' }',
'});'
].join('\n'),
options: [{customValidators: ['CustomValidator']}],
options: [{customValidators: ['CustomValidator'], skipShapeProps: false}],
parserOptions: parserOptions
}, {
code: [
Expand Down Expand Up @@ -1195,7 +1202,7 @@ ruleTester.run('no-unused-prop-types', rule, {
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured shape props can't be tested, unless we use `skipShapeProps`
// Destructured shape props are skipped by default
code: [
'class Hello extends Component {',
' static propTypes = {',
Expand All @@ -1210,7 +1217,6 @@ ruleTester.run('no-unused-prop-types', rule, {
' }',
'}'
].join('\n'),
options: [{skipShapeProps: true}],
parser: 'babel-eslint'
}, {
// Destructured props in componentWillReceiveProps shouldn't throw errors
Expand Down Expand Up @@ -1570,6 +1576,7 @@ ruleTester.run('no-unused-prop-types', rule, {
'};'
].join('\n'),
parserOptions: parserOptions,
options: [{skipShapeProps: false}],
errors: [{
message: '\'a.b\' PropType is defined but prop is never used'
}]
Expand All @@ -1590,6 +1597,7 @@ ruleTester.run('no-unused-prop-types', rule, {
'};'
].join('\n'),
parserOptions: parserOptions,
options: [{skipShapeProps: false}],
errors: [{
message: '\'a.b.c\' PropType is defined but prop is never used'
}]
Expand All @@ -1612,6 +1620,7 @@ ruleTester.run('no-unused-prop-types', rule, {
'};'
].join('\n'),
parserOptions: parserOptions,
options: [{skipShapeProps: false}],
errors: [
{message: '\'a.*.unused\' PropType is defined but prop is never used'}
]
Expand All @@ -1636,6 +1645,7 @@ ruleTester.run('no-unused-prop-types', rule, {
'};'
].join('\n'),
parserOptions: parserOptions,
options: [{skipShapeProps: false}],
errors: [
{message: '\'a.*.unused\' PropType is defined but prop is never used'}
]
Expand All @@ -1662,6 +1672,7 @@ ruleTester.run('no-unused-prop-types', rule, {
'};'
].join('\n'),
parserOptions: parserOptions,
options: [{skipShapeProps: false}],
errors: [
{message: '\'a.unused\' PropType is defined but prop is never used'},
{message: '\'a.anotherunused\' PropType is defined but prop is never used'}
Expand Down Expand Up @@ -1699,6 +1710,7 @@ ruleTester.run('no-unused-prop-types', rule, {
'};'
].join('\n'),
parserOptions: parserOptions,
options: [{skipShapeProps: false}],
errors: [
{message: '\'arr.*.some.unused\' PropType is defined but prop is never used'}
]
Expand Down

0 comments on commit 1df6118

Please sign in to comment.