Skip to content

Commit

Permalink
feat: Ignore args required for strong typing correctness (#53)
Browse files Browse the repository at this point in the history
* Ignore args required for strong typing correctness

In our codebase, we have this pattern:
```js
animate = (_: ?number) => {};
```

That triggers the unused-vars warning due to the argument being unused. In this instance, the argument is there to pass strong-type checks, and we have a code style guideline that uses prepending of underscore to signify  that the argument (or catch variable) is unused.

This PR adds a narrowing and widening of the no-unused-vars rule:
1.  to ignore unused arguments that begin with an underscore (a narrowing)
2. to report unused caught exceptions that don't begin with an underscore (a widening since unused caught errors was previously OFF by default)

* Add test

* derp

* Eliminate style errors in test file.
  • Loading branch information
matthargett authored and thymikee committed May 11, 2019
1 parent 1141a58 commit 6d10db2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
'react/no-multi-comp': [WARNING, { "ignoreStateless": true }],
'react/prop-types': OFF,
'react-native/no-unused-styles': ERROR,
'no-unused-vars': [ERROR, { 'argsIgnorePattern': '^_', 'caughtErrorsIgnorePattern': '^_' }],
'react-native/split-platform-components': OFF,
'react-native/no-inline-styles': WARNING,
'react-native/no-color-literals': WARNING,
Expand Down
8 changes: 7 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ export default class Bool extends React.Component<Props> {
let token = await this.current.keepOwnership();
return this.props.updateMode(token);
};

animate = (_: ?number) => {};
}

export function Hook() {
React.useEffect(() => {
localStorage.setItem('formData', 'data');
try {
localStorage.setItem('formData', 'data');
} catch (_hugeObject) {
// handled
}
});

return <Bool />;
Expand Down

0 comments on commit 6d10db2

Please sign in to comment.