PromucFlow_constructor/app/client/src/plugins/Linting/utils/lintJSObjectBody.ts

51 lines
1.7 KiB
TypeScript
Raw Normal View History

import type { DataTree } from "entities/DataTree/dataTreeFactory";
import type { LintError } from "utils/DynamicBindingUtils";
import { PropertyEvaluationErrorType } from "utils/DynamicBindingUtils";
import { getScriptToEval, getScriptType } from "workers/Evaluation/evaluate";
import {
INVALID_JSOBJECT_START_STATEMENT,
INVALID_JSOBJECT_START_STATEMENT_ERROR_CODE,
JS_OBJECT_START_STATEMENT,
} from "../constants";
import { Severity } from "entities/AppsmithConsole";
import type { JSActionEntity } from "entities/DataTree/types";
import { getJSToLint } from "./getJSToLint";
import getLintingErrors from "./getLintingErrors";
export default function lintJSObjectBody(
jsObjectName: string,
globalData: DataTree,
): LintError[] {
const jsObject = globalData[jsObjectName];
const rawJSObjectbody = (jsObject as unknown as JSActionEntity).body;
if (!rawJSObjectbody) return [];
if (!rawJSObjectbody.startsWith(JS_OBJECT_START_STATEMENT)) {
return [
{
errorType: PropertyEvaluationErrorType.LINT,
errorSegment: "",
originalBinding: rawJSObjectbody,
line: 0,
ch: 0,
code: INVALID_JSOBJECT_START_STATEMENT_ERROR_CODE,
variables: [],
raw: rawJSObjectbody,
errorMessage: {
name: "LintingError",
message: INVALID_JSOBJECT_START_STATEMENT,
},
severity: Severity.ERROR,
},
];
}
const scriptType = getScriptType(false, false);
const jsbodyToLint = getJSToLint(jsObject, rawJSObjectbody, "body"); // remove "export default"
const scriptToLint = getScriptToEval(jsbodyToLint, scriptType);
return getLintingErrors({
script: scriptToLint,
data: globalData,
originalBinding: jsbodyToLint,
scriptType,
});
}