Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Handle eslint pre-9.0.0 #752

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions linters/eslint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# eslint

## Migration Guide

Trunk does not yet support `eslint@9.x`, which includes substantial config format changes (see their
[migration guide](https://eslint.org/docs/latest/use/migrate-to-9.0.0#flat-config)). If you'd like
to opt-in to `eslint@9.x` with Trunk before we release official support, you can add the following
override to your `.trunk/trunk.yaml`:

```yaml
version: 0.1
---
lint:
enabled:
- eslint@9.0.0
definitions:
- name: eslint
direct_configs:
- eslint.config.js
- eslint.config.mjs
- eslint.config.cjs
```
13 changes: 13 additions & 0 deletions linters/eslint/eslint.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spawnSync } from "child_process";
import fs from "fs";
import path from "path";
import semver from "semver";
import { customLinterCheckTest } from "tests";
import { TrunkLintDriver } from "tests/driver";
import { osTimeoutMultiplier, TEST_DATA } from "tests/utils";
Expand Down Expand Up @@ -54,6 +55,7 @@ const preCheck = (driver: TrunkLintDriver) => {
cwd: driver.getSandbox(),
timeout: INSTALL_TIMEOUT,
windowsHide: true,
shell: true,
},
);
driver.debug(install);
Expand All @@ -68,12 +70,22 @@ const preCheck = (driver: TrunkLintDriver) => {
}
};

const manualVersionReplacer = (version: string) => {
// NOTE(Tyler): Continue to test eslint pre-9.0.0 and gate until we have a long-term fix.
const parsedVersion = semver.parse(version);
if (parsedVersion && parsedVersion.major >= 9) {
return "8.57.0";
}
return version;
};

// This set of testing is incomplete with regard to failure modes and unicode autofixes with eslint, but it serves as a sampling
// Use upstream=false in order to supply autofixes for committed files.
customLinterCheckTest({
linterName: "eslint",
args: `${TEST_DATA} -y --upstream=false`,
preCheck,
manualVersionReplacer,
pathsToSnapshot: [
path.join(TEST_DATA, "non_ascii.ts"),
path.join(TEST_DATA, "eof_autofix.ts"),
Expand All @@ -86,4 +98,5 @@ customLinterCheckTest({
testName: "bad_install",
args: `${TEST_DATA} -y`,
preCheck: moveConfig,
manualVersionReplacer,
});
Loading