Skip to content
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
8 changes: 6 additions & 2 deletions app/client/src/plugins/Linting/handlers/lintService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PathUtils } from "plugins/Linting/utils/pathUtils";
import { extractReferencesFromPath } from "ee/plugins/Linting/utils/getEntityDependencies";
import { groupDifferencesByType } from "plugins/Linting/utils/groupDifferencesByType";
import type {
LintRequest,
LintTreeRequestPayload,
LintTreeResponse,
} from "plugins/Linting/types";
Expand Down Expand Up @@ -39,7 +40,8 @@ class LintService {
}
}

lintTree = (payload: LintTreeRequestPayload) => {
lintTree = (lintRequest: LintRequest<LintTreeRequestPayload>) => {
const { data: payload, webworkerTelemetry } = lintRequest;
const {
cloudHosting,
configTree,
Expand Down Expand Up @@ -78,6 +80,7 @@ class LintService {
errors: {},
lintedJSPaths: [],
jsPropertiesState,
webworkerTelemetry,
};

try {
Expand All @@ -87,12 +90,13 @@ class LintService {
jsPropertiesState,
cloudHosting,
asyncJSFunctionsInDataFields,

webworkerTelemetry,
configTree,
});

lintTreeResponse.errors = lintErrors;
lintTreeResponse.lintedJSPaths = lintedJSPaths;
lintTreeResponse.webworkerTelemetry = webworkerTelemetry;
} catch (e) {}

return lintTreeResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { FeatureFlags } from "ee/entities/FeatureFlag";
import { WorkerEnv } from "workers/Evaluation/handlers/workerEnv";
import type { LintRequest } from "../types";

export const setupLintingWorkerEnv = (featureFlags: FeatureFlags) => {
export const setupLintingWorkerEnv = ({
data: featureFlags,
}: LintRequest<FeatureFlags>) => {
WorkerEnv.setFeatureFlags(featureFlags);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { updateJSLibraryProps } from "plugins/Linting/types";
import type { LintRequest, updateJSLibraryProps } from "plugins/Linting/types";
import { isEqual } from "lodash";
import { JSLibraries, JSLibraryAccessor } from "workers/common/JSLibrary";
import { resetJSLibraries } from "workers/common/JSLibrary/resetJSLibraries";

export function updateJSLibraryGlobals(data: updateJSLibraryProps) {
export function updateJSLibraryGlobals({
data,
}: LintRequest<updateJSLibraryProps>) {
const { add, libs } = data;

if (add) {
Expand Down
5 changes: 5 additions & 0 deletions app/client/src/plugins/Linting/lintTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function getLintErrorsFromTree({
jsPropertiesState,
pathsToLint,
unEvalTree,
webworkerTelemetry,
}: getLintErrorsFromTreeProps): getLintErrorsFromTreeResponse {
const lintTreeErrors: LintErrorsStore = {};
const lintedJSPaths = new Set<string>();
Expand All @@ -47,6 +48,7 @@ export function getLintErrorsFromTree({
entity,
fullPropertyPath: bindingPath,
globalData: globalData.getGlobalData(false),
webworkerTelemetry,
});

set(lintTreeErrors, `["${bindingPath}"]`, lintErrors);
Expand All @@ -67,6 +69,7 @@ export function getLintErrorsFromTree({
userScript: unEvalPropertyValue,
entity,
globalData: globalData.getGlobalData(true),
webworkerTelemetry,
});

set(lintTreeErrors, `["${triggerPath}"]`, lintErrors);
Expand All @@ -87,6 +90,7 @@ export function getLintErrorsFromTree({
const jsObjectBodyLintErrors = lintJSObjectBody(
jsObjectName,
globalData.getGlobalData(true),
webworkerTelemetry,
);

set(lintTreeErrors, jsObjectBodyPath, jsObjectBodyLintErrors);
Expand All @@ -96,6 +100,7 @@ export function getLintErrorsFromTree({
jsObjectPath,
jsObjectState,
asyncJSFunctionsInDataFields,
webworkerTelemetry,
);
const currentLintErrorsInBody = get(
lintTreeErrors,
Expand Down
20 changes: 16 additions & 4 deletions app/client/src/plugins/Linting/linters/worker.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import type { TMessage } from "utils/MessageUtil";
import { MessageType } from "utils/MessageUtil";
import { WorkerMessenger } from "workers/Evaluation/fns/utils/Messenger";
import type { LintRequest } from "../types";
import type {
LintRequest,
LintTreeRequestPayload,
updateJSLibraryProps,
} from "../types";
import { handlerMap } from "../handlers";
import type { FeatureFlags } from "ee/entities/FeatureFlag";

export function messageListener(e: MessageEvent<TMessage<LintRequest>>) {
// The messageListener can have either of these three types
type LinterFunctionPayload = LintTreeRequestPayload &
FeatureFlags &
updateJSLibraryProps;

export function messageListener(
e: MessageEvent<TMessage<LintRequest<LinterFunctionPayload>>>,
) {
const { messageType } = e.data;

if (messageType !== MessageType.REQUEST) return;

const startTime = Date.now();
const { body, messageId } = e.data;
const { data, method } = body;
const { method } = body;

if (!method) return;

const messageHandler = handlerMap[method];

if (typeof messageHandler !== "function") return;

const responseData = messageHandler(data);
const responseData = messageHandler(body);

if (!responseData) return;

Expand Down
11 changes: 11 additions & 0 deletions app/client/src/plugins/Linting/tests/getLintingErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { getScriptType } from "workers/Evaluation/evaluate";
import { CustomLintErrorCode } from "../constants";
import getLintingErrors from "../utils/getLintingErrors";

const webworkerTelemetry = {};

describe("getLintingErrors", () => {
describe("1. Verify lint errors are not shown for supported window APIs", () => {
const data = {};
Expand All @@ -17,6 +19,7 @@ describe("getLintingErrors", () => {
originalBinding,
script,
scriptType,
webworkerTelemetry,
});

expect(Array.isArray(lintErrors)).toBe(true);
Expand All @@ -29,6 +32,7 @@ describe("getLintingErrors", () => {
const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
webworkerTelemetry,
data,
originalBinding,
script,
Expand All @@ -45,6 +49,7 @@ describe("getLintingErrors", () => {
const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
webworkerTelemetry,
data,
originalBinding,
script,
Expand All @@ -65,6 +70,7 @@ describe("getLintingErrors", () => {
const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
webworkerTelemetry,
data,
originalBinding,
script,
Expand All @@ -80,6 +86,7 @@ describe("getLintingErrors", () => {
const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
webworkerTelemetry,
data,
originalBinding,
script,
Expand All @@ -95,6 +102,7 @@ describe("getLintingErrors", () => {
const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
webworkerTelemetry,
data,
originalBinding,
script,
Expand Down Expand Up @@ -128,6 +136,7 @@ describe("getLintingErrors", () => {
const scriptType = getScriptType(false, false);

const lintErrors = getLintingErrors({
webworkerTelemetry,
data,
options,
originalBinding,
Expand All @@ -150,6 +159,7 @@ describe("getLintingErrors", () => {
const scriptType = getScriptType(false, false);

const lintErrors = getLintingErrors({
webworkerTelemetry,
data,
options,
originalBinding,
Expand All @@ -172,6 +182,7 @@ describe("getLintingErrors", () => {
const scriptType = getScriptType(false, false);

const lintErrors = getLintingErrors({
webworkerTelemetry,
data,
options,
originalBinding,
Expand Down
16 changes: 12 additions & 4 deletions app/client/src/plugins/Linting/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type {
import type { DependencyMap } from "utils/DynamicBindingUtils";
import type { TJSPropertiesState } from "workers/Evaluation/JSObject/jsPropertiesState";
import type { JSLibrary } from "workers/common/JSLibrary";
import type { WebworkerSpanData } from "UITelemetry/generateWebWorkerTraces";
import type { SpanAttributes } from "UITelemetry/generateTraces";

export type WebworkerTelemetryAttribute = WebworkerSpanData | SpanAttributes;

export enum LINT_WORKER_ACTIONS {
LINT_TREE = "LINT_TREE",
Expand All @@ -21,6 +25,7 @@ export interface LintTreeResponse {
errors: LintErrorsStore;
lintedJSPaths: string[];
jsPropertiesState: TJSPropertiesState;
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>;
}

export interface LintTreeRequestPayload {
Expand All @@ -30,11 +35,10 @@ export interface LintTreeRequestPayload {
forceLinting?: boolean;
}

export interface LintRequest {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any;
export interface LintRequest<T> {
data: T;
method: LINT_WORKER_ACTIONS;
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>;
}

export interface LintTreeSagaRequestData {
Expand All @@ -46,12 +50,14 @@ export interface lintTriggerPathProps {
userScript: string;
entity: DataTreeEntity;
globalData: ReturnType<typeof createEvaluationContext>;
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>;
}
export interface lintBindingPathProps {
dynamicBinding: string;
entity: DataTreeEntity;
fullPropertyPath: string;
globalData: ReturnType<typeof createEvaluationContext>;
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>;
}
export interface getLintingErrorsProps {
script: string;
Expand All @@ -62,6 +68,7 @@ export interface getLintingErrorsProps {
options?: {
isJsObject: boolean;
};
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>;
}

export interface getLintErrorsFromTreeProps {
Expand All @@ -71,6 +78,7 @@ export interface getLintErrorsFromTreeProps {
cloudHosting: boolean;
asyncJSFunctionsInDataFields: DependencyMap;
configTree: ConfigTree;
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>;
}

export interface getLintErrorsFromTreeResponse {
Expand Down
17 changes: 15 additions & 2 deletions app/client/src/plugins/Linting/utils/getLintingErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import setters from "workers/Evaluation/setters";
import { isMemberExpressionNode } from "@shared/ast/src";
import { generate } from "astring";
import getInvalidModuleInputsError from "ee/plugins/Linting/utils/getInvalidModuleInputsError";
import { objectKeys } from "@appsmith/utils";
import { profileFn } from "UITelemetry/generateWebWorkerTraces";

const EvaluationScriptPositions: Record<string, Position> = {};

Expand Down Expand Up @@ -67,7 +69,7 @@ function generateLintingGlobalData(data: Record<string, unknown>) {

libAccessors.forEach((accessor) => (globalData[accessor] = true));
// Add all supported web apis
Object.keys(SUPPORTED_WEB_APIS).forEach(
objectKeys(SUPPORTED_WEB_APIS).forEach(
(apiName) => (globalData[apiName] = true),
);

Expand Down Expand Up @@ -190,12 +192,23 @@ export default function getLintingErrors({
originalBinding,
script,
scriptType,
webworkerTelemetry,
}: getLintingErrorsProps): LintError[] {
const scriptPos = getEvaluationScriptPosition(scriptType);
const lintingGlobalData = generateLintingGlobalData(data);
const lintingOptions = lintOptions(lintingGlobalData);

jshint(script, lintingOptions);
profileFn(
"Linter",
// adding some metrics to compare the performance changes with eslint
{
linter: "JSHint",
linesOfCodeLinted: originalBinding.split("\n").length,
codeSizeInChars: originalBinding.length,
},
webworkerTelemetry,
() => jshint(script, lintingOptions),
);
const sanitizedJSHintErrors = sanitizeJSHintErrors(jshint.errors, scriptPos);
const jshintErrors: LintError[] = sanitizedJSHintErrors.map((lintError) =>
convertJsHintErrorToAppsmithLintError(
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/plugins/Linting/utils/lintBindingPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function lintBindingPath({
entity,
fullPropertyPath,
globalData,
webworkerTelemetry,
}: lintBindingPathProps) {
let lintErrors: LintError[] = [];
const { propertyPath } = getEntityNameAndPropertyPath(fullPropertyPath);
Expand All @@ -37,6 +38,7 @@ export default function lintBindingPath({
data: globalData,
originalBinding,
scriptType,
webworkerTelemetry,
});

lintErrors = lintErrors.concat(lintErrorsFromSnippet);
Expand Down
3 changes: 3 additions & 0 deletions app/client/src/plugins/Linting/utils/lintJSObjectBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
import { Severity } from "entities/AppsmithConsole";
import { getJSToLint } from "./getJSToLint";
import getLintingErrors from "./getLintingErrors";
import type { WebworkerTelemetryAttribute } from "../types";

export default function lintJSObjectBody(
jsObjectName: string,
globalData: DataTree,
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>,
): LintError[] {
const jsObject = globalData[jsObjectName];
const rawJSObjectbody = (jsObject as unknown as JSActionEntity).body;
Expand Down Expand Up @@ -50,5 +52,6 @@ export default function lintJSObjectBody(
data: globalData,
originalBinding: jsbodyToLint,
scriptType,
webworkerTelemetry,
});
}
3 changes: 3 additions & 0 deletions app/client/src/plugins/Linting/utils/lintJSObjectProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import { globalData } from "../globalData";
import getLintSeverity from "./getLintSeverity";
import lintJSProperty from "./lintJSProperty";
import { isEmpty } from "lodash";
import type { WebworkerTelemetryAttribute } from "../types";

export default function lintJSObjectProperty(
jsPropertyFullName: string,
jsObjectState: Record<string, TJSpropertyState>,
asyncJSFunctionsInDataFields: DependencyMap,
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>,
) {
let lintErrors: LintError[] = [];
const { propertyPath: jsPropertyName } =
Expand All @@ -29,6 +31,7 @@ export default function lintJSObjectProperty(
jsPropertyFullName,
jsPropertyState,
globalData.getGlobalData(!isAsyncJSFunctionBoundToSyncField),
webworkerTelemetry,
);

lintErrors = lintErrors.concat(jsPropertyLintErrors);
Expand Down
Loading