Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerJang27 committed May 8, 2024
1 parent 104c299 commit aed6721
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 49 deletions.
4 changes: 0 additions & 4 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] |
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions actions/npm-check/npm_check.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions actions/yarn-check/yarn_check.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 22 additions & 7 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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,
Expand All @@ -24,7 +25,7 @@ module.exports = [
},
languageOptions: {
ecmaVersion: "latest",
parser,
parser: typescriptEslint.parser,
parserOptions: {
ecmaFeatures: {
jsx: true,
Expand Down Expand Up @@ -122,7 +123,7 @@ module.exports = [
},
},
],
},
}),
{
files: ["**/*test.ts"],
plugins: {
Expand All @@ -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",
},
},
];
2 changes: 0 additions & 2 deletions linters/actionlint/actionlint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};

Expand Down
1 change: 0 additions & 1 deletion linters/clippy/clippy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 0 additions & 2 deletions linters/detekt/detekt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions linters/eslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 1 addition & 3 deletions linters/eslint/eslint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const preCheck = (driver: TrunkLintDriver) => {
driver.moveFile(path.join(TEST_DATA, file), file.replace("-old", ""));
});
}
}
};

const preCheckWithInstall = (driver: TrunkLintDriver) => {
preCheck(driver);
Expand All @@ -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";
Expand All @@ -56,7 +55,6 @@ const preCheckWithInstall = (driver: TrunkLintDriver) => {
`.trunk/${toolsPath}`,
process.platform == "win32" ? "npm.bat" : "npm",
),
// trunk-ignore-end(semgrep)
["ci"],
{
cwd: driver.getSandbox(),
Expand Down
2 changes: 0 additions & 2 deletions linters/nancy/nancy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions linters/oxipng/oxipng.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
1 change: 0 additions & 1 deletion linters/sourcery/sourcery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
};

Expand Down
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions tests/driver/lint_driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -148,7 +149,7 @@ lint:

let newTrunkContents = "<undefined contents>";
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}`;
Expand All @@ -165,7 +166,7 @@ lint:
);
const enabledVersionRegex = `(?<linter>${this.linter})@(?<version>.+)\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);
}
Expand Down Expand Up @@ -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 });
}
Expand Down Expand Up @@ -360,7 +361,7 @@ lint:
async runFmtUnit(targetRelativePath: string, linter: string): Promise<TestResult> {
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 });
}
Expand Down
4 changes: 2 additions & 2 deletions tests/driver/tool_driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -99,7 +99,7 @@ lint:
);
const enabledVersionRegex = `(?<tool>${this.tool})@(?<version>.+)\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);
}
Expand Down
1 change: 0 additions & 1 deletion tests/reporter/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// trunk-ignore-all(eslint)
const path = require("path");
const tsNode = require("ts-node");

Expand Down

0 comments on commit aed6721

Please sign in to comment.