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

Support and migrate to eslint@9.0.0 #735

Merged
merged 10 commits into from
May 30, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
102 changes: 0 additions & 102 deletions .eslintrc.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ lint:
enabled:
# enabled linters inherited from github.com/trunk-io/configs plugin
- definition-checker
- eslint@9.2.0
disabled:
- pylint # pylint diagnostics are too strict
- semgrep
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ trunk check enable {linter}
[dotenv-linter]: https://github.com/dotenv-linter/dotenv-linter#readme
[dotnet-format]: https://github.com/dotnet/format#readme
[dustilock]: https://github.com/Checkmarx/dustilock
[eslint]: https://github.com/eslint/eslint#readme
[eslint]: https://eslint.org/docs/latest/
[flake8]: https://trunk.io/linters/python/flake8
[git-diff-check]: https://git-scm.com/docs/git-diff
[gitleaks]: https://trunk.io/linters/security/gitleaks
Expand Down
1 change: 0 additions & 1 deletion actions/commitlint/commitlint.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* trunk-ignore-all(eslint/import/no-extraneous-dependencies) */
import { actionRunTest } from "tests";
import { TrunkActionDriver } from "tests/driver";

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
150 changes: 150 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
const eslint = require("@eslint/js");
const typescriptEslint = require("typescript-eslint");
const importPlugin = require("eslint-plugin-import-x");
const nodeRecommended = require("eslint-plugin-n");
const prettier = require("eslint-config-prettier");
const jestPlugin = require("eslint-plugin-jest");
const simpleImportSort = require("eslint-plugin-simple-import-sort");
// const preferArrowFunctions = require("eslint-plugin-prefer-arrow-functions");

module.exports = [
eslint.configs.recommended,
prettier,
...typescriptEslint.config({
files: ["**/*.ts"],
extends: [
...typescriptEslint.configs.recommended,
...typescriptEslint.configs.strictTypeChecked,
...typescriptEslint.configs.stylisticTypeChecked,
],
plugins: {
// "prefer-arrow-functions": preferArrowFunctions,
"simple-import-sort": simpleImportSort,
"import-x": importPlugin,
n: nodeRecommended,
},
languageOptions: {
ecmaVersion: "latest",
parser: typescriptEslint.parser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
sourceType: "module",
project: "tsconfig.json",
},
},
rules: {
...importPlugin.configs.recommended.rules,
...importPlugin.configs.typescript.rules,
...nodeRecommended.configs.recommended.rules,
"no-return-await": "off",
"no-shadow": "off",
"no-unused-expressions": "off",
"no-unused-vars": "off",
"no-use-before-define": "off",
"no-useless-constructor": "off",
"@typescript-eslint/lines-between-class-members": [
"error",
"always",
{ exceptAfterSingleLine: true },
],
"@typescript-eslint/naming-convention": [
"error",
{ selector: "typeLike", format: ["PascalCase"] },
{ selector: "function", format: ["camelCase"] },
{
selector: "variable",
modifiers: ["global", "const"],
format: ["UPPER_CASE", "camelCase"],
},
],
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unused-expressions": ["error"],
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-use-before-define": ["error"],
"@typescript-eslint/no-useless-constructor": ["error"],
"@typescript-eslint/no-explicit-any": "off",
"class-methods-use-this": "off",
curly: "error",
"func-names": ["error", "as-needed"],
"func-style": ["error", "expression", { allowArrowFunctions: true }],
"import-x/extensions": "off",
"import-x/first": "error",
"import-x/no-extraneous-dependencies": [
"error",
{
devDependencies: ["**/*.test.ts", "**/tests/**"],
},
],
"import-x/no-unresolved": "off",
"import-x/prefer-default-export": "off",
"lines-between-class-members": "off",
"max-len": [
"error",
{
code: 120,
comments: 130,
tabWidth: 2,
ignoreComments: false,
ignoreTrailingComments: false,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
},
],
"no-continue": "off",
"no-param-reassign": ["error", { props: false }],
"no-restricted-syntax": "off",
"n/no-extraneous-import": ["error"],
"n/no-unpublished-import": "off",
"n/no-missing-import": "off",
"n/no-unsupported-features/es-syntax": ["error", { ignores: ["modules", "dynamicImport"] }],
// TODO(Tyler): Add prefer-arrow-functions once it becomes compatible.
// "prefer-arrow-functions/prefer-arrow-functions": [
// "error",
// {
// returnStyle: "implicit",
// },
// ],
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/restrict-template-expressions": "off",
},
settings: [
"error",
{
"import-x/resolver": {
typescript: {
alwaysTryTypes: true,
},
},
},
],
}),
{
files: ["**/*test.ts"],
plugins: {
jest: jestPlugin,
},
rules: {
...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: 1 addition & 1 deletion linters/cspell/cspell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const normalizeLandingState = (landingState: LandingState) => {
const suggestions = issue.message.match(suggestionsRegex);
const suggestionsContent = suggestions?.groups?.suggestions;
if (suggestionsContent) {
const sortedSuggestions = suggestionsContent?.split(", ").sort().join(", ");
const sortedSuggestions = suggestionsContent.split(", ").sort().join(", ");
issue.message = issue.message.replace(suggestionsContent, sortedSuggestions);
}
}
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
24 changes: 5 additions & 19 deletions linters/eslint/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
# eslint

## Migration Guide
## Configuration Notice

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
```
`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.