diff --git a/.eslintrc.cjs b/.eslintrc.cjs index c50873b..e59eea1 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -9,6 +9,7 @@ module.exports = { plugins: ["@typescript-eslint", "@stylistic/js", "react-refresh"], parser: "@typescript-eslint/parser", rules: { + eqeqeq: "error", "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-shadow": "error", "react-refresh/only-export-components": "warn", diff --git a/src/components/editor.tsx b/src/components/editor.tsx index fa087b4..32d3ddc 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -445,7 +445,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . try { const str = clipboard.readText(); - if (!str || str == "") { + if (!str || str === "") { return; } const curNodeData = findDataById(editor.selectedId); @@ -477,7 +477,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . try { const str = clipboard.readText(); - if (!str || str == "") { + if (!str || str === "") { return; } const curNodeData = findDataById(editor.selectedId); @@ -547,7 +547,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . } const parentData = findParent(data)!; - parentData.children = parentData.children!.filter((e) => e.id != editor.selectedId); + parentData.children = parentData.children!.filter((e) => e.id !== editor.selectedId); refreshItem(parentData); selectNode(null); updateGrahp(); @@ -652,7 +652,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . } subpath = subpath.replaceAll(Path.sep, "/"); - if (subpath.indexOf(workspace.workdir) == -1) { + if (subpath.indexOf(workspace.workdir) === -1) { message.warning(t("node.subtreePathError")); return; } @@ -741,7 +741,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . }); editor.graph.on("viewportchange", (data: any) => { - if (data.action == "translate" || data.action == "zoom") { + if (data.action === "translate" || data.action === "zoom") { editor.graphMatrix = data.matrix; } }); @@ -877,7 +877,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . return; } - if (srcNodeId == dstNode.getID()) { + if (srcNodeId === dstNode.getID()) { console.log("drop same node"); return; } @@ -897,30 +897,30 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . } const removeSrc = () => { - srcParent.children = srcParent.children!.filter((value) => value.id != srcData.id); + srcParent.children = srcParent.children!.filter((value) => value.id !== srcData.id); }; - if (dragDir == "dragRight") { + if (dragDir === "dragRight") { removeSrc(); if (!dstData.children) { dstData.children = []; } srcData.parent = dstData.id; dstData.children.push(srcData); - } else if (dragDir == "dragUp") { + } else if (dragDir === "dragUp") { if (!dstParent) { return; } removeSrc(); - const idx = dstParent.children!.findIndex((value) => value.id == dstData.id); + const idx = dstParent.children!.findIndex((value) => value.id === dstData.id); srcData.parent = dstParent.id; dstParent.children!.splice(idx, 0, srcData); - } else if (dragDir == "dragDown") { + } else if (dragDir === "dragDown") { if (!dstParent) { return; } removeSrc(); - const idx = dstParent.children!.findIndex((value) => value.id == dstData.id); + const idx = dstParent.children!.findIndex((value) => value.id === dstData.id); srcData.parent = dstParent.id; dstParent.children!.splice(idx + 1, 0, srcData); } else { @@ -1248,7 +1248,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . type="text" size="small" style={{ width: "30px" }} - disabled={filterOption.results.length == 0} + disabled={filterOption.results.length === 0} onClick={nextResult} /> )} @@ -1258,7 +1258,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . type="text" size="small" style={{ width: "30px" }} - disabled={filterOption.results.length == 0} + disabled={filterOption.results.length === 0} onClick={prevResult} /> )} diff --git a/src/components/inspector.tsx b/src/components/inspector.tsx index 59e0233..a36bdf7 100644 --- a/src/components/inspector.tsx +++ b/src/components/inspector.tsx @@ -109,9 +109,11 @@ const NodeInspector: FC = () => { } def.args?.forEach((v) => { if (v.type === "json" || v.type === "json?") { + const value = data.args?.[v.name]; + console.log("nameJson", v.name, value, data.args); form.setFieldValue( `args.${v.name}`, - JSON.stringify(data.args?.[v.name] ?? v.default, null, 2) + value === null ? "null" : JSON.stringify(value ?? v.default, null, 2) ); } else { form.setFieldValue(`args.${v.name}`, data.args?.[v.name] ?? v.default); @@ -194,7 +196,7 @@ const NodeInspector: FC = () => { if (v !== null && v !== undefined && v !== "") { data.args ||= {}; if (arg.type === "json" || arg.type === "json?") { - data.args[arg.name] = JSON.parse(v); + data.args[arg.name] = v === "null" ? null : JSON.parse(v); } else { data.args[arg.name] = v; } @@ -324,7 +326,7 @@ const NodeInspector: FC = () => {

{t("node.inputVariable")}

{def.input.map((v, i) => { - const required = v.indexOf("?") == -1; + const required = v.indexOf("?") === -1; const desc = v.replace("?", ""); return ( {

{t("node.args")}

{def.args.map((v) => { - const required = v.type.indexOf("?") == -1; + const required = v.type.indexOf("?") === -1; const type = v.type.replace("?", "") as NodeArgType; return ( { { required, message: t("node.fileRequired", { field: v.desc }) }, ({ getFieldValue, setFieldValue, isFieldValidating, validateFields }) => ({ validator(_, value) { - if (value && (v.type == "json" || v.type == "json?")) { + if (value && (v.type === "json" || v.type === "json?")) { try { - JSON.parse(value); + if (value !== "null") { + JSON.parse(value); + } } catch (e) { return Promise.reject(new Error(t("node.invalidValue"))); } @@ -474,7 +478,7 @@ const NodeInspector: FC = () => {

{t("node.outputVariable")}

{def.output.map((v, i) => { - const required = v.indexOf("?") == -1; + const required = v.indexOf("?") === -1; const desc = v.replace("?", ""); return ( {

{t("node.inputVariable")}

{def.input.map((v, i) => { - const required = v.indexOf("?") == -1; + const required = v.indexOf("?") === -1; return ( {

{t("node.args")}

{def.args.map((v, i) => { - const required = v.type.indexOf("?") == -1; + const required = v.type.indexOf("?") === -1; return ( {

{t("node.outputVariable")}

{def.output.map((v, i) => { - const required = v.indexOf("?") == -1; + const required = v.indexOf("?") === -1; return ( {
- {unsaves.length == 1 && ( + {unsaves.length === 1 && (
{t("workspace.saveOnClose", { name: Path.basename(unsaves[0].path) })}
)} {unsaves.length > 1 && ( @@ -331,7 +331,7 @@ export const Workspace: FC = () => { )} - {workspace.editors.length == 0 && ( + {workspace.editors.length === 0 && ( { - argValue = argValue ?? ""; + argValue = argValue === undefined ? "" : argValue; inputValue = inputValue ?? ""; return (argValue !== "" && inputValue === "") || (argValue === "" && inputValue !== ""); }; @@ -164,7 +164,7 @@ export const checkNodeData = (data: NodeModel | null | undefined) => { } let hasError = false; const conf = useWorkspace.getState().getNodeDef(data.name); - if (conf.children !== undefined && conf.children != -1) { + if (conf.children !== undefined && conf.children !== -1) { const count = data.children?.length || 0; if (conf.children !== count) { hasError = true; @@ -264,7 +264,7 @@ export const createNode = (data: TreeGraphData, includeChildren: boolean = true) node.args = {}; for (const k in data.args) { const v = data.args[k]; - if (v !== null && v !== undefined) { + if (v !== undefined) { node.args[k] = v; } } @@ -307,10 +307,10 @@ const toStatusFlag = (data: TreeGraphData) => { const appendStatusFlag = (status: number, childStatus: number) => { const childSuccess = (childStatus >> StatusFlag.SUCCESS) & 1; const childFailure = (childStatus >> StatusFlag.FAILURE) & 1; - if (childSuccess == 0) { + if (childSuccess === 0) { status |= 1 << StatusFlag.SUCCESS_ZERO; } - if (childFailure == 0) { + if (childFailure === 0) { status |= 1 << StatusFlag.FAILURE_ZERO; } status |= childStatus; @@ -404,7 +404,7 @@ export const calcTreeDataSize = (data: TreeGraphData) => { export const checkChildrenLimit = (data: TreeGraphData) => { const conf = data.def; - if (conf.children !== undefined && conf.children != -1) { + if (conf.children !== undefined && conf.children !== -1) { return (data.children?.length || 0) === conf.children; } return true;