-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: replace use of deprecated methods #1453
Changes from all commits
6508d98
72e8bc3
60a1b9a
6870186
9ef0bb6
b8684f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,7 +178,7 @@ export const removeExtraArgumentsFixer = ( | |
const firstArg = func.arguments[from]; | ||
const lastArg = func.arguments[func.arguments.length - 1]; | ||
|
||
const sourceCode = context.getSourceCode(); | ||
const sourceCode = getSourceCode(context); | ||
let tokenAfterLastParam = sourceCode.getTokenAfter(lastArg)!; | ||
|
||
if (tokenAfterLastParam.value === ',') { | ||
|
@@ -229,3 +229,63 @@ export const getFirstMatcherArg = ( | |
|
||
return followTypeAssertionChain(firstArg); | ||
}; | ||
|
||
/* istanbul ignore next */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to ignore coverage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because only one branch in each function should ever get used depending on what ESLint version you're using, and coverage is only collected against a single ESLint version at a time (technically we could merge reports for CI but that'd still be a pain locally) |
||
export const getFilename = ( | ||
context: TSESLint.RuleContext<string, unknown[]>, | ||
) => { | ||
return 'filename' in context | ||
? (context.filename as string) | ||
: context.getFilename(); | ||
}; | ||
|
||
/* istanbul ignore next */ | ||
export const getSourceCode = ( | ||
context: TSESLint.RuleContext<string, unknown[]>, | ||
) => { | ||
return 'sourceCode' in context | ||
? (context.sourceCode as TSESLint.SourceCode) | ||
: context.getSourceCode(); | ||
}; | ||
|
||
/* istanbul ignore next */ | ||
export const getScope = ( | ||
context: TSESLint.RuleContext<string, unknown[]>, | ||
node: TSESTree.Node, | ||
) => { | ||
const sourceCode = getSourceCode(context); | ||
|
||
if ('getScope' in sourceCode) { | ||
return sourceCode.getScope(node); | ||
} | ||
|
||
return context.getScope(); | ||
}; | ||
|
||
/* istanbul ignore next */ | ||
export const getAncestors = ( | ||
context: TSESLint.RuleContext<string, unknown[]>, | ||
node: TSESTree.Node, | ||
) => { | ||
const sourceCode = getSourceCode(context); | ||
|
||
if ('getAncestors' in sourceCode) { | ||
return sourceCode.getAncestors(node); | ||
} | ||
|
||
return context.getAncestors(); | ||
}; | ||
|
||
/* istanbul ignore next */ | ||
export const getDeclaredVariables = ( | ||
context: TSESLint.RuleContext<string, unknown[]>, | ||
node: TSESTree.Node, | ||
) => { | ||
const sourceCode = getSourceCode(context); | ||
|
||
if ('getDeclaredVariables' in sourceCode) { | ||
return sourceCode.getDeclaredVariables(node); | ||
} | ||
|
||
return context.getDeclaredVariables(node); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid this by upgrading to v6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I implemented the types in typescript-eslint/typescript-eslint#7812
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet! we should probably do that in a major