2023-10-10 12:32:17 +00:00
|
|
|
import type { DataTree } from "entities/DataTree/dataTreeTypes";
|
2023-05-11 05:26:03 +00:00
|
|
|
import type { LintError } from "utils/DynamicBindingUtils";
|
|
|
|
|
import { isNil } from "lodash";
|
|
|
|
|
import {
|
|
|
|
|
EvaluationScriptType,
|
|
|
|
|
getScriptToEval,
|
|
|
|
|
getScriptType,
|
|
|
|
|
} from "workers/Evaluation/evaluate";
|
|
|
|
|
import type { TJSpropertyState } from "workers/Evaluation/JSObject/jsPropertiesState";
|
|
|
|
|
import getLintingErrors from "./getLintingErrors";
|
|
|
|
|
|
|
|
|
|
export default function lintJSProperty(
|
|
|
|
|
jsPropertyFullName: string,
|
|
|
|
|
jsPropertyState: TJSpropertyState,
|
|
|
|
|
globalData: DataTree,
|
|
|
|
|
): LintError[] {
|
|
|
|
|
if (isNil(jsPropertyState)) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2023-07-05 13:34:03 +00:00
|
|
|
|
2023-05-11 05:26:03 +00:00
|
|
|
const scriptType = getScriptType(false, false);
|
|
|
|
|
const scriptToLint = getScriptToEval(
|
|
|
|
|
jsPropertyState.value,
|
|
|
|
|
EvaluationScriptType.OBJECT_PROPERTY,
|
|
|
|
|
);
|
|
|
|
|
const propLintErrors = getLintingErrors({
|
|
|
|
|
script: scriptToLint,
|
|
|
|
|
data: globalData,
|
|
|
|
|
originalBinding: jsPropertyState.value,
|
|
|
|
|
scriptType,
|
|
|
|
|
options: { isJsObject: true },
|
|
|
|
|
});
|
|
|
|
|
const refinedErrors = propLintErrors.map((lintError) => {
|
|
|
|
|
return {
|
|
|
|
|
...lintError,
|
|
|
|
|
line: lintError.line + jsPropertyState.position.startLine - 1,
|
|
|
|
|
ch:
|
|
|
|
|
lintError.line === 0
|
|
|
|
|
? lintError.ch + jsPropertyState.position.startColumn
|
|
|
|
|
: lintError.ch,
|
2023-07-05 13:34:03 +00:00
|
|
|
originalPath: jsPropertyFullName,
|
2023-05-11 05:26:03 +00:00
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return refinedErrors;
|
|
|
|
|
}
|