Skip to content

Commit 6d10db2

Browse files
matthargettthymikee
authored andcommitted
feat: Ignore args required for strong typing correctness (#53)
* 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.
1 parent 1141a58 commit 6d10db2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
'react/no-multi-comp': [WARNING, { "ignoreStateless": true }],
2929
'react/prop-types': OFF,
3030
'react-native/no-unused-styles': ERROR,
31+
'no-unused-vars': [ERROR, { 'argsIgnorePattern': '^_', 'caughtErrorsIgnorePattern': '^_' }],
3132
'react-native/split-platform-components': OFF,
3233
'react-native/no-inline-styles': WARNING,
3334
'react-native/no-color-literals': WARNING,

test/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ export default class Bool extends React.Component<Props> {
1414
let token = await this.current.keepOwnership();
1515
return this.props.updateMode(token);
1616
};
17+
18+
animate = (_: ?number) => {};
1719
}
1820

1921
export function Hook() {
2022
React.useEffect(() => {
21-
localStorage.setItem('formData', 'data');
23+
try {
24+
localStorage.setItem('formData', 'data');
25+
} catch (_hugeObject) {
26+
// handled
27+
}
2228
});
2329

2430
return <Bool />;

0 commit comments

Comments
 (0)