Skip to content
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

skipShapeProps should be enabled by default until it works properly #953

Merged
Merged
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
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