From a8dd1171bf813193b3f94f48d0934c12e511a93f Mon Sep 17 00:00:00 2001 From: Norbert Schneider Date: Tue, 11 Jul 2023 12:01:58 +0200 Subject: [PATCH 1/6] eslint: Globally ignore no-var-required errors require is used in many tests and even in some hooks, and is should not be problematic. --- .eslintrc.json | 6 ++ .../command-injection/custom-hooks.js | 2 +- .../bug-detectors/command-injection/fuzz.js | 3 +- examples/bug-detectors/path-traversal/fuzz.js | 2 - examples/custom-hooks/custom-hooks.js | 2 +- examples/custom-hooks/fuzz.js | 1 - examples/jest_integration/integration.fuzz.js | 3 +- examples/jest_integration/worker.fuzz.js | 1 - examples/jpeg/fuzz.js | 1 - examples/jpeg_es6/fuzz.js | 1 - examples/spectral/spectral-example.js | 1 - examples/xml/fuzz.js | 1 - fuzztests/FuzzedDataProvider.fuzz.js | 2 +- fuzztests/core.fuzz.js | 2 +- fuzztests/fuzzer.fuzz.js | 2 +- fuzztests/instrument.fuzz.js | 2 +- fuzztests/runFuzzTests.js | 2 - .../instrumentor/plugins/compareHooks.test.ts | 2 - .../plugins/sourceCodeCoverage.test.ts | 1 - tests/FuzzedDataProvider/fuzz.js | 1 - tests/bug-detectors/command-injection.test.js | 8 +- tests/bug-detectors/command-injection/fuzz.js | 2 - .../command-injection/makeFRIENDLY.js | 1 - tests/bug-detectors/general.test.js | 3 - tests/bug-detectors/general/fuzz.js | 1 - tests/bug-detectors/general/tests.fuzz.js | 1 - tests/bug-detectors/path-traversal.test.js | 8 +- tests/bug-detectors/path-traversal/fuzz.js | 1 - tests/code_coverage/coverage.test.js | 2 +- .../sample_fuzz_test/codeCoverage.fuzz.js | 3 +- .../sample_fuzz_test/custom-hooks.js | 1 - .../fuzz+lib+codeCoverage-fuzz.json | 80 +++++++++---------- .../fuzz+lib+customHooks.json | 66 +++++++-------- .../fuzz+lib+otherCodeCoverage-fuzz.json | 44 +++++----- .../expected_coverage/fuzz+lib.json | 44 +++++----- tests/code_coverage/sample_fuzz_test/fuzz.js | 1 - tests/helpers.js | 5 +- .../asyncRunnerAsyncReturns/fuzz.js | 1 - .../asyncRunnerMixedReturns/fuzz.js | 1 - .../asyncRunnerSyncReturns/fuzz.js | 1 - tests/return_values/return_values.test.js | 2 - .../syncRunnerAsyncReturns/fuzz.js | 1 - .../syncRunnerMixedReturns/fuzz.js | 1 - .../syncRunnerSyncReturns/fuzz.js | 1 - tests/signal_handlers/SIGINT/tests.fuzz.js | 1 - tests/signal_handlers/signal_handlers.test.js | 7 +- 46 files changed, 137 insertions(+), 188 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 33ebc53a..475ba632 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,6 +11,12 @@ "prettier" ], "overrides": [ + { + "files": ["*.js", "*.ts"], + "rules": { + "@typescript-eslint/no-var-requires": "off" + } + }, { "files": ["*.md"], "parser": "eslint-plugin-markdownlint/parser", diff --git a/examples/bug-detectors/command-injection/custom-hooks.js b/examples/bug-detectors/command-injection/custom-hooks.js index e4e0030b..0c65aba2 100644 --- a/examples/bug-detectors/command-injection/custom-hooks.js +++ b/examples/bug-detectors/command-injection/custom-hooks.js @@ -16,7 +16,7 @@ * Examples showcasing the custom hooks API */ -/* eslint-disable @typescript-eslint/no-var-requires,@typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/no-unused-vars */ const { registerReplaceHook } = require("@jazzer.js/hooking"); const { reportFinding } = require("@jazzer.js/bug-detectors"); diff --git a/examples/bug-detectors/command-injection/fuzz.js b/examples/bug-detectors/command-injection/fuzz.js index e234f654..dad278af 100644 --- a/examples/bug-detectors/command-injection/fuzz.js +++ b/examples/bug-detectors/command-injection/fuzz.js @@ -14,10 +14,9 @@ * limitations under the License. */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const { FuzzedDataProvider } = require("@jazzer.js/core"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const root = require("global-modules-path"); + module.exports.fuzz = function (data) { const provider = new FuzzedDataProvider(data); const str1 = provider.consumeString(provider.consumeIntegralInRange(1, 20)); diff --git a/examples/bug-detectors/path-traversal/fuzz.js b/examples/bug-detectors/path-traversal/fuzz.js index 1d2695f6..9d8ab933 100644 --- a/examples/bug-detectors/path-traversal/fuzz.js +++ b/examples/bug-detectors/path-traversal/fuzz.js @@ -14,9 +14,7 @@ * limitations under the License. */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const JSZip = require("jszip"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const path = require("path"); /** diff --git a/examples/custom-hooks/custom-hooks.js b/examples/custom-hooks/custom-hooks.js index 5e92162e..97fd6f4a 100644 --- a/examples/custom-hooks/custom-hooks.js +++ b/examples/custom-hooks/custom-hooks.js @@ -1,5 +1,5 @@ // noinspection JSUnusedLocalSymbols -/* eslint-disable @typescript-eslint/no-var-requires,@typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/no-unused-vars */ /* * Copyright 2022 Code Intelligence GmbH diff --git a/examples/custom-hooks/fuzz.js b/examples/custom-hooks/fuzz.js index 3d2bfb75..bbfcd285 100644 --- a/examples/custom-hooks/fuzz.js +++ b/examples/custom-hooks/fuzz.js @@ -2,7 +2,6 @@ // https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz/-/blob/34a694a8c73bfe0895c4e24784ba5b6dfe964b94/examples/jpeg/fuzz.js // The original code is available under the Apache License 2.0. -// eslint-disable-next-line @typescript-eslint/no-var-requires const jpeg = require("jpeg-js"); /** diff --git a/examples/jest_integration/integration.fuzz.js b/examples/jest_integration/integration.fuzz.js index 5b106e88..7bb03fec 100644 --- a/examples/jest_integration/integration.fuzz.js +++ b/examples/jest_integration/integration.fuzz.js @@ -14,9 +14,8 @@ * limitations under the License. */ -/* eslint no-undef: 0, no-constant-condition: 0, @typescript-eslint/no-var-requires:0 */ +/* eslint no-undef: 0, no-constant-condition: 0 */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const target = require("./target.js"); describe("My describe", () => { diff --git a/examples/jest_integration/worker.fuzz.js b/examples/jest_integration/worker.fuzz.js index 2516dd97..912223d5 100644 --- a/examples/jest_integration/worker.fuzz.js +++ b/examples/jest_integration/worker.fuzz.js @@ -16,7 +16,6 @@ /* eslint no-undef: 0 */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const target = require("./target"); const startupTeardownCalls = []; diff --git a/examples/jpeg/fuzz.js b/examples/jpeg/fuzz.js index 987d1028..ef0f7f52 100644 --- a/examples/jpeg/fuzz.js +++ b/examples/jpeg/fuzz.js @@ -2,7 +2,6 @@ // https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz/-/blob/34a694a8c73bfe0895c4e24784ba5b6dfe964b94/examples/jpeg/fuzz.js // The original code is available under the Apache License 2.0. -// eslint-disable-next-line @typescript-eslint/no-var-requires const jpeg = require("jpeg-js"); /** diff --git a/examples/jpeg_es6/fuzz.js b/examples/jpeg_es6/fuzz.js index 74c261e0..3833d618 100644 --- a/examples/jpeg_es6/fuzz.js +++ b/examples/jpeg_es6/fuzz.js @@ -2,7 +2,6 @@ // https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz/-/blob/34a694a8c73bfe0895c4e24784ba5b6dfe964b94/examples/jpeg/fuzz.js // The original code is available under the Apache License 2.0. -// eslint-disable-next-line @typescript-eslint/no-var-requires import { decode } from "jpeg-js"; /** diff --git a/examples/spectral/spectral-example.js b/examples/spectral/spectral-example.js index a1da4d95..15d12af1 100644 --- a/examples/spectral/spectral-example.js +++ b/examples/spectral/spectral-example.js @@ -14,7 +14,6 @@ * limitations under the License. */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const parsers = require("@stoplight/spectral-parsers"); /** diff --git a/examples/xml/fuzz.js b/examples/xml/fuzz.js index 97a1eed0..104e4128 100644 --- a/examples/xml/fuzz.js +++ b/examples/xml/fuzz.js @@ -2,7 +2,6 @@ // https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz/-/blob/34a694a8c73bfe0895c4e24784ba5b6dfe964b94/examples/xml/fuzz.js // The original code is available under the Apache License 2.0. -// eslint-disable-next-line @typescript-eslint/no-var-requires const xml2js = require("xml2js"); /** diff --git a/fuzztests/FuzzedDataProvider.fuzz.js b/fuzztests/FuzzedDataProvider.fuzz.js index 43ee3ef0..5aedb778 100644 --- a/fuzztests/FuzzedDataProvider.fuzz.js +++ b/fuzztests/FuzzedDataProvider.fuzz.js @@ -14,7 +14,7 @@ * limitations under the License. */ -/* eslint-disable no-undef, @typescript-eslint/no-var-requires */ +/* eslint-disable no-undef */ const { FuzzedDataProvider, jazzer } = require("@jazzer.js/core"); diff --git a/fuzztests/core.fuzz.js b/fuzztests/core.fuzz.js index 5c665aca..0cebf8d6 100644 --- a/fuzztests/core.fuzz.js +++ b/fuzztests/core.fuzz.js @@ -14,7 +14,7 @@ * limitations under the License. */ -/* eslint-disable no-undef, @typescript-eslint/no-var-requires */ +/* eslint-disable no-undef */ const { ensureFilepath } = require("@jazzer.js/core"); diff --git a/fuzztests/fuzzer.fuzz.js b/fuzztests/fuzzer.fuzz.js index 4a7427e3..a47bc427 100644 --- a/fuzztests/fuzzer.fuzz.js +++ b/fuzztests/fuzzer.fuzz.js @@ -14,7 +14,7 @@ * limitations under the License. */ -/* eslint-disable no-undef, @typescript-eslint/no-var-requires */ +/* eslint-disable no-undef */ const { fuzzer } = require("@jazzer.js/fuzzer"); const { FuzzedDataProvider } = require("@jazzer.js/core"); diff --git a/fuzztests/instrument.fuzz.js b/fuzztests/instrument.fuzz.js index 87ed09b9..f378c71f 100644 --- a/fuzztests/instrument.fuzz.js +++ b/fuzztests/instrument.fuzz.js @@ -14,7 +14,7 @@ * limitations under the License. */ -/* eslint-disable no-undef, @typescript-eslint/no-var-requires */ +/* eslint-disable no-undef */ const { Instrumentor } = require("@jazzer.js/instrumentor"); const { FuzzedDataProvider } = require("@jazzer.js/core"); diff --git a/fuzztests/runFuzzTests.js b/fuzztests/runFuzzTests.js index 7e48286e..6fe57c75 100755 --- a/fuzztests/runFuzzTests.js +++ b/fuzztests/runFuzzTests.js @@ -3,8 +3,6 @@ // Helper script that searches for Jest fuzz tests in the current directory and // executes them in new processes using the found fuzz test names. -/* eslint-disable @typescript-eslint/no-var-requires */ - const fs = require("fs/promises"); const { spawn } = require("child_process"); diff --git a/packages/instrumentor/plugins/compareHooks.test.ts b/packages/instrumentor/plugins/compareHooks.test.ts index c53d445c..66faf5a4 100644 --- a/packages/instrumentor/plugins/compareHooks.test.ts +++ b/packages/instrumentor/plugins/compareHooks.test.ts @@ -250,7 +250,6 @@ describe("compare hooks instrumentation", () => { // This is normally done by the jest environment. Here we replace every // API function with a jest mock, which can be configured in the test. function mockFuzzerApi() { - // eslint-disable-next-line @typescript-eslint/no-var-requires const fuzzer = require("@jazzer.js/fuzzer").fuzzer; jest.mock("@jazzer.js/fuzzer"); // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -260,7 +259,6 @@ function mockFuzzerApi() { } function mockHelpers() { - // eslint-disable-next-line @typescript-eslint/no-var-requires const helpers = require("./helpers"); jest.mock("./helpers"); return helpers; diff --git a/packages/instrumentor/plugins/sourceCodeCoverage.test.ts b/packages/instrumentor/plugins/sourceCodeCoverage.test.ts index 094db89a..4287d21a 100644 --- a/packages/instrumentor/plugins/sourceCodeCoverage.test.ts +++ b/packages/instrumentor/plugins/sourceCodeCoverage.test.ts @@ -21,7 +21,6 @@ import { Instrumentor } from "../instrument"; import * as libCoverage from "istanbul-lib-coverage"; import { sourceCodeCoverage } from "./sourceCodeCoverage"; -// eslint-disable-next-line @typescript-eslint/no-var-requires const fuzzer = require("@jazzer.js/fuzzer").fuzzer; jest.mock("@jazzer.js/fuzzer"); // eslint-disable-next-line @typescript-eslint/ban-ts-comment diff --git a/tests/FuzzedDataProvider/fuzz.js b/tests/FuzzedDataProvider/fuzz.js index 029dbc8d..3899321e 100644 --- a/tests/FuzzedDataProvider/fuzz.js +++ b/tests/FuzzedDataProvider/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const { FuzzedDataProvider } = require("@jazzer.js/core"); /** diff --git a/tests/bug-detectors/command-injection.test.js b/tests/bug-detectors/command-injection.test.js index ae5fd2b1..73c33b32 100644 --- a/tests/bug-detectors/command-injection.test.js +++ b/tests/bug-detectors/command-injection.test.js @@ -15,14 +15,8 @@ */ /* eslint no-undef: 0 */ -const { - FuzzTestBuilder, - FuzzingExitCode, - // eslint-disable-next-line @typescript-eslint/no-var-requires -} = require("../helpers.js"); -// eslint-disable-next-line @typescript-eslint/no-var-requires +const { FuzzTestBuilder, FuzzingExitCode } = require("../helpers.js"); const path = require("path"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const fs = require("fs"); describe("Command injection", () => { diff --git a/tests/bug-detectors/command-injection/fuzz.js b/tests/bug-detectors/command-injection/fuzz.js index 65cc078d..413d1b30 100644 --- a/tests/bug-detectors/command-injection/fuzz.js +++ b/tests/bug-detectors/command-injection/fuzz.js @@ -14,9 +14,7 @@ * limitations under the License. */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const child_process = require("child_process"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const { promisify } = require("util"); const friendlyFile = "FRIENDLY"; diff --git a/tests/bug-detectors/command-injection/makeFRIENDLY.js b/tests/bug-detectors/command-injection/makeFRIENDLY.js index 3293115f..c1db1b87 100644 --- a/tests/bug-detectors/command-injection/makeFRIENDLY.js +++ b/tests/bug-detectors/command-injection/makeFRIENDLY.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/no-var-requires const fs = require("fs"); fs.writeFileSync("FRIENDLY", ""); diff --git a/tests/bug-detectors/general.test.js b/tests/bug-detectors/general.test.js index 533587cf..6c767bdc 100644 --- a/tests/bug-detectors/general.test.js +++ b/tests/bug-detectors/general.test.js @@ -19,11 +19,8 @@ const { FuzzTestBuilder, FuzzingExitCode, JestRegressionExitCode, - // eslint-disable-next-line @typescript-eslint/no-var-requires } = require("../helpers.js"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const path = require("path"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const fs = require("fs"); describe("General tests", () => { diff --git a/tests/bug-detectors/general/fuzz.js b/tests/bug-detectors/general/fuzz.js index 50954401..688ec6db 100644 --- a/tests/bug-detectors/general/fuzz.js +++ b/tests/bug-detectors/general/fuzz.js @@ -15,7 +15,6 @@ */ /* eslint no-undef: 0 */ -/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ diff --git a/tests/bug-detectors/general/tests.fuzz.js b/tests/bug-detectors/general/tests.fuzz.js index e5c86ca8..e656b0a5 100644 --- a/tests/bug-detectors/general/tests.fuzz.js +++ b/tests/bug-detectors/general/tests.fuzz.js @@ -15,7 +15,6 @@ */ /* eslint no-undef: 0 */ -/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ diff --git a/tests/bug-detectors/path-traversal.test.js b/tests/bug-detectors/path-traversal.test.js index ed7d7a96..d6f7a38e 100644 --- a/tests/bug-detectors/path-traversal.test.js +++ b/tests/bug-detectors/path-traversal.test.js @@ -15,14 +15,8 @@ */ /* eslint no-undef: 0 */ -const { - FuzzTestBuilder, - FuzzingExitCode, - // eslint-disable-next-line @typescript-eslint/no-var-requires -} = require("../helpers.js"); -// eslint-disable-next-line @typescript-eslint/no-var-requires +const { FuzzTestBuilder, FuzzingExitCode } = require("../helpers.js"); const path = require("path"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const fs = require("fs"); describe("Path Traversal", () => { diff --git a/tests/bug-detectors/path-traversal/fuzz.js b/tests/bug-detectors/path-traversal/fuzz.js index 4f01f166..a7258922 100644 --- a/tests/bug-detectors/path-traversal/fuzz.js +++ b/tests/bug-detectors/path-traversal/fuzz.js @@ -15,7 +15,6 @@ */ /* eslint no-undef: 0 */ -/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ diff --git a/tests/code_coverage/coverage.test.js b/tests/code_coverage/coverage.test.js index 3b5ed903..f9eefcc0 100644 --- a/tests/code_coverage/coverage.test.js +++ b/tests/code_coverage/coverage.test.js @@ -14,7 +14,7 @@ * limitations under the License. */ -/* eslint no-undef: 0, @typescript-eslint/no-var-requires: 0 */ +/* eslint no-undef: 0 */ const fs = require("fs"); const path = require("path"); const { spawnSync } = require("child_process"); diff --git a/tests/code_coverage/sample_fuzz_test/codeCoverage.fuzz.js b/tests/code_coverage/sample_fuzz_test/codeCoverage.fuzz.js index 27c8af9a..917e8d6e 100644 --- a/tests/code_coverage/sample_fuzz_test/codeCoverage.fuzz.js +++ b/tests/code_coverage/sample_fuzz_test/codeCoverage.fuzz.js @@ -14,9 +14,8 @@ * limitations under the License. */ -/* eslint no-undef: 0, no-constant-condition: 0, @typescript-eslint/no-var-requires:0 */ +/* eslint no-undef: 0, no-constant-condition: 0 */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const target = require("./fuzz.js"); describe("My describe", () => { diff --git a/tests/code_coverage/sample_fuzz_test/custom-hooks.js b/tests/code_coverage/sample_fuzz_test/custom-hooks.js index cbe95b97..b6d0a9b3 100644 --- a/tests/code_coverage/sample_fuzz_test/custom-hooks.js +++ b/tests/code_coverage/sample_fuzz_test/custom-hooks.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/no-var-requires const { registerReplaceHook } = require("@jazzer.js/hooking"); // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+codeCoverage-fuzz.json b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+codeCoverage-fuzz.json index 0ff0bf1b..48e2e958 100644 --- a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+codeCoverage-fuzz.json +++ b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+codeCoverage-fuzz.json @@ -2,46 +2,46 @@ "codeCoverage.fuzz.js": { "statementMap": { "0": { - "start": { "line": 20, "column": 15 }, - "end": { "line": 20, "column": 35 } + "start": { "line": 19, "column": 15 }, + "end": { "line": 19, "column": 35 } }, "1": { - "start": { "line": 22, "column": 0 }, - "end": { "line": 26, "column": 3 } + "start": { "line": 21, "column": 0 }, + "end": { "line": 25, "column": 3 } }, "2": { - "start": { "line": 23, "column": 1 }, - "end": { "line": 25, "column": 4 } + "start": { "line": 22, "column": 1 }, + "end": { "line": 24, "column": 4 } }, "3": { - "start": { "line": 24, "column": 2 }, - "end": { "line": 24, "column": 20 } + "start": { "line": 23, "column": 2 }, + "end": { "line": 23, "column": 20 } } }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { - "start": { "line": 22, "column": 24 }, - "end": { "line": 22, "column": 25 } + "start": { "line": 21, "column": 24 }, + "end": { "line": 21, "column": 25 } }, "loc": { - "start": { "line": 22, "column": 30 }, - "end": { "line": 26, "column": 1 } + "start": { "line": 21, "column": 30 }, + "end": { "line": 25, "column": 1 } }, - "line": 22 + "line": 21 }, "1": { "name": "(anonymous_1)", "decl": { - "start": { "line": 23, "column": 25 }, - "end": { "line": 23, "column": 26 } + "start": { "line": 22, "column": 25 }, + "end": { "line": 22, "column": 26 } }, "loc": { - "start": { "line": 23, "column": 35 }, - "end": { "line": 25, "column": 2 } + "start": { "line": 22, "column": 35 }, + "end": { "line": 24, "column": 2 } }, - "line": 23 + "line": 22 } }, "branchMap": {}, @@ -54,59 +54,59 @@ "fuzz.js": { "statementMap": { "0": { - "start": { "line": 18, "column": 12 }, - "end": { "line": 18, "column": 28 } + "start": { "line": 17, "column": 12 }, + "end": { "line": 17, "column": 28 } }, "1": { - "start": { "line": 23, "column": 0 }, - "end": { "line": 29, "column": 2 } + "start": { "line": 22, "column": 0 }, + "end": { "line": 28, "column": 2 } }, "2": { - "start": { "line": 24, "column": 1 }, - "end": { "line": 24, "column": 41 } + "start": { "line": 23, "column": 1 }, + "end": { "line": 23, "column": 41 } }, "3": { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, "4": { - "start": { "line": 26, "column": 2 }, - "end": { "line": 26, "column": 9 } + "start": { "line": 25, "column": 2 }, + "end": { "line": 25, "column": 9 } }, "5": { - "start": { "line": 28, "column": 1 }, - "end": { "line": 28, "column": 18 } + "start": { "line": 27, "column": 1 }, + "end": { "line": 27, "column": 18 } } }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { - "start": { "line": 23, "column": 22 }, - "end": { "line": 23, "column": 23 } + "start": { "line": 22, "column": 22 }, + "end": { "line": 22, "column": 23 } }, "loc": { - "start": { "line": 23, "column": 38 }, - "end": { "line": 29, "column": 1 } + "start": { "line": 22, "column": 38 }, + "end": { "line": 28, "column": 1 } }, - "line": 23 + "line": 22 } }, "branchMap": { "0": { "loc": { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, "type": "if", "locations": [ { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, { "start": {}, "end": {} } ], - "line": 25 + "line": 24 } }, "s": { "0": 1, "1": 1, "2": 2, "3": 2, "4": 1, "5": 1 }, diff --git a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+customHooks.json b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+customHooks.json index 6cdf89fd..99e00ff9 100644 --- a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+customHooks.json +++ b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+customHooks.json @@ -2,30 +2,30 @@ "custom-hooks.js": { "statementMap": { "0": { - "start": { "line": 2, "column": 32 }, - "end": { "line": 2, "column": 61 } + "start": { "line": 1, "column": 32 }, + "end": { "line": 1, "column": 61 } }, "1": { - "start": { "line": 5, "column": 0 }, - "end": { "line": 7, "column": 3 } + "start": { "line": 4, "column": 0 }, + "end": { "line": 6, "column": 3 } }, "2": { - "start": { "line": 6, "column": 1 }, - "end": { "line": 6, "column": 37 } + "start": { "line": 5, "column": 1 }, + "end": { "line": 5, "column": 37 } } }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { - "start": { "line": 5, "column": 41 }, - "end": { "line": 5, "column": 42 } + "start": { "line": 4, "column": 41 }, + "end": { "line": 4, "column": 42 } }, "loc": { - "start": { "line": 5, "column": 78 }, - "end": { "line": 7, "column": 1 } + "start": { "line": 4, "column": 78 }, + "end": { "line": 6, "column": 1 } }, - "line": 5 + "line": 4 } }, "branchMap": {}, @@ -38,59 +38,59 @@ "fuzz.js": { "statementMap": { "0": { - "start": { "line": 18, "column": 12 }, - "end": { "line": 18, "column": 28 } + "start": { "line": 17, "column": 12 }, + "end": { "line": 17, "column": 28 } }, "1": { - "start": { "line": 23, "column": 0 }, - "end": { "line": 29, "column": 2 } + "start": { "line": 22, "column": 0 }, + "end": { "line": 28, "column": 2 } }, "2": { - "start": { "line": 24, "column": 1 }, - "end": { "line": 24, "column": 41 } + "start": { "line": 23, "column": 1 }, + "end": { "line": 23, "column": 41 } }, "3": { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, "4": { - "start": { "line": 26, "column": 2 }, - "end": { "line": 26, "column": 9 } + "start": { "line": 25, "column": 2 }, + "end": { "line": 25, "column": 9 } }, "5": { - "start": { "line": 28, "column": 1 }, - "end": { "line": 28, "column": 18 } + "start": { "line": 27, "column": 1 }, + "end": { "line": 27, "column": 18 } } }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { - "start": { "line": 23, "column": 22 }, - "end": { "line": 23, "column": 23 } + "start": { "line": 22, "column": 22 }, + "end": { "line": 22, "column": 23 } }, "loc": { - "start": { "line": 23, "column": 38 }, - "end": { "line": 29, "column": 1 } + "start": { "line": 22, "column": 38 }, + "end": { "line": 28, "column": 1 } }, - "line": 23 + "line": 22 } }, "branchMap": { "0": { "loc": { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, "type": "if", "locations": [ { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, { "start": {}, "end": {} } ], - "line": 25 + "line": 24 } }, "s": { "0": 1, "1": 1, "2": 3, "3": 3, "4": 2, "5": 1 }, diff --git a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+otherCodeCoverage-fuzz.json b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+otherCodeCoverage-fuzz.json index 4e6d7b9f..4e55f72d 100644 --- a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+otherCodeCoverage-fuzz.json +++ b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+otherCodeCoverage-fuzz.json @@ -63,59 +63,59 @@ "fuzz.js": { "statementMap": { "0": { - "start": { "line": 18, "column": 12 }, - "end": { "line": 18, "column": 28 } + "start": { "line": 17, "column": 12 }, + "end": { "line": 17, "column": 28 } }, "1": { - "start": { "line": 23, "column": 0 }, - "end": { "line": 29, "column": 2 } + "start": { "line": 22, "column": 0 }, + "end": { "line": 28, "column": 2 } }, "2": { - "start": { "line": 24, "column": 1 }, - "end": { "line": 24, "column": 41 } + "start": { "line": 23, "column": 1 }, + "end": { "line": 23, "column": 41 } }, "3": { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, "4": { - "start": { "line": 26, "column": 2 }, - "end": { "line": 26, "column": 9 } + "start": { "line": 25, "column": 2 }, + "end": { "line": 25, "column": 9 } }, "5": { - "start": { "line": 28, "column": 1 }, - "end": { "line": 28, "column": 18 } + "start": { "line": 27, "column": 1 }, + "end": { "line": 27, "column": 18 } } }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { - "start": { "line": 23, "column": 22 }, - "end": { "line": 23, "column": 23 } + "start": { "line": 22, "column": 22 }, + "end": { "line": 22, "column": 23 } }, "loc": { - "start": { "line": 23, "column": 38 }, - "end": { "line": 29, "column": 1 } + "start": { "line": 22, "column": 38 }, + "end": { "line": 28, "column": 1 } }, - "line": 23 + "line": 22 } }, "branchMap": { "0": { "loc": { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, "type": "if", "locations": [ { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, { "start": {}, "end": {} } ], - "line": 25 + "line": 24 } }, "s": { "0": 1, "1": 1, "2": 2, "3": 2, "4": 1, "5": 1 }, diff --git a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib.json b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib.json index 8647d119..ef204720 100644 --- a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib.json +++ b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib.json @@ -2,59 +2,59 @@ "fuzz.js": { "statementMap": { "0": { - "start": { "line": 18, "column": 12 }, - "end": { "line": 18, "column": 28 } + "start": { "line": 17, "column": 12 }, + "end": { "line": 17, "column": 28 } }, "1": { - "start": { "line": 23, "column": 0 }, - "end": { "line": 29, "column": 2 } + "start": { "line": 22, "column": 0 }, + "end": { "line": 28, "column": 2 } }, "2": { - "start": { "line": 24, "column": 1 }, - "end": { "line": 24, "column": 41 } + "start": { "line": 23, "column": 1 }, + "end": { "line": 23, "column": 41 } }, "3": { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, "4": { - "start": { "line": 26, "column": 2 }, - "end": { "line": 26, "column": 9 } + "start": { "line": 25, "column": 2 }, + "end": { "line": 25, "column": 9 } }, "5": { - "start": { "line": 28, "column": 1 }, - "end": { "line": 28, "column": 18 } + "start": { "line": 27, "column": 1 }, + "end": { "line": 27, "column": 18 } } }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { - "start": { "line": 23, "column": 22 }, - "end": { "line": 23, "column": 23 } + "start": { "line": 22, "column": 22 }, + "end": { "line": 22, "column": 23 } }, "loc": { - "start": { "line": 23, "column": 38 }, - "end": { "line": 29, "column": 1 } + "start": { "line": 22, "column": 38 }, + "end": { "line": 28, "column": 1 } }, - "line": 23 + "line": 22 } }, "branchMap": { "0": { "loc": { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, "type": "if", "locations": [ { - "start": { "line": 25, "column": 1 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 24, "column": 1 }, + "end": { "line": 26, "column": 2 } }, { "start": {}, "end": {} } ], - "line": 25 + "line": 24 } }, "s": { "0": 1, "1": 1, "2": 3, "3": 3, "4": 2, "5": 1 }, diff --git a/tests/code_coverage/sample_fuzz_test/fuzz.js b/tests/code_coverage/sample_fuzz_test/fuzz.js index 8aa449f7..e057e220 100644 --- a/tests/code_coverage/sample_fuzz_test/fuzz.js +++ b/tests/code_coverage/sample_fuzz_test/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const lib = require("./lib"); /** diff --git a/tests/helpers.js b/tests/helpers.js index a994f602..10283e5f 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -14,13 +14,10 @@ * limitations under the License. */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const { spawnSync } = require("child_process"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const fs = require("fs"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const path = require("path"); -// eslint-disable-next-line @typescript-eslint/no-var-requires + const assert = require("assert"); // This is used to distinguish an error thrown during fuzzing from other errors, diff --git a/tests/return_values/asyncRunnerAsyncReturns/fuzz.js b/tests/return_values/asyncRunnerAsyncReturns/fuzz.js index dadc8756..fc65797a 100644 --- a/tests/return_values/asyncRunnerAsyncReturns/fuzz.js +++ b/tests/return_values/asyncRunnerAsyncReturns/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-var-requires */ const code = require("../exampleCode/code"); let syncCtr = 0; diff --git a/tests/return_values/asyncRunnerMixedReturns/fuzz.js b/tests/return_values/asyncRunnerMixedReturns/fuzz.js index 36ba7142..5302c5f7 100644 --- a/tests/return_values/asyncRunnerMixedReturns/fuzz.js +++ b/tests/return_values/asyncRunnerMixedReturns/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-var-requires */ const code = require("../exampleCode/code"); let syncCtr = 0; diff --git a/tests/return_values/asyncRunnerSyncReturns/fuzz.js b/tests/return_values/asyncRunnerSyncReturns/fuzz.js index e98fe057..9dec2439 100644 --- a/tests/return_values/asyncRunnerSyncReturns/fuzz.js +++ b/tests/return_values/asyncRunnerSyncReturns/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-var-requires */ const code = require("../exampleCode/code"); let syncCtr = 0; diff --git a/tests/return_values/return_values.test.js b/tests/return_values/return_values.test.js index 061081b6..f78a6241 100644 --- a/tests/return_values/return_values.test.js +++ b/tests/return_values/return_values.test.js @@ -15,9 +15,7 @@ */ /* eslint no-undef: 0 */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const { spawnSync } = require("child_process"); -// eslint-disable-next-line @typescript-eslint/no-var-requires const path = require("path"); const SyncInfo = "Exclusively observed synchronous return values from fuzzed function. Fuzzing in synchronous mode seems benefical!"; diff --git a/tests/return_values/syncRunnerAsyncReturns/fuzz.js b/tests/return_values/syncRunnerAsyncReturns/fuzz.js index dadc8756..fc65797a 100644 --- a/tests/return_values/syncRunnerAsyncReturns/fuzz.js +++ b/tests/return_values/syncRunnerAsyncReturns/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-var-requires */ const code = require("../exampleCode/code"); let syncCtr = 0; diff --git a/tests/return_values/syncRunnerMixedReturns/fuzz.js b/tests/return_values/syncRunnerMixedReturns/fuzz.js index 36ba7142..5302c5f7 100644 --- a/tests/return_values/syncRunnerMixedReturns/fuzz.js +++ b/tests/return_values/syncRunnerMixedReturns/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-var-requires */ const code = require("../exampleCode/code"); let syncCtr = 0; diff --git a/tests/return_values/syncRunnerSyncReturns/fuzz.js b/tests/return_values/syncRunnerSyncReturns/fuzz.js index e98fe057..9dec2439 100644 --- a/tests/return_values/syncRunnerSyncReturns/fuzz.js +++ b/tests/return_values/syncRunnerSyncReturns/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-var-requires */ const code = require("../exampleCode/code"); let syncCtr = 0; diff --git a/tests/signal_handlers/SIGINT/tests.fuzz.js b/tests/signal_handlers/SIGINT/tests.fuzz.js index 238d4c29..858d6098 100644 --- a/tests/signal_handlers/SIGINT/tests.fuzz.js +++ b/tests/signal_handlers/SIGINT/tests.fuzz.js @@ -15,7 +15,6 @@ */ /* eslint no-undef: 0 */ -/* eslint-disable @typescript-eslint/no-var-requires */ const { SIGINT_SYNC, SIGINT_ASYNC } = require("./fuzz.js"); diff --git a/tests/signal_handlers/signal_handlers.test.js b/tests/signal_handlers/signal_handlers.test.js index e58a3614..2b4388b2 100644 --- a/tests/signal_handlers/signal_handlers.test.js +++ b/tests/signal_handlers/signal_handlers.test.js @@ -15,12 +15,7 @@ */ /* eslint no-undef: 0 */ -const { - FuzzTestBuilder, - describeSkipOnPlatform, - // eslint-disable-next-line @typescript-eslint/no-var-requires -} = require("../helpers.js"); -// eslint-disable-next-line @typescript-eslint/no-var-requires +const { FuzzTestBuilder, describeSkipOnPlatform } = require("../helpers.js"); const path = require("path"); // Signal handling in Node.js on Windows is only rudimentary supported. From 8b49297d5dd55e498bb12bfef405e1a1a3305dc8 Mon Sep 17 00:00:00 2001 From: Norbert Schneider Date: Tue, 11 Jul 2023 12:26:22 +0200 Subject: [PATCH 2/6] eslint: Properly configure Jest support Introduce Jest globals to not disable no-undef rule all the time. --- .eslintrc.json | 5 +-- examples/bug-detectors/path-traversal/fuzz.js | 29 +++++++-------- examples/jest_integration/integration.fuzz.js | 2 +- examples/jest_integration/integration.test.js | 2 -- examples/jest_integration/worker.fuzz.js | 2 -- .../workerGoldenReference.test.js | 2 -- .../integration.test.ts | 2 -- fuzztests/FuzzedDataProvider.fuzz.js | 4 +-- fuzztests/core.fuzz.js | 2 -- fuzztests/fuzzer.fuzz.js | 2 -- fuzztests/instrument.fuzz.js | 2 -- tests/bug-detectors/command-injection.test.js | 1 - tests/bug-detectors/general.test.js | 1 - tests/bug-detectors/general/fuzz.js | 1 - tests/bug-detectors/general/tests.fuzz.js | 1 - tests/bug-detectors/path-traversal.test.js | 1 - tests/bug-detectors/path-traversal/fuzz.js | 3 +- tests/code_coverage/coverage.test.js | 1 - .../sample_fuzz_test/codeCoverage.fuzz.js | 2 -- .../fuzz+lib+codeCoverage-fuzz.json | 36 +++++++++---------- tests/return_values/return_values.test.js | 1 - tests/signal_handlers/SIGINT/tests.fuzz.js | 2 -- tests/signal_handlers/signal_handlers.test.js | 1 - 23 files changed, 37 insertions(+), 68 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 475ba632..dd5a0c31 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,9 +1,10 @@ { "root": true, "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], + "plugins": ["@typescript-eslint", "jest"], "env": { - "node": true + "node": true, + "jest/globals": true }, "extends": [ "eslint:recommended", diff --git a/examples/bug-detectors/path-traversal/fuzz.js b/examples/bug-detectors/path-traversal/fuzz.js index 9d8ab933..bb831a87 100644 --- a/examples/bug-detectors/path-traversal/fuzz.js +++ b/examples/bug-detectors/path-traversal/fuzz.js @@ -24,20 +24,17 @@ const path = require("path"); module.exports.fuzz = function (data) { // Parse the buffer into a JSZip object. The buffer might have been obtained from an http-request. // See https://stuk.github.io/jszip/documentation/howto/read_zip.html for some examples. - return ( - JSZip.loadAsync(data) - .then((zip) => { - for (const file in zip.files) { - // We might want to extract the file from the zip archive and write it to disk. - // The loadAsync function should have sanitized the path already. - // Here we only construct the absolute path and trigger the path traversal bug. - // This issue was fixed in jszip 3.8.0. - path.join(__dirname, file); - } - }) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - .catch(() => { - /* ignore broken zip files */ - }) - ); + return JSZip.loadAsync(data) + .then((zip) => { + for (const file in zip.files) { + // We might want to extract the file from the zip archive and write it to disk. + // The loadAsync function should have sanitized the path already. + // Here we only construct the absolute path and trigger the path traversal bug. + // This issue was fixed in jszip 3.8.0. + path.join(__dirname, file); + } + }) + .catch(() => { + /* ignore broken zip files */ + }); }; diff --git a/examples/jest_integration/integration.fuzz.js b/examples/jest_integration/integration.fuzz.js index 7bb03fec..af7ba5c5 100644 --- a/examples/jest_integration/integration.fuzz.js +++ b/examples/jest_integration/integration.fuzz.js @@ -14,7 +14,7 @@ * limitations under the License. */ -/* eslint no-undef: 0, no-constant-condition: 0 */ +/* eslint no-constant-condition: 0 */ const target = require("./target.js"); diff --git a/examples/jest_integration/integration.test.js b/examples/jest_integration/integration.test.js index 044bfc1f..e95e347f 100644 --- a/examples/jest_integration/integration.test.js +++ b/examples/jest_integration/integration.test.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ - describe("My describe", () => { it("My normal Jest test", () => { expect(1).toEqual(1); diff --git a/examples/jest_integration/worker.fuzz.js b/examples/jest_integration/worker.fuzz.js index 912223d5..290d01d7 100644 --- a/examples/jest_integration/worker.fuzz.js +++ b/examples/jest_integration/worker.fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ - const target = require("./target"); const startupTeardownCalls = []; diff --git a/examples/jest_integration/workerGoldenReference.test.js b/examples/jest_integration/workerGoldenReference.test.js index b096ee86..3e87504e 100644 --- a/examples/jest_integration/workerGoldenReference.test.js +++ b/examples/jest_integration/workerGoldenReference.test.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ - const startupTeardownCalls = []; function addCallLog(uniqueId) { diff --git a/examples/jest_typescript_integration/integration.test.ts b/examples/jest_typescript_integration/integration.test.ts index 3ad4519c..05172efa 100644 --- a/examples/jest_typescript_integration/integration.test.ts +++ b/examples/jest_typescript_integration/integration.test.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ - import * as target from "./target"; describe("My describe", () => { diff --git a/fuzztests/FuzzedDataProvider.fuzz.js b/fuzztests/FuzzedDataProvider.fuzz.js index 5aedb778..be1a24d7 100644 --- a/fuzztests/FuzzedDataProvider.fuzz.js +++ b/fuzztests/FuzzedDataProvider.fuzz.js @@ -14,15 +14,13 @@ * limitations under the License. */ -/* eslint-disable no-undef */ - const { FuzzedDataProvider, jazzer } = require("@jazzer.js/core"); describe("FuzzedDataProvider", () => { // In this fuzz test we try to guide the fuzzer to use as many functions on // FuzzedDataProvider as possible, before invoking a terminating one // like consumeRemainingXY. Strange combinations of functions could produce a - // one off error. + // one-off error. it.fuzz( "consumes the provided input", (data) => { diff --git a/fuzztests/core.fuzz.js b/fuzztests/core.fuzz.js index 0cebf8d6..511e7320 100644 --- a/fuzztests/core.fuzz.js +++ b/fuzztests/core.fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint-disable no-undef */ - const { ensureFilepath } = require("@jazzer.js/core"); const cwd = process.cwd(); diff --git a/fuzztests/fuzzer.fuzz.js b/fuzztests/fuzzer.fuzz.js index a47bc427..a4813256 100644 --- a/fuzztests/fuzzer.fuzz.js +++ b/fuzztests/fuzzer.fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint-disable no-undef */ - const { fuzzer } = require("@jazzer.js/fuzzer"); const { FuzzedDataProvider } = require("@jazzer.js/core"); diff --git a/fuzztests/instrument.fuzz.js b/fuzztests/instrument.fuzz.js index f378c71f..30491aa5 100644 --- a/fuzztests/instrument.fuzz.js +++ b/fuzztests/instrument.fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint-disable no-undef */ - const { Instrumentor } = require("@jazzer.js/instrumentor"); const { FuzzedDataProvider } = require("@jazzer.js/core"); diff --git a/tests/bug-detectors/command-injection.test.js b/tests/bug-detectors/command-injection.test.js index 73c33b32..433538df 100644 --- a/tests/bug-detectors/command-injection.test.js +++ b/tests/bug-detectors/command-injection.test.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ const { FuzzTestBuilder, FuzzingExitCode } = require("../helpers.js"); const path = require("path"); const fs = require("fs"); diff --git a/tests/bug-detectors/general.test.js b/tests/bug-detectors/general.test.js index 6c767bdc..14f3a293 100644 --- a/tests/bug-detectors/general.test.js +++ b/tests/bug-detectors/general.test.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ const { FuzzTestBuilder, FuzzingExitCode, diff --git a/tests/bug-detectors/general/fuzz.js b/tests/bug-detectors/general/fuzz.js index 688ec6db..c9636990 100644 --- a/tests/bug-detectors/general/fuzz.js +++ b/tests/bug-detectors/general/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ diff --git a/tests/bug-detectors/general/tests.fuzz.js b/tests/bug-detectors/general/tests.fuzz.js index e656b0a5..6ea63cb0 100644 --- a/tests/bug-detectors/general/tests.fuzz.js +++ b/tests/bug-detectors/general/tests.fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ diff --git a/tests/bug-detectors/path-traversal.test.js b/tests/bug-detectors/path-traversal.test.js index d6f7a38e..66998231 100644 --- a/tests/bug-detectors/path-traversal.test.js +++ b/tests/bug-detectors/path-traversal.test.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ const { FuzzTestBuilder, FuzzingExitCode } = require("../helpers.js"); const path = require("path"); const fs = require("fs"); diff --git a/tests/bug-detectors/path-traversal/fuzz.js b/tests/bug-detectors/path-traversal/fuzz.js index a7258922..b716a875 100644 --- a/tests/bug-detectors/path-traversal/fuzz.js +++ b/tests/bug-detectors/path-traversal/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ @@ -22,7 +21,7 @@ const fs = require("fs"); const fsp = require("fs").promises; const path = require("path"); -const { makeFnCalledOnce } = require("../../helpers"); +const { makeFnCalledOnce, callWithTimeout } = require("../../helpers"); const evil_path = "../../jaz_zer/"; const safe_path = "../../safe_path/"; diff --git a/tests/code_coverage/coverage.test.js b/tests/code_coverage/coverage.test.js index f9eefcc0..98d8137f 100644 --- a/tests/code_coverage/coverage.test.js +++ b/tests/code_coverage/coverage.test.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ const fs = require("fs"); const path = require("path"); const { spawnSync } = require("child_process"); diff --git a/tests/code_coverage/sample_fuzz_test/codeCoverage.fuzz.js b/tests/code_coverage/sample_fuzz_test/codeCoverage.fuzz.js index 917e8d6e..191d5439 100644 --- a/tests/code_coverage/sample_fuzz_test/codeCoverage.fuzz.js +++ b/tests/code_coverage/sample_fuzz_test/codeCoverage.fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0, no-constant-condition: 0 */ - const target = require("./fuzz.js"); describe("My describe", () => { diff --git a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+codeCoverage-fuzz.json b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+codeCoverage-fuzz.json index 48e2e958..c2501a52 100644 --- a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+codeCoverage-fuzz.json +++ b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+codeCoverage-fuzz.json @@ -2,46 +2,46 @@ "codeCoverage.fuzz.js": { "statementMap": { "0": { - "start": { "line": 19, "column": 15 }, - "end": { "line": 19, "column": 35 } + "start": { "line": 17, "column": 15 }, + "end": { "line": 17, "column": 35 } }, "1": { - "start": { "line": 21, "column": 0 }, - "end": { "line": 25, "column": 3 } + "start": { "line": 19, "column": 0 }, + "end": { "line": 23, "column": 3 } }, "2": { - "start": { "line": 22, "column": 1 }, - "end": { "line": 24, "column": 4 } + "start": { "line": 20, "column": 1 }, + "end": { "line": 22, "column": 4 } }, "3": { - "start": { "line": 23, "column": 2 }, - "end": { "line": 23, "column": 20 } + "start": { "line": 21, "column": 2 }, + "end": { "line": 21, "column": 20 } } }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { - "start": { "line": 21, "column": 24 }, - "end": { "line": 21, "column": 25 } + "start": { "line": 19, "column": 24 }, + "end": { "line": 19, "column": 25 } }, "loc": { - "start": { "line": 21, "column": 30 }, - "end": { "line": 25, "column": 1 } + "start": { "line": 19, "column": 30 }, + "end": { "line": 23, "column": 1 } }, - "line": 21 + "line": 19 }, "1": { "name": "(anonymous_1)", "decl": { - "start": { "line": 22, "column": 25 }, - "end": { "line": 22, "column": 26 } + "start": { "line": 20, "column": 25 }, + "end": { "line": 20, "column": 26 } }, "loc": { - "start": { "line": 22, "column": 35 }, - "end": { "line": 24, "column": 2 } + "start": { "line": 20, "column": 35 }, + "end": { "line": 22, "column": 2 } }, - "line": 22 + "line": 20 } }, "branchMap": {}, diff --git a/tests/return_values/return_values.test.js b/tests/return_values/return_values.test.js index f78a6241..1836b0d2 100644 --- a/tests/return_values/return_values.test.js +++ b/tests/return_values/return_values.test.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ const { spawnSync } = require("child_process"); const path = require("path"); const SyncInfo = diff --git a/tests/signal_handlers/SIGINT/tests.fuzz.js b/tests/signal_handlers/SIGINT/tests.fuzz.js index 858d6098..51e7bad1 100644 --- a/tests/signal_handlers/SIGINT/tests.fuzz.js +++ b/tests/signal_handlers/SIGINT/tests.fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ - const { SIGINT_SYNC, SIGINT_ASYNC } = require("./fuzz.js"); describe("Jest", () => { diff --git a/tests/signal_handlers/signal_handlers.test.js b/tests/signal_handlers/signal_handlers.test.js index 2b4388b2..46a24a0c 100644 --- a/tests/signal_handlers/signal_handlers.test.js +++ b/tests/signal_handlers/signal_handlers.test.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-undef: 0 */ const { FuzzTestBuilder, describeSkipOnPlatform } = require("../helpers.js"); const path = require("path"); From 985f9599ede98b472505cee1b0e2b45cd7c358e3 Mon Sep 17 00:00:00 2001 From: Norbert Schneider Date: Tue, 11 Jul 2023 12:36:42 +0200 Subject: [PATCH 3/6] eslint: Disable ban-ts-comment The JavaScript interop requires to disable TypeScript checks at some places. Disable this rule for now. --- .eslintrc.json | 3 ++- packages/instrumentor/instrument.test.ts | 2 -- packages/instrumentor/plugins/compareHooks.test.ts | 1 - packages/instrumentor/plugins/functionHooks.test.ts | 1 - packages/instrumentor/plugins/sourceCodeCoverage.test.ts | 1 - packages/jest-runner/fuzz.test.ts | 1 - packages/jest-runner/fuzz.ts | 2 -- packages/jest-runner/worker.ts | 2 -- 8 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index dd5a0c31..1536ea4d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -15,7 +15,8 @@ { "files": ["*.js", "*.ts"], "rules": { - "@typescript-eslint/no-var-requires": "off" + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/ban-ts-comment": "off" } }, { diff --git a/packages/instrumentor/instrument.test.ts b/packages/instrumentor/instrument.test.ts index 2e40cfac..b9036567 100644 --- a/packages/instrumentor/instrument.test.ts +++ b/packages/instrumentor/instrument.test.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint @typescript-eslint/ban-ts-comment:0 */ - import * as ts from "typescript"; import { Instrumentor } from "./instrument"; diff --git a/packages/instrumentor/plugins/compareHooks.test.ts b/packages/instrumentor/plugins/compareHooks.test.ts index 66faf5a4..ff9a235f 100644 --- a/packages/instrumentor/plugins/compareHooks.test.ts +++ b/packages/instrumentor/plugins/compareHooks.test.ts @@ -252,7 +252,6 @@ describe("compare hooks instrumentation", () => { function mockFuzzerApi() { const fuzzer = require("@jazzer.js/fuzzer").fuzzer; jest.mock("@jazzer.js/fuzzer"); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore global.Fuzzer = fuzzer; return fuzzer; diff --git a/packages/instrumentor/plugins/functionHooks.test.ts b/packages/instrumentor/plugins/functionHooks.test.ts index 2de57f5c..17f09cc1 100644 --- a/packages/instrumentor/plugins/functionHooks.test.ts +++ b/packages/instrumentor/plugins/functionHooks.test.ts @@ -908,7 +908,6 @@ describe("function hooks instrumentation", () => { }); function registerHookManagerGlobally() { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore global.HookManager = hooking.hookManager; } diff --git a/packages/instrumentor/plugins/sourceCodeCoverage.test.ts b/packages/instrumentor/plugins/sourceCodeCoverage.test.ts index 4287d21a..aa8f148d 100644 --- a/packages/instrumentor/plugins/sourceCodeCoverage.test.ts +++ b/packages/instrumentor/plugins/sourceCodeCoverage.test.ts @@ -23,7 +23,6 @@ import { sourceCodeCoverage } from "./sourceCodeCoverage"; const fuzzer = require("@jazzer.js/fuzzer").fuzzer; jest.mock("@jazzer.js/fuzzer"); -// eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore global.Fuzzer = fuzzer; diff --git a/packages/jest-runner/fuzz.test.ts b/packages/jest-runner/fuzz.test.ts index 54d4a99f..8d86372a 100644 --- a/packages/jest-runner/fuzz.test.ts +++ b/packages/jest-runner/fuzz.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ /* * Copyright 2022 Code Intelligence GmbH * diff --git a/packages/jest-runner/fuzz.ts b/packages/jest-runner/fuzz.ts index daf70ed5..ad07e137 100644 --- a/packages/jest-runner/fuzz.ts +++ b/packages/jest-runner/fuzz.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/ban-ts-comment */ - import { Global } from "@jest/types"; import { FuzzTarget, diff --git a/packages/jest-runner/worker.ts b/packages/jest-runner/worker.ts index 27401753..602d97d5 100644 --- a/packages/jest-runner/worker.ts +++ b/packages/jest-runner/worker.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/ban-ts-comment */ - import { Test } from "jest-runner"; import { Circus, Config } from "@jest/types"; import { TestResult } from "@jest/test-result"; From 16c9f52cc877707546671f4715ebfd4771bcde74 Mon Sep 17 00:00:00 2001 From: Norbert Schneider Date: Tue, 11 Jul 2023 13:10:52 +0200 Subject: [PATCH 4/6] eslint: Disable no-unused-vars As Jest fuzz functions require the data parameter, even if not used, disable the no-unused-vars check globally. --- .eslintrc.json | 3 ++- .../command-injection/custom-hooks.js | 4 +--- examples/custom-hooks/custom-hooks.js | 7 ++----- examples/jest_integration/integration.fuzz.js | 1 - examples/jest_integration/worker.fuzz.js | 1 - .../workerGoldenReference.test.js | 1 - packages/instrumentor/edgeIdStrategy.ts | 4 ---- .../instrumentor/plugins/functionHooks.test.ts | 3 --- packages/jest-runner/fuzz.test.ts | 2 -- packages/jest-runner/index.ts | 2 +- tests/bug-detectors/command-injection/fuzz.js | 12 ------------ tests/bug-detectors/general/fuzz.js | 1 - tests/bug-detectors/general/tests.fuzz.js | 2 -- tests/bug-detectors/path-traversal/fuzz.js | 3 +-- .../sample_fuzz_test/custom-hooks.js | 3 +-- .../fuzz+lib+customHooks.json | 18 +++++++++--------- tests/return_values/return_values.test.js | 1 - tests/signal_handlers/SIGINT/fuzz.js | 2 -- 18 files changed, 17 insertions(+), 53 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 1536ea4d..1a32858b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -16,7 +16,8 @@ "files": ["*.js", "*.ts"], "rules": { "@typescript-eslint/no-var-requires": "off", - "@typescript-eslint/ban-ts-comment": "off" + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/no-unused-vars": "off" } }, { diff --git a/examples/bug-detectors/command-injection/custom-hooks.js b/examples/bug-detectors/command-injection/custom-hooks.js index 0c65aba2..3fae17b0 100644 --- a/examples/bug-detectors/command-injection/custom-hooks.js +++ b/examples/bug-detectors/command-injection/custom-hooks.js @@ -16,8 +16,6 @@ * Examples showcasing the custom hooks API */ -/* eslint-disable @typescript-eslint/no-unused-vars */ - const { registerReplaceHook } = require("@jazzer.js/hooking"); const { reportFinding } = require("@jazzer.js/bug-detectors"); const { guideTowardsEquality } = require("@jazzer.js/fuzzer"); @@ -29,7 +27,7 @@ registerReplaceHook( "execSync", "child_process", false, - (thisPtr, params, hookId, origFn) => { + (thisPtr, params, hookId) => { if (params === undefined || params.length === 0) { return; } diff --git a/examples/custom-hooks/custom-hooks.js b/examples/custom-hooks/custom-hooks.js index 97fd6f4a..4526bda7 100644 --- a/examples/custom-hooks/custom-hooks.js +++ b/examples/custom-hooks/custom-hooks.js @@ -1,6 +1,3 @@ -// noinspection JSUnusedLocalSymbols -/* eslint-disable @typescript-eslint/no-unused-vars */ - /* * Copyright 2022 Code Intelligence GmbH * @@ -32,7 +29,7 @@ registerReplaceHook( "JpegImage.jpegImage.constructor.prototype.copyToImageData.copyToImageData", "jpeg-js", false, - (thisPtr, params, hookId, origFn) => { + (thisPtr, params) => { if (params[0].data[0] === 0) { // we are only interested in image frames in which data[0] equals zero throw Error( @@ -101,7 +98,7 @@ registerBeforeHook( "JpegImage.jpegImage.constructor.prototype.parse.parse.readDataBlock", "jpeg-js", false, - (thisPtr, params, hookId) => { + () => { console.log( `[jpeg-js] [before] Called hooked function before calling resetMaxMemoryUsage()`, ); diff --git a/examples/jest_integration/integration.fuzz.js b/examples/jest_integration/integration.fuzz.js index af7ba5c5..506e0a2a 100644 --- a/examples/jest_integration/integration.fuzz.js +++ b/examples/jest_integration/integration.fuzz.js @@ -73,7 +73,6 @@ describe("My describe", () => { // regression and fuzzing mode. libFuzzer shuts down the process after Jest // received the error and displayed its result. // Two parameters are required to execute the done callback branch. - // eslint-disable-next-line @typescript-eslint/no-unused-vars it.skip.fuzz("Done callback timeout", (ignore, ignore2) => { // don't call done }); diff --git a/examples/jest_integration/worker.fuzz.js b/examples/jest_integration/worker.fuzz.js index 290d01d7..72329f20 100644 --- a/examples/jest_integration/worker.fuzz.js +++ b/examples/jest_integration/worker.fuzz.js @@ -56,7 +56,6 @@ describe("Hooks", () => { let test = 0; // Busy wait, do nothing for (let i = 0; i < 1000; i++) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars test++; } addCallLog("My describe: afterEach"); diff --git a/examples/jest_integration/workerGoldenReference.test.js b/examples/jest_integration/workerGoldenReference.test.js index 3e87504e..9ea52d42 100644 --- a/examples/jest_integration/workerGoldenReference.test.js +++ b/examples/jest_integration/workerGoldenReference.test.js @@ -58,7 +58,6 @@ describe("My describe", () => { let test = 0; // Busy wait, do nothing for (let i = 0; i < 1000; i++) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars test++; } addCallLog("My describe: afterEach"); diff --git a/packages/instrumentor/edgeIdStrategy.ts b/packages/instrumentor/edgeIdStrategy.ts index 254a6a80..797f30ef 100644 --- a/packages/instrumentor/edgeIdStrategy.ts +++ b/packages/instrumentor/edgeIdStrategy.ts @@ -60,12 +60,10 @@ export class MemorySyncIdStrategy extends IncrementingEdgeIdStrategy { super(0); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars startForSourceFile(filename: string): void { // nothing to do here } - // eslint-disable-next-line @typescript-eslint/no-unused-vars commitIdCount(filename: string) { // nothing to do here } @@ -240,12 +238,10 @@ export class ZeroEdgeIdStrategy implements EdgeIdStrategy { return 0; } - // eslint-disable-next-line @typescript-eslint/no-unused-vars startForSourceFile(filename: string): void { // Nothing to do here } - // eslint-disable-next-line @typescript-eslint/no-unused-vars commitIdCount(filename: string): void { // Nothing to do here } diff --git a/packages/instrumentor/plugins/functionHooks.test.ts b/packages/instrumentor/plugins/functionHooks.test.ts index 17f09cc1..4be91f1e 100644 --- a/packages/instrumentor/plugins/functionHooks.test.ts +++ b/packages/instrumentor/plugins/functionHooks.test.ts @@ -14,9 +14,6 @@ * limitations under the License. */ -/* eslint @typescript-eslint/no-unused-vars: 0 */ -/* eslint @typescript-eslint/no-empty-function: 0 */ - import { instrumentAndEvalWith } from "./testhelpers"; import { functionHooks } from "./functionHooks"; import * as hooking from "@jazzer.js/hooking"; diff --git a/packages/jest-runner/fuzz.test.ts b/packages/jest-runner/fuzz.test.ts index 8d86372a..ba3e67fe 100644 --- a/packages/jest-runner/fuzz.test.ts +++ b/packages/jest-runner/fuzz.test.ts @@ -151,7 +151,6 @@ describe("fuzz", () => { runInRegressionMode( "fuzz", // Parameters needed to pass in done callback. - // eslint-disable-next-line @typescript-eslint/no-unused-vars (ignored: Buffer, ignored2: (e?: Error) => void) => { return new Promise(() => { // promise is ignored due to done callback @@ -172,7 +171,6 @@ describe("fuzz", () => { withMockTest(() => { runInRegressionMode( "fuzz", - // eslint-disable-next-line @typescript-eslint/no-unused-vars (ignored: Buffer, done: (e?: Error) => void) => { done(); done(); diff --git a/packages/jest-runner/index.ts b/packages/jest-runner/index.ts index 2dfb4336..1e5f8d85 100644 --- a/packages/jest-runner/index.ts +++ b/packages/jest-runner/index.ts @@ -48,7 +48,7 @@ class FuzzRunner extends CallbackTestRunner { onStart: OnTestStart, onResult: OnTestSuccess, onFailure: OnTestFailure, - options: TestRunnerOptions, // eslint-disable-line @typescript-eslint/no-unused-vars + options: TestRunnerOptions, ): Promise { const config = loadConfig(); config.coverage = this.shouldCollectCoverage; diff --git a/tests/bug-detectors/command-injection/fuzz.js b/tests/bug-detectors/command-injection/fuzz.js index 413d1b30..83c4ce7d 100644 --- a/tests/bug-detectors/command-injection/fuzz.js +++ b/tests/bug-detectors/command-injection/fuzz.js @@ -23,22 +23,18 @@ const evilCommand = "jaz_zer"; const friendlyCommand = (process.platform === "win32" ? "copy NUL " : "touch ") + friendlyFile; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.execEVIL = async function (data) { child_process.exec(evilCommand); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.execFRIENDLY = async function (data) { child_process.exec(friendlyCommand); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.execFileEVIL = async function (data) { child_process.execFile(evilCommand); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.execFileFRIENDLY = async function (data) { const command = process.platform === "win32" ? "copy" : "touch"; const args = @@ -47,12 +43,10 @@ module.exports.execFileFRIENDLY = async function (data) { await execFile(command, args, { shell: true }); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.execFileSyncEVIL = function (data) { child_process.execFileSync(evilCommand); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.execFileSyncFRIENDLY = function (data) { const command = process.platform === "win32" ? "copy" : "touch"; const args = @@ -61,12 +55,10 @@ module.exports.execFileSyncFRIENDLY = function (data) { child_process.execFileSync(command, args, options); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.spawnEVIL = async function (data) { child_process.spawn(evilCommand); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.spawnFRIENDLY = async function (data) { const command = process.platform === "win32" ? "copy" : "touch"; const args = @@ -82,12 +74,10 @@ module.exports.spawnFRIENDLY = async function (data) { }); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.spawnSyncEVIL = function (data) { child_process.spawnSync(evilCommand); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.spawnSyncFRIENDLY = function (data) { const command = process.platform === "win32" ? "copy" : "touch"; const args = @@ -95,12 +85,10 @@ module.exports.spawnSyncFRIENDLY = function (data) { child_process.spawnSync(command, args, { shell: true }); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.forkEVIL = function (data) { child_process.fork(evilCommand); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.forkFRIENDLY = function (data) { child_process.fork("makeFRIENDLY.js"); }; diff --git a/tests/bug-detectors/general/fuzz.js b/tests/bug-detectors/general/fuzz.js index c9636990..02510822 100644 --- a/tests/bug-detectors/general/fuzz.js +++ b/tests/bug-detectors/general/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ const child_process = require("child_process"); diff --git a/tests/bug-detectors/general/tests.fuzz.js b/tests/bug-detectors/general/tests.fuzz.js index 6ea63cb0..f5cce32f 100644 --- a/tests/bug-detectors/general/tests.fuzz.js +++ b/tests/bug-detectors/general/tests.fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ const child_process = require("child_process"); @@ -81,7 +80,6 @@ function test(data) { function makeFuzzFunctionWithInput(n, input) { assert(n > 0); let i = n; - // eslint-disable-next-line @typescript-eslint/no-unused-vars return function (data) { i--; if (i === 0) { diff --git a/tests/bug-detectors/path-traversal/fuzz.js b/tests/bug-detectors/path-traversal/fuzz.js index b716a875..6c915924 100644 --- a/tests/bug-detectors/path-traversal/fuzz.js +++ b/tests/bug-detectors/path-traversal/fuzz.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ const fs = require("fs"); @@ -38,7 +37,7 @@ module.exports.PathTraversalFsOpenEvilSync = makeFnCalledOnce((data) => { }); module.exports.PathTraversalFsOpenEvilAsync = makeFnCalledOnce(async (data) => { - fs.open(evil_path, "r", (err, f) => {}); + fs.open(evil_path, "r", () => {}); }); module.exports.PathTraversalFsMkdirEvilSync = makeFnCalledOnce((data) => { diff --git a/tests/code_coverage/sample_fuzz_test/custom-hooks.js b/tests/code_coverage/sample_fuzz_test/custom-hooks.js index b6d0a9b3..f187f36b 100644 --- a/tests/code_coverage/sample_fuzz_test/custom-hooks.js +++ b/tests/code_coverage/sample_fuzz_test/custom-hooks.js @@ -1,6 +1,5 @@ const { registerReplaceHook } = require("@jazzer.js/hooking"); -// eslint-disable-next-line @typescript-eslint/no-unused-vars -registerReplaceHook("foo", "lib", false, (thisPtr, params, hookId, origFn) => { +registerReplaceHook("foo", "lib", false, () => { console.log("CUSTOM HOOKS CALLED!"); }); diff --git a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+customHooks.json b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+customHooks.json index 99e00ff9..c972495e 100644 --- a/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+customHooks.json +++ b/tests/code_coverage/sample_fuzz_test/expected_coverage/fuzz+lib+customHooks.json @@ -6,26 +6,26 @@ "end": { "line": 1, "column": 61 } }, "1": { - "start": { "line": 4, "column": 0 }, - "end": { "line": 6, "column": 3 } + "start": { "line": 3, "column": 0 }, + "end": { "line": 5, "column": 3 } }, "2": { - "start": { "line": 5, "column": 1 }, - "end": { "line": 5, "column": 37 } + "start": { "line": 4, "column": 1 }, + "end": { "line": 4, "column": 37 } } }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { - "start": { "line": 4, "column": 41 }, - "end": { "line": 4, "column": 42 } + "start": { "line": 3, "column": 41 }, + "end": { "line": 3, "column": 42 } }, "loc": { - "start": { "line": 4, "column": 78 }, - "end": { "line": 6, "column": 1 } + "start": { "line": 3, "column": 47 }, + "end": { "line": 5, "column": 1 } }, - "line": 4 + "line": 3 } }, "branchMap": {}, diff --git a/tests/return_values/return_values.test.js b/tests/return_values/return_values.test.js index 1836b0d2..662d0a2a 100644 --- a/tests/return_values/return_values.test.js +++ b/tests/return_values/return_values.test.js @@ -68,7 +68,6 @@ function executeFuzzTest(sync, verbose, dir) { // Specify mode if (sync) options.push("--sync"); options.push("--"); - // eslint-disable-next-line @typescript-eslint/no-unused-vars const process = spawnSync("npx", options, { stdio: "pipe", cwd: dir, diff --git a/tests/signal_handlers/SIGINT/fuzz.js b/tests/signal_handlers/SIGINT/fuzz.js index ab76313e..f0a009aa 100644 --- a/tests/signal_handlers/SIGINT/fuzz.js +++ b/tests/signal_handlers/SIGINT/fuzz.js @@ -16,7 +16,6 @@ let i = 0; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.SIGINT_SYNC = (data) => { if (i === 1000) { console.log("kill with SIGINT"); @@ -28,7 +27,6 @@ module.exports.SIGINT_SYNC = (data) => { i++; }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars module.exports.SIGINT_ASYNC = (data) => { // Raising SIGINT in async mode does not stop the fuzzer directly, // as the event is handled asynchronously in the event loop. From f95351fa852e566e69fc78f51185ed68941a002a Mon Sep 17 00:00:00 2001 From: Norbert Schneider Date: Tue, 11 Jul 2023 13:14:26 +0200 Subject: [PATCH 5/6] eslint: Fix no-empty-function errors --- examples/custom-hooks/custom-hooks.js | 5 +++-- packages/fuzzer/fuzzer.test.ts | 1 - packages/hooking/manager.test.ts | 19 +++++++++---------- tests/bug-detectors/general/fuzz.js | 3 --- tests/bug-detectors/general/tests.fuzz.js | 4 +--- tests/bug-detectors/path-traversal/fuzz.js | 14 +++++++++----- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/examples/custom-hooks/custom-hooks.js b/examples/custom-hooks/custom-hooks.js index 4526bda7..23467306 100644 --- a/examples/custom-hooks/custom-hooks.js +++ b/examples/custom-hooks/custom-hooks.js @@ -128,6 +128,7 @@ registerReplaceHook( "JpegImage.jpegImage.constructor.prototype.parse.parse.NonExistingFunc", "jpeg-js", false, - // eslint-disable-next-line @typescript-eslint/no-empty-function - () => {}, + () => { + /* empty */ + }, ); diff --git a/packages/fuzzer/fuzzer.test.ts b/packages/fuzzer/fuzzer.test.ts index ccf55ba8..8b9d991f 100644 --- a/packages/fuzzer/fuzzer.test.ts +++ b/packages/fuzzer/fuzzer.test.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint no-empty-function: 0 */ import { fuzzer } from "./fuzzer"; describe("compare hooks", () => { diff --git a/packages/hooking/manager.test.ts b/packages/hooking/manager.test.ts index da0c664c..e3500006 100644 --- a/packages/hooking/manager.test.ts +++ b/packages/hooking/manager.test.ts @@ -1,7 +1,6 @@ import { hookManager } from "./manager"; import { HookType } from "./hook"; -/* eslint @typescript-eslint/no-empty-function: 0 */ /* eslint @typescript-eslint/ban-types: 0 */ describe("Hooks manager", () => { @@ -100,18 +99,18 @@ function registerHook( ) { switch (hookType) { case HookType.Before: - hookManager.registerHook(HookType.Before, target, pkg, isAsync, () => {}); + hookManager.registerHook(HookType.Before, target, pkg, isAsync, () => { + /* empty */ + }); break; case HookType.Replace: - hookManager.registerHook( - HookType.Replace, - target, - pkg, - isAsync, - () => {}, - ); + hookManager.registerHook(HookType.Replace, target, pkg, isAsync, () => { + /* empty */ + }); break; case HookType.After: - hookManager.registerHook(HookType.After, target, pkg, isAsync, () => {}); + hookManager.registerHook(HookType.After, target, pkg, isAsync, () => { + /* empty */ + }); } } diff --git a/tests/bug-detectors/general/fuzz.js b/tests/bug-detectors/general/fuzz.js index 02510822..fae78b38 100644 --- a/tests/bug-detectors/general/fuzz.js +++ b/tests/bug-detectors/general/fuzz.js @@ -14,10 +14,7 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-empty-function */ - const child_process = require("child_process"); -const path = require("path"); const fs = require("fs"); const assert = require("assert"); const { platform } = require("os"); diff --git a/tests/bug-detectors/general/tests.fuzz.js b/tests/bug-detectors/general/tests.fuzz.js index f5cce32f..1b5aa65b 100644 --- a/tests/bug-detectors/general/tests.fuzz.js +++ b/tests/bug-detectors/general/tests.fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-empty-function */ - const child_process = require("child_process"); const assert = require("assert"); @@ -69,7 +67,7 @@ function test(data) { try { child_process.execSync(data); } catch (e) { - // eslint-disable-line no-empty + // Ignored } } diff --git a/tests/bug-detectors/path-traversal/fuzz.js b/tests/bug-detectors/path-traversal/fuzz.js index 6c915924..3e0ce866 100644 --- a/tests/bug-detectors/path-traversal/fuzz.js +++ b/tests/bug-detectors/path-traversal/fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint-disable @typescript-eslint/no-empty-function */ - const fs = require("fs"); const fsp = require("fs").promises; const path = require("path"); @@ -37,7 +35,9 @@ module.exports.PathTraversalFsOpenEvilSync = makeFnCalledOnce((data) => { }); module.exports.PathTraversalFsOpenEvilAsync = makeFnCalledOnce(async (data) => { - fs.open(evil_path, "r", () => {}); + fs.open(evil_path, "r", () => { + /* empty */ + }); }); module.exports.PathTraversalFsMkdirEvilSync = makeFnCalledOnce((data) => { @@ -50,13 +50,17 @@ module.exports.PathTraversalFsMkdirSafeSync = makeFnCalledOnce((data) => { module.exports.PathTraversalFsMkdirEvilAsync = makeFnCalledOnce( async (data) => { - fs.mkdir(evil_path, () => {}); + fs.mkdir(evil_path, () => { + /* empty */ + }); }, ); module.exports.PathTraversalFsMkdirSafeAsync = makeFnCalledOnce( async (data) => { - fs.mkdir(safe_path, () => {}); + fs.mkdir(safe_path, () => { + /* empty */ + }); }, ); From eba94c5d3d6fd427677280fbddfef5afac8e2ba1 Mon Sep 17 00:00:00 2001 From: Norbert Schneider Date: Tue, 11 Jul 2023 13:21:45 +0200 Subject: [PATCH 6/6] eslint: Fix no-explicit-any errors --- examples/jest_integration/integration.fuzz.js | 4 +--- packages/hooking/hook.ts | 3 ++- packages/hooking/manager.test.ts | 18 ++++++++++++++++-- .../instrumentor/plugins/functionHooks.test.ts | 9 +++------ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/examples/jest_integration/integration.fuzz.js b/examples/jest_integration/integration.fuzz.js index 506e0a2a..19cd405d 100644 --- a/examples/jest_integration/integration.fuzz.js +++ b/examples/jest_integration/integration.fuzz.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint no-constant-condition: 0 */ - const target = require("./target.js"); describe("My describe", () => { @@ -55,7 +53,7 @@ describe("My describe", () => { // finding and shut down the whole process with exit code 70. it.skip.fuzz("Sync timeout", () => { // noinspection InfiniteLoopJS - while (true) { + for (;;) { // Ignore } }); diff --git a/packages/hooking/hook.ts b/packages/hooking/hook.ts index f27bddfe..f531f1cc 100644 --- a/packages/hooking/hook.ts +++ b/packages/hooking/hook.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +/* eslint @typescript-eslint/no-explicit-any: 0 */ + export interface TrackedHook { target: string; pkg: string; @@ -143,7 +145,6 @@ export function logHooks(hooks: Hook[]) { export const hookTracker = new HookTracker(); -/*eslint @typescript-eslint/no-explicit-any: 0 */ export enum HookType { Before, After, diff --git a/packages/hooking/manager.test.ts b/packages/hooking/manager.test.ts index e3500006..72238897 100644 --- a/packages/hooking/manager.test.ts +++ b/packages/hooking/manager.test.ts @@ -1,8 +1,22 @@ +/* + * Copyright 2023 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { hookManager } from "./manager"; import { HookType } from "./hook"; -/* eslint @typescript-eslint/ban-types: 0 */ - describe("Hooks manager", () => { describe("Matching hooks", () => { it("should be valid when having a single REPLACE hook", () => { diff --git a/packages/instrumentor/plugins/functionHooks.test.ts b/packages/instrumentor/plugins/functionHooks.test.ts index 4be91f1e..d77034f3 100644 --- a/packages/instrumentor/plugins/functionHooks.test.ts +++ b/packages/instrumentor/plugins/functionHooks.test.ts @@ -562,8 +562,7 @@ describe("function hooks instrumentation", () => { expectTrackedHooksUnknown(hookCallMap, 0); }); - //eslint-disable-next-line @typescript-eslint/no-explicit-any - it("one hook called after an async function", (): any => { + it("one hook called after an async function", () => { hooking.hookManager.clearHooks(); hookTracker.clear(); const hookCallMap = registerAsyncFunctionHook( @@ -619,8 +618,7 @@ describe("function hooks instrumentation", () => { expectLogHooks(dbgMock, 1, "After", "foo"); }); - //eslint-disable-next-line @typescript-eslint/no-explicit-any - it("two hooks called after an async function", (): any => { + it("two hooks called after an async function", () => { hooking.hookManager.clearHooks(); hookTracker.clear(); const hookCallMap = registerAsyncFunctionHook( @@ -832,8 +830,7 @@ describe("function hooks instrumentation", () => { expectTrackedHooksUnknown(beforeHookCallMap, 0); expectTrackedHooksUnknown(afterHookCallMap, 0); }); - //eslint-disable-next-line @typescript-eslint/no-explicit-any - it("one Before and ond After hook for an async function", (): any => { + it("one Before and ond After hook for an async function", () => { hooking.hookManager.clearHooks(); hookTracker.clear(); const beforeHookCallMap = registerSyncFunctionHook(