📝 Disallow usage of deprecated methods on rule context objects.
💼 This rule is enabled in the ✅ recommended config.
🔧 This rule is automatically fixable by the --fix CLI option.
This rule disallows the use of deprecated methods on rule context objects.
The deprecated methods are:
getSourcegetSourceLinesgetAllCommentsgetNodeByRangeIndexgetCommentsgetCommentsBeforegetCommentsAftergetCommentsInsidegetJSDocCommentgetFirstTokengetFirstTokensgetLastTokengetLastTokensgetTokenAftergetTokenBeforegetTokenByRangeStartgetTokensgetTokensAftergetTokensBeforegetTokensBetween
Instead of using these methods, you should use the equivalent methods on SourceCode, e.g. context.sourceCode.getText() instead of context.getSource().
Examples of incorrect code for this rule:
module.exports = {
create(context) {
return {
Program(ast) {
const firstToken = context.getFirstToken(ast);
},
};
},
};Examples of correct code for this rule:
module.exports = {
create(context) {
const sourceCode = context.getSourceCode();
return {
Program(ast) {
const firstToken = sourceCode.getFirstToken(ast);
},
};
},
};If you need to support very old versions of ESLint where SourceCode doesn't exist, you should not enable this rule.