Skip to content

Commit

Permalink
chore: add a few todos
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Dec 10, 2023
1 parent e4759a7 commit d485783
Show file tree
Hide file tree
Showing 26 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions lib/rules/fixer-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ module.exports = {
* @returns {boolean}
*/
function isFix(node) {
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: use context.sourceCode when dropping eslint < v9
if (node.type === 'ArrayExpression' && node.elements.length === 0) {
// An empty array is not a fix.
return false;
}
const scope =
(context.sourceCode || context.getSourceCode()).getScope?.(node) ||
context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
const staticValue = getStaticValue(node, scope);
if (!staticValue) {
// If we can't find a static value, assume it's a real fix value.
Expand All @@ -100,7 +99,7 @@ module.exports = {

return {
Program(ast) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
contextIdentifiers = utils.getContextIdentifiers(
sourceCode.scopeManager,
ast
Expand Down Expand Up @@ -150,7 +149,8 @@ module.exports = {
// Ensure the current (arrow) fixer function returned a fix.
'ArrowFunctionExpression:exit'(node) {
if (funcInfo.shouldCheck) {
const loc = context.getSourceCode().getTokenBefore(node.body).loc; // Show violation on arrow (=>).
const sourceCode = context.sourceCode || context.getSourceCode();
const loc = sourceCode.getTokenBefore(node.body).loc; // Show violation on arrow (=>).
if (node.expression) {
// When the return is implied (no curly braces around the body), we have to check the single body node directly.
if (!isFix(node.body)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/meta-property-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const ruleInfo = getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-deprecated-context-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9

// ----------------------------------------------------------------------
// Public
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-deprecated-report-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
let contextIdentifiers;

// ----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-identical-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9

// ----------------------------------------------------------------------
// Helpers
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-missing-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const { scopeManager } = sourceCode;
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-missing-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const { scopeManager } = sourceCode;

let contextIdentifiers;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-only-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
messageId: 'removeOnly',
*fix(fixer) {
const sourceCode =
context.sourceCode || context.getSourceCode();
context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9

const tokenBefore =
sourceCode.getTokenBefore(onlyProperty);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unused-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const { scopeManager } = sourceCode;
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unused-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const { scopeManager } = sourceCode;

let contextIdentifiers;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-useless-token-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9

// ----------------------------------------------------------------------
// Helpers
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-object-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
// Public
// ----------------------------------------------------------------------

const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-output-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
// Public
// ----------------------------------------------------------------------

const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9

return {
Program(ast) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
create(context) {
let contextIdentifiers;

const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const { scopeManager } = sourceCode;

// ----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-replace-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
let funcInfo = {
upper: null,
codePath: null,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/report-message-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = {
}
}

const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-docs-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/require-meta-docs-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
*/
create(context) {
const options = context.options[0] || {};
const filename = context.filename || context.getFilename();
const filename = context.filename || context.getFilename(); // TODO: just use context.filename when dropping eslint < v9
const ruleName =
filename === '<input>'
? undefined
Expand All @@ -76,7 +76,7 @@ module.exports = {
);
}

const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const ruleInfo = util.getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-fixable.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {
const catchNoFixerButFixableProperty =
context.options[0] && context.options[0].catchNoFixerButFixableProperty;

const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const { scopeManager } = sourceCode;
const ruleInfo = utils.getRuleInfo(sourceCode);
let contextIdentifiers;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-has-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const { scopeManager } = sourceCode;
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const { scopeManager } = sourceCode;
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
// Public
// ----------------------------------------------------------------------

const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/test-case-property-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {
'env',
'errors',
];
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9

return {
Program(ast) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/test-case-shorthand-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {

create(context) {
const shorthandOption = context.options[0] || 'as-needed';
const sourceCode = context.sourceCode || context.getSourceCode();
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9

// ----------------------------------------------------------------------
// Helpers
Expand Down
6 changes: 3 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ module.exports = {
statements,
variableIdentifiers = new Set()
) {
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const runCalls = [];

for (const statement of statements) {
Expand Down Expand Up @@ -612,9 +613,8 @@ module.exports = {
}

let keys;
const scope =
(context.sourceCode || context.getSourceCode()).getScope?.(node) ||
context.getScope(); // TODO: just use sourceCode.getScope() when dropping eslint < v9
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: use context.sourceCode when dropping eslint < v9
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when dropping eslint < v9
const secondArgStaticValue = getStaticValue(reportArgs[1], scope);

if (
Expand Down

0 comments on commit d485783

Please sign in to comment.