forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: linter rules to detect
forwardRef
usage (callstack#3632)
- Loading branch information
1 parent
0556ba6
commit e4aefd0
Showing
11 changed files
with
89 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Object.assign(exports, require('./no-import-react-forwardref')); | ||
Object.assign(exports, require('./no-react-forwardref-usage')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
exports['no-import-react-forwardref'] = { | ||
meta: { | ||
docs: { | ||
description: 'Disallow importing of React.forwardRef', | ||
category: 'Possible Errors', | ||
recommended: false, | ||
}, | ||
schema: [], | ||
}, | ||
create(context) { | ||
return { | ||
ImportDeclaration(node) { | ||
if (node.source.value !== 'react') return; | ||
|
||
for (const specifier of node.specifiers) { | ||
if (specifier.type !== 'ImportSpecifier') continue; | ||
if (specifier.imported.name !== 'forwardRef') continue; | ||
|
||
context.report({ | ||
loc: specifier.loc, | ||
message: 'Import forwardRef from src/utils/forwardRef instead', | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
exports['no-react-forwardref-usage'] = { | ||
meta: { | ||
docs: { | ||
description: 'Disallow usage of React.forwardRef', | ||
category: 'Possible Errors', | ||
recommended: false, | ||
}, | ||
schema: [], | ||
}, | ||
create(context) { | ||
return { | ||
CallExpression(node) { | ||
if (node.callee?.type !== 'MemberExpression') return; | ||
|
||
const { callee } = node; | ||
if (callee.object.type !== 'Identifier') return; | ||
if (callee.object.name !== 'React') return; | ||
if (callee.property.type !== 'Identifier') return; | ||
if (callee.property.name !== 'forwardRef') return; | ||
|
||
context.report({ | ||
loc: callee.loc, | ||
message: 'Use forwardRef from src/utils/forwardRef instead', | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters