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

chore: add eslint package to handle linting #37417

Merged
merged 67 commits into from
Nov 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
11c88a6
create: feature flag for eslint migration
ayushpahwa Sep 25, 2024
8c4ad0f
update: enum for linter engines
ayushpahwa Sep 25, 2024
8cc1c36
update: refactored if check logic
ayushpahwa Sep 25, 2024
35c9441
update: remove const from enum declaration
ayushpahwa Sep 25, 2024
3ff9c9e
create: type added for lint length
ayushpahwa Sep 25, 2024
77ef464
update: logic added to skip lint length calculation
ayushpahwa Sep 25, 2024
bba3989
Merge branch 'release' into feat/eslint/feature-flag
ayushpahwa Sep 28, 2024
5c3c434
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Sep 28, 2024
7ab0717
Merge branch 'release' into feat/eslint/feature-flag
ayushpahwa Sep 30, 2024
5579787
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Sep 30, 2024
1298a8f
Merge branch 'release' into feat/eslint/feature-flag
ayushpahwa Oct 9, 2024
206db12
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Oct 9, 2024
9e1a65b
Merge branch 'release' into feat/eslint/feature-flag
ayushpahwa Oct 14, 2024
d84b7b1
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Oct 14, 2024
64d4272
Merge branch 'release' into feat/eslint/feature-flag
ayushpahwa Nov 6, 2024
40b0c85
Merge branch 'release' into feat/eslint/feature-flag
ayushpahwa Nov 11, 2024
34b638b
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Nov 11, 2024
18afebc
update: sync with release
ayushpahwa Nov 11, 2024
a03edc2
update: refactor var name
ayushpahwa Nov 11, 2024
23649ca
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Nov 11, 2024
03e97dd
Merge branch 'release' into feat/eslint/feature-flag
ayushpahwa Nov 12, 2024
254f465
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Nov 12, 2024
00d8519
update: refactored variable name
ayushpahwa Nov 12, 2024
43b4ef2
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Nov 12, 2024
ac773e1
update: refactor var name
ayushpahwa Nov 12, 2024
7c35991
Merge branch 'feat/eslint/feature-flag' into feat/eslint/lint-length-…
ayushpahwa Nov 12, 2024
0919825
Merge branch 'release' into feat/eslint/lint-length-processing
ayushpahwa Nov 14, 2024
b6d23a7
Merge branch 'release' into feat/eslint/lint-length-processing
ayushpahwa Nov 18, 2024
924ceb0
update: add tests for lint length change
ayushpahwa Nov 18, 2024
afe552b
update: fix lint issue
ayushpahwa Nov 18, 2024
fc035b4
create: new package for eslint
ayushpahwa Nov 18, 2024
c4df9f1
update: config update based on lintertype used
ayushpahwa Nov 18, 2024
3c8ef15
update: pass the current lintertype to options conflig
ayushpahwa Nov 18, 2024
7452c8c
update: helper methods for eslint
ayushpahwa Nov 18, 2024
b63e371
update: lock file
ayushpahwa Nov 18, 2024
b3600f3
update: lint length if engine is eslint
ayushpahwa Nov 18, 2024
9653d47
update: source of linter
ayushpahwa Nov 18, 2024
0f6078a
update: constants for linter
ayushpahwa Nov 18, 2024
a13751f
update: add polyfill for missing method
ayushpahwa Nov 18, 2024
36e7f16
update: force the lint test to be run for both jshint and eslint
ayushpahwa Nov 18, 2024
b263be4
update: refactor function passing for jest test
ayushpahwa Nov 18, 2024
987d809
update: pass mocked function for test
ayushpahwa Nov 18, 2024
8df7584
update: comment added for clarity
ayushpahwa Nov 18, 2024
7da61e7
Merge branch 'release' into feat/eslint/lint-length-processing
ayushpahwa Nov 19, 2024
6b07590
Merge branch 'feat/eslint/lint-length-processing' into feat/eslint/es…
ayushpahwa Nov 19, 2024
550dd08
Merge branch 'release' into feat/eslint/eslint-package
ayushpahwa Nov 20, 2024
8996a3a
Merge branch 'release' into feat/eslint/eslint-package
ayushpahwa Nov 21, 2024
418b990
update: WIP tests for each rule config
ayushpahwa Nov 21, 2024
6ea9f12
update: add tests for curl
ayushpahwa Nov 21, 2024
40f57f7
update: moved unused vars to warn state
ayushpahwa Nov 21, 2024
073ad50
update: new tests for config rules
ayushpahwa Nov 21, 2024
7fb4717
update: add tests for asi and boss rule config
ayushpahwa Nov 21, 2024
1291da0
udpate: add tests for no semicolons
ayushpahwa Nov 21, 2024
e72081e
update: add test for boss rule
ayushpahwa Nov 21, 2024
74951dc
update: add tests for eval rule
ayushpahwa Nov 21, 2024
2ab43e4
update: add tests for funcscope and dotnotation
ayushpahwa Nov 21, 2024
983fa65
update: add tests for expr rule config
ayushpahwa Nov 21, 2024
23543c3
update: fix test for funcscope
ayushpahwa Nov 21, 2024
22e7cc8
Merge branch 'release' into feat/eslint/eslint-package
ayushpahwa Nov 21, 2024
9ea70c6
update: add indirect eval tests
ayushpahwa Nov 21, 2024
a347807
update: remove redundant code
ayushpahwa Nov 21, 2024
7df7f53
update: add polyfil for jest tests
ayushpahwa Nov 21, 2024
32ea12a
update: acorn walk package
ayushpahwa Nov 21, 2024
81bc617
update: yarn lock for package upgrade
ayushpahwa Nov 21, 2024
518c411
update: remove unused type skip commetns
ayushpahwa Nov 21, 2024
7fd76f3
Merge branch 'chore/fix-acorn-version' into feat/eslint/eslint-package
ayushpahwa Nov 21, 2024
579e477
Merge branch 'release' into feat/eslint/eslint-package
ayushpahwa Nov 22, 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
Prev Previous commit
Next Next commit
update: new tests for config rules
  • Loading branch information
ayushpahwa committed Nov 21, 2024
commit 073ad5087b91577220b4f819e05f23469e5c0e93
120 changes: 101 additions & 19 deletions app/client/src/plugins/Linting/tests/getLintingErrors.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getScriptType } from "workers/Evaluation/evaluate";
import { CustomLintErrorCode, LINTER_TYPE } from "../constants";
import getLintingErrors from "../utils/getLintingErrors";
import { Severity } from "entities/AppsmithConsole";

const webworkerTelemetry = {};

Expand Down Expand Up @@ -278,17 +279,16 @@ describe.each(linterTypes)(

expect(Array.isArray(lintErrors)).toBe(true);
// Should have at least one error for modifying native objects
expect(lintErrors.length).toBeGreaterThan(0);
expect(
lintErrors.some(
(error) =>
error.errorMessage.name === "LintingError" &&
(error.errorMessage.message ===
"Extending prototype of native object: 'Array'." ||
error.errorMessage.message ===
"Array prototype is read only, properties should not be added."),
),
).toBe(true);
expect(lintErrors.length).toBe(1);
const lintError = lintErrors[0];
const expectedErrorMessage =
linterType === LINTER_TYPE.JSHINT
? "Extending prototype of native object: 'Array'."
: "Array prototype is read only, properties should not be added.";

expect(lintError.severity).toBe(Severity.ERROR);

expect(lintError.errorMessage.message).toContain(expectedErrorMessage);
});

// Test for 'undef: true' (Disallow use of undeclared variables)
Expand All @@ -310,15 +310,37 @@ describe.each(linterTypes)(

expect(Array.isArray(lintErrors)).toBe(true);
// Should have at least one error for 'x' being undefined
expect(lintErrors.length).toBeGreaterThan(0);
expect(lintErrors.length).toBe(1);
// Check if the error code corresponds to undefined variable
expect(
lintErrors.some(
(error) =>
error.errorMessage.name === "LintingError" &&
error.errorMessage.message === "'x' is not defined.",
),
).toBe(true);
const lintError = lintErrors[0];
const expectedErrorMessage = "'x' is not defined.";

expect(lintError.severity).toBe(Severity.ERROR);

expect(lintError.errorMessage.message).toContain(expectedErrorMessage);
});

// Test for 'forin: false' (Doesn't require filtering for..in loops with obj.hasOwnProperty())
it("5. Should allow unflitered forin loops without error", () => {
const data = { obj: { a: 1, b: 2 } };
const originalBinding =
"{{ for (var key in obj) { console.log(key); } }}";
const script = "for (var key in obj) { console.log(key); }";

const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
getLinterTypeFn: () => linterType,
data,
originalBinding,
script,
scriptType,
webworkerTelemetry,
});

expect(Array.isArray(lintErrors)).toBe(true);
// Should have no errors for unfiltered 'for-in' loops
expect(lintErrors.length).toEqual(0);
});

// Test for 'noempty: false' (Allow empty blocks)
Expand All @@ -342,6 +364,66 @@ describe.each(linterTypes)(
// Should have no errors
expect(lintErrors.length).toEqual(0);
});

// Test for 'strict: false' (strict mode is not enforced)
it("7. should allow blocks without strict mode enabled", () => {
const data = {
THIS_CONTEXT: {},
};
const originalBinding = "myFun1() {\n\t\tconsole.log('test')\n\t}";
const script =
"\n function $$closedFn () {\n const $$result = {myFun1() {\n\t\tconsole.log('test')\n\t}}\n return $$result\n }\n $$closedFn.call(THIS_CONTEXT)\n";
const options = { isJsObject: true };
//const originalBinding = "{{ console.log('some statement') }}";
//const script = "console.log('some statement')";

const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
getLinterTypeFn: () => linterType,
data,
originalBinding,
options,
script,
scriptType,
webworkerTelemetry,
});

expect(Array.isArray(lintErrors)).toBe(true);
// Should have no errors for missing 'use strict'
expect(lintErrors.length).toEqual(0);
});

// Test for 'unused: 'strict'' (if a variable is defined, it should be used)
it("8. should throw error for unused variables", () => {
const data = {};
const originalBinding = "{{ const x = 1; }}";
const script = "const x = 1;";

const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
getLinterTypeFn: () => linterType,
data,
originalBinding,
script,
scriptType,
webworkerTelemetry,
});

expect(Array.isArray(lintErrors)).toBe(true);
// Should have no errors
expect(lintErrors.length).toEqual(1);
const lintError = lintErrors[0];

const expectedMessage =
linterType === LINTER_TYPE.JSHINT
? "'x' is defined but never used."
: "'x' is assigned a value but never used.";

expect(lintError.severity).toBe(Severity.WARNING);
expect(lintError.errorMessage.message).toBe(expectedMessage);
});
});
},
);
Loading