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

chore: turn off eslint complexity rule #445

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
"no-shadow": "off",
"no-warning-comments": "warn",
"require-jsdoc": "off",
complexity: "off",
"prettier/prettier": [
"error",
{},
Expand Down
2 changes: 0 additions & 2 deletions src/parser/converts/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ import type { ScriptLetBlockParam } from "../../context/script-let";
import { ParseError } from "../..";
import { convertRenderTag } from "./render";

/* eslint-disable complexity -- X */
/** Convert for Fragment or Element or ... */
export function* convertChildren(
/* eslint-enable complexity -- X */
fragment: { children?: SvAST.TemplateNode[] },
parent:
| SvelteProgram
Expand Down
91 changes: 44 additions & 47 deletions src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ function transformForDeclareReactiveVar(
ctx.appendOriginal(statement.range[1]);
ctx.appendVirtualScript(`}`);

// eslint-disable-next-line complexity -- ignore X(
ctx.restoreContext.addRestoreStatementProcess((node, result) => {
if ((node as any).type !== "SvelteReactiveStatement") {
return false;
Expand Down Expand Up @@ -818,55 +817,53 @@ function transformForDollarDerived(

ctx.restoreContext.addRestoreExpressionProcess<TSESTree.CallExpression>({
target: "CallExpression" as TSESTree.AST_NODE_TYPES.CallExpression,
restore:
// eslint-disable-next-line complexity -- ignore
(node, result) => {
if (
node.callee.type !== "Identifier" ||
node.callee.name !== "$derived"
) {
return false;
}
const arg = node.arguments[0];
if (
!arg ||
arg.type !== "CallExpression" ||
arg.arguments.length !== 0 ||
arg.callee.type !== "ArrowFunctionExpression" ||
arg.callee.body.type !== "BlockStatement" ||
arg.callee.body.body.length !== 2 ||
arg.callee.body.body[0].type !== "ReturnStatement" ||
arg.callee.body.body[0].argument?.type !== "CallExpression" ||
arg.callee.body.body[0].argument.callee.type !== "Identifier" ||
arg.callee.body.body[0].argument.callee.name !== functionId ||
arg.callee.body.body[1].type !== "FunctionDeclaration" ||
arg.callee.body.body[1].id.name !== functionId
) {
return false;
}
const fnNode = arg.callee.body.body[1];
if (
fnNode.body.body.length !== 1 ||
fnNode.body.body[0].type !== "ReturnStatement" ||
!fnNode.body.body[0].argument
) {
return false;
}
restore: (node, result) => {
if (
node.callee.type !== "Identifier" ||
node.callee.name !== "$derived"
) {
return false;
}
const arg = node.arguments[0];
if (
!arg ||
arg.type !== "CallExpression" ||
arg.arguments.length !== 0 ||
arg.callee.type !== "ArrowFunctionExpression" ||
arg.callee.body.type !== "BlockStatement" ||
arg.callee.body.body.length !== 2 ||
arg.callee.body.body[0].type !== "ReturnStatement" ||
arg.callee.body.body[0].argument?.type !== "CallExpression" ||
arg.callee.body.body[0].argument.callee.type !== "Identifier" ||
arg.callee.body.body[0].argument.callee.name !== functionId ||
arg.callee.body.body[1].type !== "FunctionDeclaration" ||
arg.callee.body.body[1].id.name !== functionId
) {
return false;
}
const fnNode = arg.callee.body.body[1];
if (
fnNode.body.body.length !== 1 ||
fnNode.body.body[0].type !== "ReturnStatement" ||
!fnNode.body.body[0].argument
) {
return false;
}

const expr = fnNode.body.body[0].argument;
const expr = fnNode.body.body[0].argument;

node.arguments[0] = expr;
expr.parent = node;
node.arguments[0] = expr;
expr.parent = node;

const scopeManager = result.scopeManager as ScopeManager;
removeFunctionScope(arg.callee.body.body[1], scopeManager);
removeIdentifierReference(
arg.callee.body.body[0].argument.callee,
scopeManager.acquire(arg.callee)!,
);
removeFunctionScope(arg.callee, scopeManager);
return true;
},
const scopeManager = result.scopeManager as ScopeManager;
removeFunctionScope(arg.callee.body.body[1], scopeManager);
removeIdentifierReference(
arg.callee.body.body[0].argument.callee,
scopeManager.acquire(arg.callee)!,
);
removeFunctionScope(arg.callee, scopeManager);
return true;
},
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/scope/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ export function getProgramScope(scopeManager: ScopeManager): Scope {
);
}

/* eslint-disable complexity -- ignore X( */
/** Remove variable */
export function removeIdentifierVariable(
/* eslint-enable complexity -- ignore X( */
node:
| ESTree.Pattern
| TSESTree.BindingName
Expand Down
7 changes: 1 addition & 6 deletions tests/src/parser/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,10 @@ export function normalizeError(error: any): any {
};
}

/* eslint-disable complexity -- ignore */
/**
* Remove `parent` properties from the given AST.
*/
function nodeReplacer(
/* eslint-enable complexity -- ignore */
key: string,
value: any,
): any {
function nodeReplacer(key: string, value: any): any {
if (key === "parent") {
return undefined;
}
Expand Down
Loading