2022-11-03 09:23:15 +00:00
|
|
|
import { ENTITY_TYPE, Severity } from "entities/AppsmithConsole";
|
|
|
|
|
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
2023-09-29 10:42:14 +00:00
|
|
|
import type { DataTree } from "@appsmith/entities/DataTree/types";
|
2022-11-03 09:23:15 +00:00
|
|
|
import { isEmpty } from "lodash";
|
|
|
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
|
|
|
|
import {
|
|
|
|
|
getEntityNameAndPropertyPath,
|
|
|
|
|
isJSAction,
|
2022-12-22 06:34:28 +00:00
|
|
|
} from "@appsmith/workers/Evaluation/evaluationUtils";
|
2023-04-03 10:41:15 +00:00
|
|
|
import type { LintErrorsStore } from "reducers/lintingReducers/lintErrorsReducers";
|
2022-11-03 09:23:15 +00:00
|
|
|
|
|
|
|
|
// We currently only log lint errors in JSObjects
|
|
|
|
|
export function* logLatestLintPropertyErrors({
|
|
|
|
|
dataTree,
|
|
|
|
|
errors,
|
|
|
|
|
}: {
|
2023-04-03 10:41:15 +00:00
|
|
|
errors: LintErrorsStore;
|
2022-11-03 09:23:15 +00:00
|
|
|
dataTree: DataTree;
|
|
|
|
|
}) {
|
2022-12-07 10:28:29 +00:00
|
|
|
const errorsToAdd = [];
|
|
|
|
|
const errorsToRemove = [];
|
|
|
|
|
|
2022-11-03 09:23:15 +00:00
|
|
|
for (const path of Object.keys(errors)) {
|
|
|
|
|
const { entityName, propertyPath } = getEntityNameAndPropertyPath(path);
|
|
|
|
|
const entity = dataTree[entityName];
|
|
|
|
|
// only log lint errors in JSObjects
|
|
|
|
|
if (!isJSAction(entity)) continue;
|
|
|
|
|
// only log lint errors (not warnings)
|
|
|
|
|
const lintErrorsInPath = errors[path].filter(
|
|
|
|
|
(error) => error.severity === Severity.ERROR,
|
|
|
|
|
);
|
|
|
|
|
const lintErrorMessagesInPath = lintErrorsInPath.map((error) => ({
|
|
|
|
|
type: error.errorType,
|
|
|
|
|
message: error.errorMessage,
|
2023-02-18 12:55:46 +00:00
|
|
|
lineNumber: error.line,
|
2023-08-17 13:47:56 +00:00
|
|
|
character: error.ch,
|
2022-11-03 09:23:15 +00:00
|
|
|
}));
|
|
|
|
|
const debuggerKey = entity.actionId + propertyPath + "-lint";
|
|
|
|
|
|
|
|
|
|
if (isEmpty(lintErrorsInPath)) {
|
2022-12-07 10:28:29 +00:00
|
|
|
errorsToRemove.push({ id: debuggerKey });
|
2022-11-03 09:23:15 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-02-18 12:55:46 +00:00
|
|
|
|
2022-12-07 10:28:29 +00:00
|
|
|
errorsToAdd.push({
|
|
|
|
|
payload: {
|
|
|
|
|
id: debuggerKey,
|
|
|
|
|
logType: LOG_TYPE.LINT_ERROR,
|
2023-02-18 12:55:46 +00:00
|
|
|
text: "LINT ERROR",
|
2022-12-07 10:28:29 +00:00
|
|
|
messages: lintErrorMessagesInPath,
|
|
|
|
|
source: {
|
2023-02-06 07:38:09 +00:00
|
|
|
id: entity.actionId,
|
2022-12-07 10:28:29 +00:00
|
|
|
name: entityName,
|
|
|
|
|
type: ENTITY_TYPE.JSACTION,
|
|
|
|
|
propertyPath,
|
|
|
|
|
},
|
2022-11-03 09:23:15 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-02-06 07:38:09 +00:00
|
|
|
|
2022-12-07 10:28:29 +00:00
|
|
|
AppsmithConsole.addErrors(errorsToAdd);
|
|
|
|
|
AppsmithConsole.deleteErrors(errorsToRemove);
|
2022-11-03 09:23:15 +00:00
|
|
|
}
|