Skip to content

Commit

Permalink
Move propWrapperFunctions into settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinsoftware committed Jun 24, 2017
1 parent 4df159b commit b6e3a2f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
3 changes: 1 addition & 2 deletions docs/rules/no-unused-prop-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ This rule can take one argument to ignore some specific props during validation.

```js
...
"react/no-unused-prop-types": [<enabled>, { customValidators: <customValidator>, skipShapeProps: <skipShapeProps>, propWrapperFunctions: <propWrapperFunctions> }]
"react/no-unused-prop-types": [<enabled>, { customValidators: <customValidator>, skipShapeProps: <skipShapeProps> }]
...
```

* `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
* `customValidators`: optional array of validators used for propTypes validation.
* `skipShapeProps`: In some cases it is impossible to accurately detect whether or not a `PropTypes.shape`'s values are being used. Setting this option to `true` will skip validation of `PropTypes.shape` (`true` by default).
* `propWrapperFunctions`: The names of any functions used to wrap the propTypes object, such as `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped.

## Caveats

Expand Down
9 changes: 1 addition & 8 deletions lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ module.exports = {
},
skipShapeProps: {
type: 'boolean'
},
propWrapperFunctions: {
type: 'array',
items: {
type: 'string'
},
uniqueItems: true
}
},
additionalProperties: false
Expand All @@ -63,7 +56,7 @@ module.exports = {
var configuration = Object.assign({}, defaults, context.options[0] || {});
var skipShapeProps = configuration.skipShapeProps;
var customValidators = configuration.customValidators || [];
var propWrapperFunctions = new Set(configuration.propWrapperFunctions || []);
var propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);

// Used to track the type annotations in scope.
// Necessary because babel's scopes do not track type annotations.
Expand Down
17 changes: 2 additions & 15 deletions lib/rules/require-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,12 @@ module.exports = {
category: 'Best Practices'
},

schema: [{
type: 'object',
properties: {
propWrapperFunctions: {
type: 'array',
items: {
type: 'string'
},
uniqueItems: true
}
},
additionalProperties: false
}]
schema: []
},

create: Components.detect(function(context, components, utils) {
var sourceCode = context.getSourceCode();
var configuration = context.options[0] || {};
var propWrapperFunctions = new Set(configuration.propWrapperFunctions || []);
var propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);

/**
* Get properties name
Expand Down
8 changes: 6 additions & 2 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2798,7 +2798,9 @@ ruleTester.run('no-unused-prop-types', rule, {
line: 10,
column: 8
}],
options: [{propWrapperFunctions: ['forbidExtraProps']}]
settings: {
propWrapperFunctions: ['forbidExtraProps']
}
}, {
code: [
'class Hello extends Component {',
Expand All @@ -2819,7 +2821,9 @@ ruleTester.run('no-unused-prop-types', rule, {
line: 4,
column: 10
}],
options: [{propWrapperFunctions: ['forbidExtraProps']}]
settings: {
propWrapperFunctions: ['forbidExtraProps']
}
}
/* , {
// Enable this when the following issue is fixed
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/rules/require-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,9 @@ ruleTester.run('require-default-props', rule, {
line: 5,
column: 3
}],
options: [{propWrapperFunctions: ['forbidExtraProps']}]
settings: {
propWrapperFunctions: ['forbidExtraProps']
}
},
{
code: [
Expand Down

0 comments on commit b6e3a2f

Please sign in to comment.