Skip to content

Commit

Permalink
refactor: Enable stylistic ESLint rules
Browse files Browse the repository at this point in the history
* Migrate to the new "flat" eslint config [1]
    * The eslintrc format will be deprecated and removed in ESLint v10
    * ESLint plugins in your IDE might still require a "useFlatConfig"
      setting to be set until ESLint 9 is released [4]
* Migrate from @typescript-eslint/eslint-plugin to typescript-eslint [2]
* Enable TypeScript compiler to process test/ dir
    * Separate "tsconfig.build.json" is used for releases and still
      only includes sources
    * Before,  no TypeScript validation occurced in test files
* Enable and enforce "ESLint Stylistic" rules [3]
* Unfortunately I failed to get the eslint-plugin-ava working with
  TypeScript

[1]: https://eslint.org/docs/latest/use/configure/configuration-files-new
[2]: https://typescript-eslint.io/packages/typescript-eslint#migrating-from-legacy-config-setups
[3]: https://eslint.style/guide/getting-started
[4]: https://eslint.org/blog/2023/10/flat-config-rollout-plans/
  • Loading branch information
RandomByte committed Mar 12, 2024
1 parent dfbd590 commit 8e9ce60
Show file tree
Hide file tree
Showing 8 changed files with 5,625 additions and 6,475 deletions.
12 changes: 0 additions & 12 deletions .eslintignore

This file was deleted.

54 changes: 0 additions & 54 deletions .eslintrc.cjs

This file was deleted.

121 changes: 121 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import stylistic from "@stylistic/eslint-plugin";

export default tseslint.config(
{
// This block defines ignore patterns globally to all configurations below
// (therefore it can use slightly different patterns, see also the eslint "Flat Config" doc)
ignores: [
".husky/*",
".github/*",
".reuse/*",
"docs/*",
"rfcs/*",
"coverage/*",

// Exclude test files
"test/tmp/*",
"test/projects/*",
"test/fixtures/*",

// Exclude generated code
"lib/*",
],
},
// Base configs applying to JS and TS files
eslint.configs.recommended,
stylistic.configs.customize({
indent: "tab",
quotes: "double",
semi: true,
jsx: false,
arrowParens: true,
braceStyle: "1tbs",
blockSpacing: false,
}), {
// Lint all JS files using the eslint parser
files: ["**/*.js"],
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
},
}, {
// Lint all TS files using the typescript-eslint parser
// Also enable all recommended typescript-eslint rules
files: ["src/**/*.ts", "test/**/*.ts", "scripts/**/*.ts"],
extends: [
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
parser: tseslint.parser,
parserOptions: {
project: true,
},
},
rules: {
// TypeScript specific overwrites
// We must disable the base rule as it can report incorrect errors
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error", {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
},
}, {
// To be discussed: Type-aware checks might add quite some additional work when writing tests
// and could even require us to export types that we would otherwise not export
files: ["test/**/*.ts"],
rules: {
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-unary-minus": "off",
},
}, {
// Overwrite any rules from the configurations above for both, JS and TS files
rules: {
"linebreak-style": [
"error",
"unix",
],
"@stylistic/object-curly-spacing": [
"error",
"never",
],
"@stylistic/operator-linebreak": ["error", "after"],
"@stylistic/comma-dangle": ["error", {
functions: "never",
arrays: "always-multiline",
objects: "always-multiline",
imports: "always-multiline",
exports: "always-multiline",
enums: "always-multiline",
generics: "always-multiline",
tuples: "always-multiline",
}],
"max-len": [
"error",
{
code: 120,
ignoreUrls: true,
ignoreRegExpLiterals: true,
},
],
"no-implicit-coercion": [
2,
{allow: ["!!"]},
],
"no-console": "error",
},
}
);
Loading

0 comments on commit 8e9ce60

Please sign in to comment.