Skip to content

Commit

Permalink
fork impl instead of checking an invariant every call
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 22, 2024
1 parent 31ba7bf commit 5d30424
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
30 changes: 16 additions & 14 deletions packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,25 @@ export default {
/**
* SourceCode#getText that also works down to ESLint 3.0.0
*/
function getSource(node) {
if (typeof context.getSource === 'function') {
return context.getSource(node);
} else {
return context.sourceCode.getText(node);
}
}
const getSource =
typeof context.getSource === 'function'
? node => {
return context.getSource(node);
}
: node => {
return context.sourceCode.getText(node);
};
/**
* SourceCode#getScope that also works down to ESLint 3.0.0
*/
function getScope(node) {
if (typeof context.getScope === 'function') {
return context.getScope();
} else {
return context.sourceCode.getScope(node);
}
}
const getScope =
typeof context.getScope === 'function'
? () => {
return context.getScope();
}
: node => {
return context.sourceCode.getScope(node);
};

const scopeManager = context.getSourceCode().scopeManager;

Expand Down
30 changes: 16 additions & 14 deletions packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,25 @@ export default {
/**
* SourceCode#getText that also works down to ESLint 3.0.0
*/
function getSource(node) {
if (typeof context.getSource === 'function') {
return context.getSource(node);
} else {
return context.sourceCode.getText(node);
}
}
const getSource =
typeof context.getSource === 'function'
? node => {
return context.getSource(node);
}
: node => {
return context.sourceCode.getText(node);
};
/**
* SourceCode#getScope that also works down to ESLint 3.0.0
*/
function getScope(node) {
if (typeof context.getScope === 'function') {
return context.getScope();
} else {
return context.sourceCode.getScope(node);
}
}
const getScope =
typeof context.getScope === 'function'
? () => {
return context.getScope();
}
: node => {
return context.sourceCode.getScope(node);
};

return {
// Maintain code segment path stack as we traverse.
Expand Down

0 comments on commit 5d30424

Please sign in to comment.