From aed6721943a1447683eecf876ced03523ac2a0b7 Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Wed, 8 May 2024 11:37:51 -0700 Subject: [PATCH] more cleanup --- .trunk/trunk.yaml | 4 ---- README.md | 6 +++--- actions/npm-check/npm_check.js | 3 +-- actions/yarn-check/yarn_check.js | 3 +-- eslint.config.cjs | 29 ++++++++++++++++++++------- linters/actionlint/actionlint.test.ts | 2 -- linters/clippy/clippy.test.ts | 1 - linters/detekt/detekt.test.ts | 2 -- linters/eslint/README.md | 6 ++++-- linters/eslint/eslint.test.ts | 4 +--- linters/nancy/nancy.test.ts | 2 -- linters/oxipng/oxipng.test.ts | 2 -- linters/sourcery/sourcery.test.ts | 1 - package-lock.json | 9 --------- tests/driver/lint_driver.ts | 9 +++++---- tests/driver/tool_driver.ts | 4 ++-- tests/reporter/index.js | 1 - 17 files changed, 39 insertions(+), 49 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index ca2488ab0..f1cc368ce 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -52,10 +52,6 @@ lint: paths: - "**/test_data" # required for golangci-lint, which runs on directories - "**/test_data/**" - # - linters: [eslint] - # paths: - # - "**/*.js" - # - "**/*.cjs" actions: # Uncomment to enable more verbose action logs diff --git a/README.md b/README.md index 84646abd6..a7a5ce646 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ trunk check enable {linter} | HAML | [haml-lint] | | HTML Templates | [djlint] | | Java | [google-java-format], [pmd], [semgrep] | -| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] | -| JSON | [biome], [deno], [eslint], [prettier], [semgrep] | +| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] | +| JSON | [biome], [deno], [eslint], [prettier], [semgrep] | | Kotlin | [detekt], [ktlint] | | Kubernetes | [kube-linter] | | Lua | [stylua] | @@ -89,7 +89,7 @@ trunk check enable {linter} | Terragrunt | [terragrunt] | | Textproto | [txtpbfmt] | | TOML | [taplo] | -| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] | +| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] | | YAML | [prettier], [semgrep], [yamllint] | [actionlint]: https://trunk.io/linters/infra/actionlint diff --git a/actions/npm-check/npm_check.js b/actions/npm-check/npm_check.js index 53643b6a3..8fbe1c2da 100755 --- a/actions/npm-check/npm_check.js +++ b/actions/npm-check/npm_check.js @@ -1,6 +1,5 @@ #!/usr/bin/env node -// trunk-ignore-all(eslint) const npmCheck = require("npm-check"); const YAML = require("yaml"); const path = require("path"); @@ -30,7 +29,7 @@ npmCheck({}) message: `${uninstalled_count} npm ${pluralize( uninstalled_count, "package", - "packages" + "packages", )} ${pluralize(uninstalled_count, "needs", "need")} to be installed\n`, commands: [{ run: "npm install", title: "npm install" }], icon: iconPath, diff --git a/actions/yarn-check/yarn_check.js b/actions/yarn-check/yarn_check.js index 6fbd71028..7ccfe3488 100755 --- a/actions/yarn-check/yarn_check.js +++ b/actions/yarn-check/yarn_check.js @@ -1,6 +1,5 @@ #!/usr/bin/env node -// trunk-ignore-all(eslint) const yarnCheck = require("yarn-check"); const YAML = require("yaml"); const path = require("path"); @@ -28,7 +27,7 @@ yarnCheck({}) message: `${uninstalled_count} yarn ${pluralize( uninstalled_count, "package", - "packages" + "packages", )} ${pluralize(uninstalled_count, "needs", "need")} to be installed\n`, commands: [{ run: "yarn install", title: "yarn install" }], icon: iconPath, diff --git a/eslint.config.cjs b/eslint.config.cjs index bf79a0f28..0694f4094 100644 --- a/eslint.config.cjs +++ b/eslint.config.cjs @@ -1,7 +1,6 @@ const eslint = require("@eslint/js"); const typescriptEslint = require("typescript-eslint"); const importPlugin = require("eslint-plugin-import-x"); -const parser = require("@typescript-eslint/parser"); const nodeRecommended = require("eslint-plugin-n"); const prettier = require("eslint-config-prettier"); const jestPlugin = require("eslint-plugin-jest"); @@ -10,12 +9,14 @@ const simpleImportSort = require("eslint-plugin-simple-import-sort"); module.exports = [ eslint.configs.recommended, - ...typescriptEslint.configs.recommended, - ...typescriptEslint.configs.strictTypeChecked, - ...typescriptEslint.configs.stylisticTypeChecked, prettier, - { + ...typescriptEslint.config({ files: ["**/*.ts"], + extends: [ + ...typescriptEslint.configs.recommended, + ...typescriptEslint.configs.strictTypeChecked, + ...typescriptEslint.configs.stylisticTypeChecked, + ], plugins: { // "prefer-arrow-functions": preferArrowFunctions, "simple-import-sort": simpleImportSort, @@ -24,7 +25,7 @@ module.exports = [ }, languageOptions: { ecmaVersion: "latest", - parser, + parser: typescriptEslint.parser, parserOptions: { ecmaFeatures: { jsx: true, @@ -122,7 +123,7 @@ module.exports = [ }, }, ], - }, + }), { files: ["**/*test.ts"], plugins: { @@ -132,4 +133,18 @@ module.exports = [ ...jestPlugin.configs.recommended.rules, }, }, + { + // Used for scripts and Trunk Actions. + files: ["**/*.{js,cjs}"], + languageOptions: { + globals: { + node: true, + require: true, + console: true, + module: true, + __dirname: true, + }, + ecmaVersion: "latest", + }, + }, ]; diff --git a/linters/actionlint/actionlint.test.ts b/linters/actionlint/actionlint.test.ts index b7fe2eb01..fcb655f3c 100644 --- a/linters/actionlint/actionlint.test.ts +++ b/linters/actionlint/actionlint.test.ts @@ -6,11 +6,9 @@ import { TEST_DATA } from "tests/utils"; // actionlint is specially triggered to run on github workflow files const preCheck = async (driver: TrunkLintDriver) => { - // trunk-ignore-begin(semgrep): driver.getSandbox() is generated during testing and is safe fs.readdirSync(path.resolve(driver.getSandbox(), TEST_DATA)).forEach((file) => { driver.moveFile(path.join(TEST_DATA, file), path.join(".github/workflows", file)); }); - // trunk-ignore-end(semgrep) await driver.gitDriver?.add(".").commit("moved"); }; diff --git a/linters/clippy/clippy.test.ts b/linters/clippy/clippy.test.ts index a2eedad9b..d3fa7b924 100644 --- a/linters/clippy/clippy.test.ts +++ b/linters/clippy/clippy.test.ts @@ -3,7 +3,6 @@ import { customLinterCheckTest } from "tests"; import { TrunkLintDriver } from "tests/driver"; import { TEST_DATA } from "tests/utils"; -// trunk-ignore-all(semgrep) // Ensure that the Cargo files are at the same level as the src/ directory. const moveCargoFiles = (dest: string) => (driver: TrunkLintDriver) => { ["Cargo.lock", "Cargo.toml"].forEach((file) => { diff --git a/linters/detekt/detekt.test.ts b/linters/detekt/detekt.test.ts index 7f492b426..d064c44e1 100644 --- a/linters/detekt/detekt.test.ts +++ b/linters/detekt/detekt.test.ts @@ -32,7 +32,6 @@ linterCheckTest({ const gradlePreCheck: TestCallback = (driver) => { // Based on plugin.yaml, trunk invokes ${workspace}/gradlew and expects gradlew, etc. to exist at the workspace root. // However, we expect .trunk/trunk.yaml to exist at the workspace root as well, so we move each file up to the workspace. - // trunk-ignore-begin(semgrep): paths used here are safe fs.readdirSync(path.resolve(driver.getSandbox(), TEST_DATA, "detekt_gradle")).forEach((file) => { driver.moveFile(path.join(TEST_DATA, "detekt_gradle", file), file); }); @@ -55,7 +54,6 @@ const gradlePreCheck: TestCallback = (driver) => { list: ["\${env.PATH}"] `); driver.writeFile(trunkYamlPath, finalContents); - // trunk-ignore-end(semgrep) }; // TODO(Tyler): detekt-gradle has issues resolving stdin correctly on Windows. diff --git a/linters/eslint/README.md b/linters/eslint/README.md index fe4143f74..cb23b3e87 100644 --- a/linters/eslint/README.md +++ b/linters/eslint/README.md @@ -2,5 +2,7 @@ ## Configuration Notice -`eslint@9.x` requires a flat config format (see their [migration guide](https://eslint.org/docs/latest/use/migrate-to-9.0.0#flat-config)) -in order to run. Trunk will automatically detect which config file you have and by default will only enable a compatible version. +`eslint@9.x` requires a flat config format (see their +[migration guide](https://eslint.org/docs/latest/use/migrate-to-9.0.0#flat-config)) in order to run. +Trunk will automatically detect which config file you have and by default will only enable a +compatible version. diff --git a/linters/eslint/eslint.test.ts b/linters/eslint/eslint.test.ts index c16e5bd0e..fc5250081 100644 --- a/linters/eslint/eslint.test.ts +++ b/linters/eslint/eslint.test.ts @@ -19,7 +19,7 @@ const preCheck = (driver: TrunkLintDriver) => { driver.moveFile(path.join(TEST_DATA, file), file.replace("-old", "")); }); } -} +}; const preCheckWithInstall = (driver: TrunkLintDriver) => { preCheck(driver); @@ -39,7 +39,6 @@ const preCheckWithInstall = (driver: TrunkLintDriver) => { driver.debug("About to install shims"); driver.runTrunkSync(["tools", "install"]); driver.debug("Done installing shims"); - // trunk-ignore-begin(semgrep): Safe paths const toolsPath = fs.existsSync(path.resolve(driver.getSandbox(), ".trunk/dev-tools")) ? "dev-tools" : "tools"; @@ -56,7 +55,6 @@ const preCheckWithInstall = (driver: TrunkLintDriver) => { `.trunk/${toolsPath}`, process.platform == "win32" ? "npm.bat" : "npm", ), - // trunk-ignore-end(semgrep) ["ci"], { cwd: driver.getSandbox(), diff --git a/linters/nancy/nancy.test.ts b/linters/nancy/nancy.test.ts index 9289c51a8..ae6867010 100644 --- a/linters/nancy/nancy.test.ts +++ b/linters/nancy/nancy.test.ts @@ -7,11 +7,9 @@ import { TEST_DATA } from "tests/utils"; import { createFuzzyMatcher } from "tests/utils/landing_state"; const preCheck = (driver: TrunkLintDriver) => { - // trunk-ignore-begin(semgrep): driver.getSandbox() is generated during testing and is safe fs.readdirSync(path.resolve(driver.getSandbox(), TEST_DATA)).forEach((file) => { driver.moveFile(path.join(TEST_DATA, file), file); }); - // trunk-ignore-end(semgrep) }; // trunk-ignore(eslint/@typescript-eslint/no-unsafe-assignment) diff --git a/linters/oxipng/oxipng.test.ts b/linters/oxipng/oxipng.test.ts index e3da0d5d4..32b28d3cb 100644 --- a/linters/oxipng/oxipng.test.ts +++ b/linters/oxipng/oxipng.test.ts @@ -19,10 +19,8 @@ const preCheck = (driver: TrunkLintDriver) => { const postCheck = (driver: TrunkLintDriver) => { const originalSize = fs.statSync( - // trunk-ignore(semgrep): paths used here are safe path.resolve(driver.getSandbox(), TEST_DATA, "good.png.bak"), ).size; - // trunk-ignore(semgrep): paths used here are safe const compressedSize = fs.statSync(path.resolve(driver.getSandbox(), TEST_DATA, "good.png")).size; expect(compressedSize).toBeLessThan(originalSize); }; diff --git a/linters/sourcery/sourcery.test.ts b/linters/sourcery/sourcery.test.ts index 3001a750b..19ac943b7 100644 --- a/linters/sourcery/sourcery.test.ts +++ b/linters/sourcery/sourcery.test.ts @@ -23,7 +23,6 @@ lint:`, // NOTE(Tyler): Sourcery relies on checking if the repo is open source for its pricing model. // The sandbox tests run on a subset of the main repo, and it needs access to the repo root .git folder in order to run. driver.deleteFile(".git"); - // trunk-ignore(semgrep): This path is safe. fs.symlinkSync(path.join(REPO_ROOT, ".git"), path.join(driver.getSandbox(), ".git")); }; diff --git a/package-lock.json b/package-lock.json index d6db49aa2..12d7158f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,6 @@ "eslint-plugin-import-x": "^0.5.0", "eslint-plugin-jest": "^28.3.0", "eslint-plugin-n": "^17.1.0", - "eslint-plugin-prefer-arrow-functions": "^3.3.2", "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-simple-import-sort": "^12.1.0", "fast-sort": "^3.2.0", @@ -3260,14 +3259,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/eslint-plugin-prefer-arrow-functions": { - "version": "3.3.2", - "dev": true, - "license": "MIT", - "peerDependencies": { - "eslint": ">=5.0.0" - } - }, "node_modules/eslint-plugin-prettier": { "version": "5.1.3", "dev": true, diff --git a/tests/driver/lint_driver.ts b/tests/driver/lint_driver.ts index b74a93b3a..6fd118492 100644 --- a/tests/driver/lint_driver.ts +++ b/tests/driver/lint_driver.ts @@ -126,6 +126,7 @@ lint: (this.getFullTrunkConfig().lint.definitions.find( ({ name }: { name: string }) => name === this.linter, )?.known_good_version as string) ?? ""; + // trunk-ignore(eslint/@typescript-eslint/no-useless-template-literals): Convert kgv to string if (this.linter === "include-what-you-use" && `${kgv}`.length === 3) { // TODO(Tyler): `trunk config print` does not correctly wrap quotes around kgv, so we must patch iwyu here return `${kgv}0`; @@ -148,7 +149,7 @@ lint: let newTrunkContents = ""; try { - // Cast version to string in case of decimal representation (e.g. 0.40) + // trunk-ignore(eslint/@typescript-eslint/no-useless-template-literals): Cast to string to handle decimal case const version = `${this.extractLinterVersion()}`; const versionString = version.length > 0 ? `@${version}` : ""; const linterVersionString = `${this.linter}${versionString}`; @@ -165,7 +166,7 @@ lint: ); const enabledVersionRegex = `(?${this.linter})@(?.+)\n`; const foundIn = newTrunkContents.match(enabledVersionRegex); - if (foundIn && foundIn.groups?.version && foundIn.groups?.version.length > 0) { + if (foundIn?.groups?.version && foundIn.groups.version.length > 0) { this.enabledVersion = foundIn.groups.version; this.debug("Enabled %s", this.enabledVersion); } @@ -284,7 +285,7 @@ lint: // this has been changed from ".json" to ".out.json" for linters that run on terraform files // terraform extensions are .tf and .tf.json - this change prevents accidentally linting the trunk output const resultJsonPath = `${targetAbsPath}.out.json`; - const args = `${targetRelativePath}`; + const args = targetRelativePath; this.debug("Running `trunk check` on %s", targetRelativePath); return await this.runCheck({ args, linter, targetAbsPath, resultJsonPath }); } @@ -360,7 +361,7 @@ lint: async runFmtUnit(targetRelativePath: string, linter: string): Promise { const targetAbsPath = path.resolve(this.sandboxPath ?? "", targetRelativePath); const resultJsonPath = `${targetAbsPath}.json`; - const args = `${targetRelativePath}`; + const args = targetRelativePath; this.debug("Running `trunk fmt` on %s", targetRelativePath); return await this.runFmt({ args, linter, targetAbsPath, resultJsonPath }); } diff --git a/tests/driver/tool_driver.ts b/tests/driver/tool_driver.ts index eb26deec7..091e4d4fb 100644 --- a/tests/driver/tool_driver.ts +++ b/tests/driver/tool_driver.ts @@ -84,7 +84,7 @@ lint: return; } try { - // Cast version to string in case of decimal representation (e.g. 0.40) + // trunk-ignore(eslint/@typescript-eslint/no-useless-template-literals): Cast to string to handle decimal case const version = `${this.extractToolVersion()}`; const versionString = version.length > 0 ? `@${version}` : ""; const toolVersionString = `${this.tool}${versionString}`; @@ -99,7 +99,7 @@ lint: ); const enabledVersionRegex = `(?${this.tool})@(?.+)\n`; const foundIn = newTrunkContents.match(enabledVersionRegex); - if (foundIn && foundIn.groups?.version && foundIn.groups?.version.length > 0) { + if (foundIn?.groups?.version && foundIn.groups.version.length > 0) { this.enabledVersion = foundIn.groups.version; this.debug("Enabled %s", this.enabledVersion); } diff --git a/tests/reporter/index.js b/tests/reporter/index.js index 71479f9d7..b13da7823 100644 --- a/tests/reporter/index.js +++ b/tests/reporter/index.js @@ -1,4 +1,3 @@ -// trunk-ignore-all(eslint) const path = require("path"); const tsNode = require("ts-node");