Skip to content
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

feat: Add eslint v9 support #3743

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix linting issues
  • Loading branch information
MatiPl01 committed Apr 28, 2024
commit 9d4cc14f6821f7954911d968ca1a8793996e95ed
8 changes: 4 additions & 4 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const propsUtil = require('../util/props');
const docsUrl = require('../util/docsUrl');
const propWrapperUtil = require('../util/propWrapper');
const report = require('../util/report');
const { getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -116,7 +116,7 @@ module.exports = {
// we can't get the name of the Flow object key name. So we have
// to hack around it for now.
if (node.type === 'ObjectTypeProperty') {
return getSourceCode(context).getFirstToken(node).value;
return eslintUtil.getSourceCode(context).getFirstToken(node).value;
}

return node.key.name;
Expand Down Expand Up @@ -309,7 +309,7 @@ module.exports = {
&& node.value.type === 'CallExpression'
&& propWrapperUtil.isPropWrapperFunction(
context,
getSourceCode(context).getText(node.value.callee)
eslintUtil.getSourceCode(context).getText(node.value.callee)
)
) {
checkPropWrapperArguments(node, node.value.arguments);
Expand All @@ -335,7 +335,7 @@ module.exports = {
right.type === 'CallExpression'
&& propWrapperUtil.isPropWrapperFunction(
context,
getSourceCode(context).getText(right.callee)
eslintUtil.getSourceCode(context).getText(right.callee)
)
) {
checkPropWrapperArguments(component.node, right.arguments);
Expand Down
14 changes: 7 additions & 7 deletions lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');
const { getScope, getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');
const isAssignmentLHS = require('../util/ast').isAssignmentLHS;
const report = require('../util/report');

Expand Down Expand Up @@ -103,7 +103,7 @@ module.exports = {
function handleStatelessComponent(node) {
const params = evalParams(node.params);

const SFCComponent = components.get(getScope(node, context).block);
const SFCComponent = components.get(eslintUtil.getScope(node, context).block);
if (!SFCComponent) {
return;
}
Expand All @@ -121,7 +121,7 @@ module.exports = {
}

function handleStatelessComponentExit(node) {
const SFCComponent = components.get(getScope(node, context).block);
const SFCComponent = components.get(eslintUtil.getScope(node, context).block);
if (SFCComponent) {
sfcParams.pop();
}
Expand Down Expand Up @@ -193,7 +193,7 @@ module.exports = {
'FunctionExpression:exit': handleStatelessComponentExit,

MemberExpression(node) {
let scope = getScope(node, context);
let scope = eslintUtil.getScope(node, context);
let SFCComponent = components.get(scope.block);
while (!SFCComponent && scope.upper && scope.upper !== scope) {
SFCComponent = components.get(scope.upper.block);
Expand All @@ -211,7 +211,7 @@ module.exports = {

VariableDeclarator(node) {
const classComponent = utils.getParentComponent(node);
const SFCComponent = components.get(getScope(node, context).block);
const SFCComponent = components.get(eslintUtil.getScope(node, context).block);

const destructuring = (node.init && node.id && node.id.type === 'ObjectPattern');
// let {foo} = props;
Expand Down Expand Up @@ -249,7 +249,7 @@ module.exports = {
&& destructureInSignature === 'always'
&& node.init.name === 'props'
) {
const scopeSetProps = getScope(node, context).set.get('props');
const scopeSetProps = eslintUtil.getScope(node, context).set.get('props');
const propsRefs = scopeSetProps && scopeSetProps.references;
if (!propsRefs) {
return;
Expand All @@ -270,7 +270,7 @@ module.exports = {
param.typeAnnotation ? param.typeAnnotation.range[0] : param.range[1],
];
return [
fixer.replaceTextRange(replaceRange, getSourceCode(context).getText(node.id)),
fixer.replaceTextRange(replaceRange, eslintUtil.getSourceCode(context).getText(node.id)),
fixer.remove(node.parent),
];
},
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const has = require('object.hasown/polyfill')();
const docsUrl = require('../util/docsUrl');
const { getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');
const isCreateElement = require('../util/isCreateElement');
const report = require('../util/report');

Expand Down Expand Up @@ -91,7 +91,7 @@ module.exports = {

return {
JSXOpeningElement(node) {
reportIfForbidden(getSourceCode(context).getText(node.name), node.name);
reportIfForbidden(eslintUtil.getSourceCode(context).getText(node.name), node.name);
},

CallExpression(node) {
Expand All @@ -111,7 +111,7 @@ module.exports = {
} else if (argType === 'Literal' && /^[a-z][^.]*$/.test(argument.value)) {
reportIfForbidden(argument.value, argument);
} else if (argType === 'MemberExpression') {
reportIfForbidden(getSourceCode(context).getText(argument), argument);
reportIfForbidden(eslintUtil.getSourceCode(context).getText(argument), argument);
}
},
};
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const astUtil = require('../util/ast');
const docsUrl = require('../util/docsUrl');
const propWrapperUtil = require('../util/propWrapper');
const report = require('../util/report');
const { getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');

// ------------------------------------------------------------------------------
// Constants
Expand Down Expand Up @@ -174,9 +174,9 @@ module.exports = {
if (
propWrapperUtil.isPropWrapperFunction(
context,
getSourceCode(context).getText(node.callee)
) &&
innerNode
eslintUtil.getSourceCode(context).getText(node.callee)
)
&& innerNode
) {
checkNode(innerNode);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/function-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const arrayIncludes = require('array-includes');
const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');
const reportC = require('../util/report');
const { getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -182,7 +182,7 @@ module.exports = {
);

function getFixer(node, options) {
const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);
const source = sourceCode.getText();

const typeAnnotation = getTypeAnnotation(node, source);
Expand Down
40 changes: 20 additions & 20 deletions lib/rules/hook-use-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');
const report = require('../util/report');
const getMessageData = require('../util/message');
const eslintUtil = require('../util/eslint');

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -158,29 +159,28 @@ module.exports = {
Object.assign(
getMessageData('suggestMemo', messages.suggestMemo),
{
fix: (fixer) =>
[
// Add useMemo import, if necessary
useStateReactImportSpecifier &&
(!useMemoReactImportSpecifier ||
defaultReactImportName) &&
fixer.insertTextAfter(
fix: (fixer) => [
// Add useMemo import, if necessary
useStateReactImportSpecifier
&& (!useMemoReactImportSpecifier
|| defaultReactImportName)
&& fixer.insertTextAfter(
useStateReactImportSpecifier,
', useMemo'
),
// Convert single-value destructure to simple assignment
fixer.replaceTextRange(
node.parent.id.range,
valueVariableName
),
// Convert useState call to useMemo + arrow function + dependency array
fixer.replaceTextRange(
node.range,
`${useMemoCode}(() => ${getSourceCode(context).getText(
node.arguments[0]
)}, [])`
),
].filter(Boolean),
// Convert single-value destructure to simple assignment
fixer.replaceTextRange(
node.parent.id.range,
valueVariableName
),
// Convert useState call to useMemo + arrow function + dependency array
fixer.replaceTextRange(
node.range,
`${useMemoCode}(() => ${eslintUtil.getSourceCode(context).getText(
node.arguments[0]
)}, [])`
),
].filter(Boolean),
}
)
);
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const has = require('object.hasown/polyfill')();
const docsUrl = require('../util/docsUrl');
const { getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');
const report = require('../util/report');

// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -172,13 +172,13 @@ module.exports = {
switch (expectedLocation) {
case 'props-aligned':
indentation = /^\s*/.exec(
getSourceCode(context).lines[tokens.lastProp.firstLine - 1]
eslintUtil.getSourceCode(context).lines[tokens.lastProp.firstLine - 1]
)[0];
break;
case 'tag-aligned':
case 'line-aligned':
indentation = /^\s*/.exec(
getSourceCode(context).lines[tokens.opening.line - 1]
eslintUtil.getSourceCode(context).lines[tokens.opening.line - 1]
)[0];
break;
default:
Expand All @@ -199,7 +199,7 @@ module.exports = {
* prop and start of opening line.
*/
function getTokensLocations(node) {
const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);
const opening = sourceCode.getFirstToken(node).loc.start;
const closing = sourceCode.getLastTokens(node, node.selfClosing ? 2 : 1)[0].loc.start;
const tag = sourceCode.getFirstToken(node.name).loc.start;
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const arrayIncludes = require('array-includes');
const docsUrl = require('../util/docsUrl');
const jsxUtil = require('../util/jsx');
const report = require('../util/report');
const { getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');

// ------------------------------------------------------------------------------
// Constants
Expand Down Expand Up @@ -177,7 +177,7 @@ module.exports = {

let textToReplace;
if (jsxUtil.isJSX(expression)) {
const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);
textToReplace = sourceCode.getText(expression);
} else {
const expressionType = expression && expression.type;
Expand All @@ -189,7 +189,7 @@ module.exports = {
: expression.raw.slice(1, -1)
}"`;
} else if (jsxUtil.isJSX(expression)) {
const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);

textToReplace = sourceCode.getText(expression);
} else {
Expand All @@ -210,7 +210,7 @@ module.exports = {
if (jsxUtil.isJSX(literalNode)) {
return fixer.replaceText(
literalNode,
`{${getSourceCode(context).getText(literalNode)}}`
`{${eslintUtil.getSourceCode(context).getText(literalNode)}}`
);
}

Expand Down Expand Up @@ -255,7 +255,7 @@ module.exports = {
const expression = JSXExpressionNode.expression;
const expressionType = expression.type;

const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);
// Curly braces containing comments are necessary
if (sourceCode.getCommentsInside && sourceCode.getCommentsInside(JSXExpressionNode).length > 0) {
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/jsx-curly-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

const docsUrl = require('../util/docsUrl');
const { getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');
const report = require('../util/report');

// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -78,7 +78,7 @@ module.exports = {
},

create(context) {
const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);
const option = getNormalizedOption(context);

// ----------------------------------------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions lib/rules/jsx-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

const has = require('object.hasown/polyfill')();
const docsUrl = require('../util/docsUrl');
const { getSourceCode } = require('../util/eslint');
const eslintUtil = require('../util/eslint');
const report = require('../util/report');

// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -176,7 +176,7 @@ module.exports = {
* @returns {Object|*|{range, text}}
*/
function fixByTrimmingWhitespace(fixer, fromLoc, toLoc, mode, spacing) {
let replacementText = getSourceCode(context).text.slice(fromLoc, toLoc);
let replacementText = eslintUtil.getSourceCode(context).text.slice(fromLoc, toLoc);
if (mode === 'start') {
replacementText = replacementText.replace(/^\s+/gm, '');
} else {
Expand Down Expand Up @@ -207,7 +207,7 @@ module.exports = {
token: token.value,
},
fix(fixer) {
const nextToken = getSourceCode(context).getTokenAfter(token);
const nextToken = eslintUtil.getSourceCode(context).getTokenAfter(token);
return fixByTrimmingWhitespace(fixer, token.range[1], nextToken.range[0], 'start', spacing);
},
});
Expand All @@ -228,7 +228,7 @@ module.exports = {
token: token.value,
},
fix(fixer) {
const previousToken = getSourceCode(context).getTokenBefore(token);
const previousToken = eslintUtil.getSourceCode(context).getTokenBefore(token);
return fixByTrimmingWhitespace(fixer, previousToken.range[1], token.range[0], 'end', spacing);
},
});
Expand All @@ -248,7 +248,7 @@ module.exports = {
token: token.value,
},
fix(fixer) {
const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);
const nextToken = sourceCode.getTokenAfter(token);
let nextComment;

Expand Down Expand Up @@ -285,7 +285,7 @@ module.exports = {
token: token.value,
},
fix(fixer) {
const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);
const previousToken = sourceCode.getTokenBefore(token);
let previousComment;

Expand Down Expand Up @@ -371,7 +371,7 @@ module.exports = {
return;
}

const sourceCode = getSourceCode(context);
const sourceCode = eslintUtil.getSourceCode(context);
const first = sourceCode.getFirstToken(node);
const last = sourceCode.getLastToken(node);
let second = sourceCode.getTokenAfter(first, { includeComments: true });
Expand Down
Loading