Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: eslint integration poc #36428

Draft
wants to merge 27 commits into
base: release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d00d5d1
upadte: added telemety for jshint
ayushpahwa Sep 19, 2024
a3a0612
update: types for each linter handler function to add telemetry
ayushpahwa Sep 19, 2024
15cccc0
update: type definitions for linter functions
ayushpahwa Sep 19, 2024
36c925b
update: passing down telemetry function to linter functions
ayushpahwa Sep 19, 2024
0da7c9d
update: method to profile linter func
ayushpahwa Sep 19, 2024
237a960
Merge branch 'release' into feat/telemetry-for-linters
ayushpahwa Sep 19, 2024
da5b190
create: alternate way to calculate linter length
ayushpahwa Sep 19, 2024
f213059
create: new pkg for linting
ayushpahwa Sep 19, 2024
0e47d57
update: new opts based on linterversion
ayushpahwa Sep 19, 2024
77cc9ca
create: conditional trigger for eslint
ayushpahwa Sep 19, 2024
e8c33b8
Merge branch 'release' into feat/eslint-integration
ayushpahwa Sep 19, 2024
d133670
Merge branch 'release' into feat/eslint-integration
ayushpahwa Sep 20, 2024
149053a
Merge branch 'release' into feat/eslint-integration
ayushpahwa Sep 24, 2024
085a543
update: added new feature flag
ayushpahwa Sep 24, 2024
7c5f36e
update: enums to dictate linter version
ayushpahwa Sep 24, 2024
7437f88
update: started using feature flag to control linter engine
ayushpahwa Sep 24, 2024
64cd372
Merge branch 'release' into feat/eslint-integration
ayushpahwa Sep 24, 2024
2f59150
udpate: fix unit tests
ayushpahwa Sep 24, 2024
5b6bffd
Merge branch 'release' into feat/eslint-integration
ayushpahwa Sep 25, 2024
318c190
Merge branch 'release' into feat/eslint-integration
ayushpahwa Sep 30, 2024
3238122
Merge branch 'release' into feat/eslint-integration
ayushpahwa Oct 9, 2024
676353b
Merge branch 'release' into feat/eslint-integration
ayushpahwa Oct 14, 2024
c944f89
Merge branch 'release' into feat/eslint-integration
ayushpahwa Nov 6, 2024
6733e74
Merge branch 'release' into feat/eslint-integration
ayushpahwa Nov 7, 2024
2458a8c
update: release sync
ayushpahwa Nov 7, 2024
122a5e7
Merge branch 'release' into feat/eslint-integration
ayushpahwa Nov 7, 2024
a293361
Merge branch 'release' into feat/eslint-integration
ayushpahwa Nov 11, 2024
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
1 change: 1 addition & 0 deletions app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"deep-diff": "^1.0.2",
"downloadjs": "^1.4.7",
"echarts": "^5.4.2",
"eslint-linter-browserify": "^9.10.0",
"fast-deep-equal": "^3.1.3",
"fast-sort": "^3.4.0",
"fastdom": "^1.0.11",
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/ce/entities/FeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const FEATURE_FLAG = {
release_drag_drop_building_blocks_enabled:
"release_drag_drop_building_blocks_enabled",
rollout_side_by_side_enabled: "rollout_side_by_side_enabled",
rollout_eslint_enabled: "rollout_eslint_enabled",
release_layout_conversion_enabled: "release_layout_conversion_enabled",
release_anvil_toggle_enabled: "release_anvil_toggle_enabled",
release_git_persist_branch_enabled: "release_git_persist_branch_enabled",
Expand Down Expand Up @@ -70,6 +71,7 @@ export const DEFAULT_FEATURE_FLAG_VALUE: FeatureFlags = {
ab_appsmith_ai_query: false,
release_actions_redesign_enabled: false,
rollout_remove_feature_walkthrough_enabled: true,
rollout_eslint_enabled: false,
rollout_side_by_side_enabled: false,
release_layout_conversion_enabled: false,
release_anvil_toggle_enabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
INVALID_JSOBJECT_START_STATEMENT,
INVALID_JSOBJECT_START_STATEMENT_ERROR_CODE,
} from "plugins/Linting/constants";

export const getIndexOfRegex = (
str: string,
regex: RegExp,
Expand Down Expand Up @@ -137,6 +138,7 @@ export const getLintAnnotations = (
line,
originalBinding,
severity,
variableLength,
variables,
} = error;

Expand All @@ -157,16 +159,18 @@ export const getLintAnnotations = (
});
}

let variableLength = 1;
let calculatedVariableLength = 1;

// Find the variable with minimal length
if (variables) {
if (variableLength && variableLength > 0) {
calculatedVariableLength = variableLength;
} else if (variables) {
for (const variable of variables) {
if (variable) {
variableLength =
variableLength === 1
calculatedVariableLength =
calculatedVariableLength === 1
? String(variable).length
: Math.min(String(variable).length, variableLength);
: Math.min(String(variable).length, calculatedVariableLength);
}
}
}
Expand Down Expand Up @@ -205,7 +209,7 @@ export const getLintAnnotations = (
};
const to = {
line: from.line,
ch: from.ch + variableLength,
ch: from.ch + calculatedVariableLength,
};

annotations.push({
Expand Down
100 changes: 74 additions & 26 deletions app/client/src/plugins/Linting/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,80 @@ import { ECMA_VERSION } from "@shared/ast";
import type { LintOptions } from "jshint";
import isEntityFunction from "./utils/isEntityFunction";

export const lintOptions = (globalData: Record<string, boolean>) =>
({
indent: 2,
esversion: ECMA_VERSION,
eqeqeq: false, // Not necessary to use ===
curly: false, // Blocks can be added without {}, eg if (x) return true
freeze: true, // Overriding inbuilt classes like Array is not allowed
undef: true, // Undefined variables should be reported as error
forin: false, // Doesn't require filtering for..in loops with obj.hasOwnProperty()
noempty: false, // Empty blocks are allowed
strict: false, // We won't force strict mode
unused: "strict", // Unused variables are not allowed
asi: true, // Tolerate Automatic Semicolon Insertion (no semicolons)
boss: true, // Tolerate assignments where comparisons would be expected
evil: false, // Use of eval not allowed
funcscope: true, // Tolerate variable definition inside control statements
sub: true, // Don't force dot notation
expr: true, // suppresses warnings about the use of expressions where normally you would expect to see assignments or function calls
// environments
browser: false,
worker: true,
mocha: false,
// global values
globals: globalData,
loopfunc: true,
}) as LintOptions;
export const enum LINTER_VERSION {
"JSHINT" = "JSHint",
"ESLINT" = "ESLint",
}

export const lintOptions = (
globalData: Record<string, boolean>,
linterVersion = LINTER_VERSION.JSHINT,
) => {
if (linterVersion === LINTER_VERSION.JSHINT) {
return {
indent: 2,
esversion: ECMA_VERSION,
eqeqeq: false, // Not necessary to use ===
curly: false, // Blocks can be added without {}, eg if (x) return true
freeze: true, // Overriding inbuilt classes like Array is not allowed
undef: true, // Undefined variables should be reported as error
forin: false, // Doesn't require filtering for..in loops with obj.hasOwnProperty()
noempty: false, // Empty blocks are allowed
strict: false, // We won't force strict mode
unused: "strict", // Unused variables are not allowed
asi: true, // Tolerate Automatic Semicolon Insertion (no semicolons)
boss: true, // Tolerate assignments where comparisons would be expected
evil: false, // Use of eval not allowed
funcscope: true, // Tolerate variable definition inside control statements
sub: true, // Don't force dot notation
expr: true, // suppresses warnings about the use of expressions where normally you would expect to see assignments or function calls
// environments
browser: false,
worker: true,
mocha: false,
// global values
globals: globalData,
loopfunc: true,
} as LintOptions;
} else {
const eslintGlobals: Record<string, "writable" | "readonly"> = {};

for (const key in globalData) {
//eslintGlobals[key] = globalData[key] ? "writable" : "readonly";
eslintGlobals[key] = "readonly";
}

return {
languageOptions: {
ecmaVersion: ECMA_VERSION,
globals: eslintGlobals,
sourceType: "script",
},
rules: {
indent: ["off", "tab"],
//indent: "off",
eqeqeq: "off",
curly: "off",
"no-extend-native": "error",
"no-undef": "error",
"guard-for-in": "off",
"no-empty": "off",
strict: "off",
"no-unused-vars": [
"error",
{ vars: "all", args: "all", ignoreRestSiblings: false },
],
//semi: ["error", "never"],
"no-cond-assign": "off",
"no-eval": "error",
"block-scoped-var": "off",
"dot-notation": "off",
"no-unused-expressions": "off",
"no-loop-func": "off",
},
};
}
};
export const JS_OBJECT_START_STATEMENT = "export default";
export const INVALID_JSOBJECT_START_STATEMENT = `JSObject must start with '${JS_OBJECT_START_STATEMENT}'`;
export const INVALID_JSOBJECT_START_STATEMENT_ERROR_CODE =
Expand Down
1 change: 1 addition & 0 deletions app/client/src/plugins/Linting/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface getLintingErrorsProps {
isJsObject: boolean;
};
webworkerTelemetry: Record<string, WebworkerTelemetryAttribute>;
linterVersion?: number;
}

export interface getLintErrorsFromTreeProps {
Expand Down
Loading
Loading