Skip to content

Commit

Permalink
build: switch from eslint.config.mjs to eslint.config.mts
Browse files Browse the repository at this point in the history
  • Loading branch information
Rel1cx committed May 21, 2024
1 parent 0384db0 commit 46e396e
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 103 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"files.exclude": {
"**/.turbo": true,
".npmignore": true,
".eslintcache": true
".eslintcache": true,
"eslint.config.js": true
},
"typescript.preferences.importModuleSpecifier": "non-relative",
"typescript.tsdk": "node_modules/typescript/lib"
Expand Down
11 changes: 4 additions & 7 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// @ts-check
const { bundleRequire } = require("bundle-require");

// TODO - https://github.com/eslint/eslint/pull/17909
// either it gets back-ported (https://github.com/eslint/eslint/issues/17966) or we wait till v9

/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigPromise} */
const config = (async () => (await import("./eslint.config.mjs")).default)();
module.exports = config;
module.exports = bundleRequire({
filepath: "./eslint.config.mts",
}).then(require => require.mod.default);
145 changes: 82 additions & 63 deletions eslint.config.mjs → eslint.config.mts
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
// @ts-check

import url from "node:url";

// @ts-expect-error - this is a valid import
import eslint from "@eslint/js";
import gitignore from "eslint-config-flat-gitignore";
// @ts-expect-error - this is a valid import
import eslintCommentsPlugin from "eslint-plugin-eslint-comments";
// @ts-expect-error - this is a valid import
import eslintPluginPlugin from "eslint-plugin-eslint-plugin";
import gitignore from "eslint-config-flat-gitignore";
import jsdocPlugin from "eslint-plugin-jsdoc";
// @ts-expect-error - this is a valid import
import perfectionist from "eslint-plugin-perfectionist";
// @ts-expect-error - this is a valid import
import perfectionistNatural from "eslint-plugin-perfectionist/configs/recommended-natural";
import simpleImportSortPlugin from "eslint-plugin-simple-import-sort";
// @ts-expect-error - this is a valid import
import unicornPlugin from "eslint-plugin-unicorn";
import tseslint from "typescript-eslint";
import vitest from "eslint-plugin-vitest";
import tseslint from "typescript-eslint";

type FlatConfig = Parameters<typeof tseslint.config>[number];
const dirname = url.fileURLToPath(new URL(".", import.meta.url));

export default tseslint.config(
const config = [
// register all of the plugins up-front
{
// note - intentionally uses computed syntax to make it easy to sort the keys
plugins: {
["@typescript-eslint"]: tseslint.plugin,
["eslint-plugin"]: eslintPluginPlugin,
["eslint-comments"]: eslintCommentsPlugin,
["eslint-plugin"]: eslintPluginPlugin,
["jsdoc"]: jsdocPlugin,
["simple-import-sort"]: simpleImportSortPlugin,
["perfectionist"]: perfectionist,
["simple-import-sort"]: simpleImportSortPlugin,
["unicorn"]: unicornPlugin,
},
},
// extends ...
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
// @ts-ignore
perfectionistNatural,
jsdocPlugin.configs["flat/recommended-typescript-error"],
// base config
Expand All @@ -51,30 +54,30 @@ export default tseslint.config(
},
},
rules: {
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/ban-ts-comment": [
"error",
{
minimumDescriptionLength: 5,
"ts-check": false,
"ts-expect-error": "allow-with-description",
"ts-ignore": true,
"ts-nocheck": true,
"ts-check": false,
minimumDescriptionLength: 5,
},
],
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-type-imports": ["error", {
prefer: "type-imports",
disallowTypeAnnotations: true,
prefer: "type-imports",
}],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
caughtErrors: "all",
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
},
],
"@typescript-eslint/prefer-nullish-coalescing": [
Expand All @@ -85,18 +88,43 @@ export default tseslint.config(
},
],
"array-callback-return": "off",
curly: "off",
eqeqeq: ["error", "always"],
"eslint-comments/disable-enable-pair": ["error", { allowWholeFile: true }],
"eslint-comments/no-aggregating-enable": "error",
"eslint-comments/no-duplicate-disable": "error",
"eslint-comments/no-unlimited-disable": "error",
"eslint-comments/no-unused-disable": "error",
"eslint-comments/no-unused-enable": "error",
"eslint-comments/no-use": [
"error",
{
allow: [
"eslint-disable",
"eslint-disable-line",
"eslint-disable-next-line",
"eslint-enable",
"global",
],
},
],
"eslint-plugin/require-meta-docs-url": "off",
"jsdoc/check-param-names": "off",
"jsdoc/check-tag-names": "off",
"jsdoc/informative-docs": "warn",
"jsdoc/require-jsdoc": "off",
"jsdoc/require-param": "off",
"jsdoc/require-param-description": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-yields": "off",
"jsdoc/tag-lines": "off",
"logical-assignment-operators": "error",
"max-depth": ["warn", 3],
"no-console": "error",
"no-else-return": "error",
"no-fallthrough": ["error", { commentPattern: ".*intentional fallthrough.*" }],
"no-mixed-operators": "error",
"no-process-exit": "error",
"no-undef": "off",
"one-var": ["error", "never"],
"prefer-object-has-own": "error",
curly: "off",
eqeqeq: ["error", "always"],
"no-restricted-syntax": [
"error",
{
Expand All @@ -116,19 +144,16 @@ export default tseslint.config(
selector: 'ImportDeclaration[source.value="."]',
},
],
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn",
"unicorn/template-indent": "warn",
"no-undef": "off",
"one-var": ["error", "never"],
"perfectionist/sort-exports": "off",
"perfectionist/sort-imports": "off",
"perfectionist/sort-named-exports": "off",
"perfectionist/sort-named-imports": "off",
"perfectionist/sort-object-types": [
"warn",
{
order: "asc",
type: "natural",
groups: ["id", "type", "meta", "unknown"],
"custom-groups": {
id: ["_", "id", "key"],
type: ["type", "kind"],
Expand All @@ -139,15 +164,14 @@ export default tseslint.config(
"description",
],
},
groups: ["id", "type", "meta", "unknown"],
order: "asc",
},
],
"perfectionist/sort-objects": [
"warn",
{
order: "asc",
type: "natural",
"partition-by-comment": "Part:**",
groups: ["id", "type", "meta", "unknown"],
"custom-groups": {
id: ["_", "id", "key"],
type: ["type", "kind"],
Expand All @@ -158,50 +182,30 @@ export default tseslint.config(
"description",
],
},
groups: ["id", "type", "meta", "unknown"],
order: "asc",
"partition-by-comment": "Part:**",
},
],
"perfectionist/sort-union-types": [
"warn",
{
order: "asc",
type: "natural",
order: "asc",
},
],
"eslint-plugin/require-meta-docs-url": "off",
"eslint-comments/disable-enable-pair": ["error", { allowWholeFile: true }],
"eslint-comments/no-aggregating-enable": "error",
"eslint-comments/no-duplicate-disable": "error",
"eslint-comments/no-unlimited-disable": "error",
"eslint-comments/no-unused-disable": "error",
"eslint-comments/no-unused-enable": "error",
"eslint-comments/no-use": [
"error",
{
allow: [
"eslint-disable",
"eslint-disable-line",
"eslint-disable-next-line",
"eslint-enable",
"global",
],
},
],
"jsdoc/check-tag-names": "off",
"jsdoc/check-param-names": "off",
"jsdoc/require-jsdoc": "off",
"jsdoc/require-param": "off",
"jsdoc/require-param-description": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-yields": "off",
"jsdoc/tag-lines": "off",
"jsdoc/informative-docs": "warn",
"prefer-object-has-own": "error",
"simple-import-sort/exports": "warn",
"simple-import-sort/imports": "warn",
"unicorn/template-indent": "warn",
},
},
{
files: ["**/*.js"],
extends: [tseslint.configs.disableTypeChecked],
files: ["**/*.js"],
rules: {
// turn off rules that don't apply to JS code
"@typescript-eslint/no-var-requires": "off",
},
},
{
Expand All @@ -211,11 +215,15 @@ export default tseslint.config(
"**/spec.{ts,tsx,cts,mts}",
"**/test.{ts,tsx,cts,mts}",
],
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
plugins: {
vitest,
},
rules: {
// @ts-ignore
...vitest.configs.recommended.rules,
"@typescript-eslint/no-empty-function": ["error", { allow: ["arrowFunctions"] }],
"@typescript-eslint/no-non-null-assertion": "off",
Expand All @@ -224,9 +232,19 @@ export default tseslint.config(
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
},
},
{
extends: [tseslint.configs.disableTypeChecked],
files: [
"*.config.{ts,tsx,cts,mts}",
],
languageOptions: {
globals: {
...vitest.environments.env.globals,
parserOptions: {
project: [
"tsconfig.json",
],
tsconfigRootDir: dirname,
warnOnUnsupportedTypeScriptVersion: false,
},
},
},
Expand All @@ -236,7 +254,8 @@ export default tseslint.config(
"docs",
"examples",
"website",
"eslint.config.mjs",
],
},
);
] satisfies FlatConfig[];

export default tseslint.config(...config);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@vitest/ui": "1.6.0",
"bun": "1.1.8",
"bun-types": "1.1.8",
"bundle-require": "^4.1.0",
"code-block-writer": "13.0.1",
"cspell": "8.8.1",
"dedent": "1.5.3",
Expand Down Expand Up @@ -101,7 +102,7 @@
"typescript": "5.4.5",
"vitest": "1.6.0"
},
"packageManager": "pnpm@9.1.0",
"packageManager": "pnpm@9.1.2",
"engines": {
"bun": ">=1.0.15",
"node": ">=18.18.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@typescript-eslint/utils": "^7.10.0",
"deepmerge-ts": "7.0.0"
"deepmerge-ts": "7.0.1"
},
"devDependencies": {
"type-fest": "4.18.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReadonlyDeep } from "type-fest";
import { array, object, optional, type InferOutput, string } from "valibot";
import { array, type InferOutput, object, optional, string } from "valibot";

/**
* @internal
Expand Down
Loading

0 comments on commit 46e396e

Please sign in to comment.