Skip to content

Commit ce78d33

Browse files
authored
build: upgrade from ES2018 to ESNext (#52)
* chore: remove unused interval-checking logic * build: upgrade from ES2018 to ESNext * style: enforce eslint on config files * refactor: remove unused luxon helpers * refactor: rename to assertValid * style: fix broken eslint rules and enforce them across the codebase * style: narrow external rule to be exactly what's needed * style: rename type parameter for better clarity * feat: also validate date format strings
1 parent f5c5d32 commit ce78d33

20 files changed

+815
-703
lines changed

boundaries.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export const ELEMENT_SETTINGS = [
88
defineFolderScope("model"),
99
defineFolderScope("render"),
1010

11+
{
12+
type: "config",
13+
pattern: "*.config.js",
14+
capture: ["name"],
15+
mode: "full",
16+
},
1117
{
1218
type: "shared",
1319
pattern: "src/util",
@@ -59,6 +65,10 @@ export const ELEMENT_TYPE_RULES = [
5965
from: "const",
6066
allow: ["./*"],
6167
},
68+
{
69+
from: [["config", { name: "eslint" }]],
70+
allow: [["config", { name: "boundaries" }]],
71+
},
6272
];
6373

6474
/** @see {@link https://github.com/javierbrea/eslint-plugin-boundaries#rules-configuration} */
@@ -71,6 +81,26 @@ export const EXTERNAL_RULES = [
7181
from: [["render", { elementName: "preact" }]],
7282
allow: ["preact", "preact/hooks"],
7383
},
84+
{
85+
from: [["config", { name: "eslint" }]],
86+
allow: [
87+
"@eslint/js",
88+
"@vitest/eslint-plugin",
89+
"eslint",
90+
"eslint/config",
91+
"eslint-plugin-boundaries",
92+
"eslint-plugin-import",
93+
"eslint-plugin-jsdoc",
94+
"eslint-plugin-react-hooks",
95+
"eslint-plugin-tsdoc",
96+
"globals",
97+
"typescript-eslint",
98+
],
99+
},
100+
{
101+
from: [["config", { name: "vite" }]],
102+
allow: ["@preact/preset-vite", "vite", "vite-plugin-static-copy"],
103+
},
74104
{
75105
from: "lib",
76106
allow: ["${from.lib}"],

eslint.config.js

+38-60
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,41 @@
1-
import eslintConfigPreact from "eslint-config-preact";
2-
import eslintConfigPrettier from "eslint-config-prettier";
3-
import eslintPluginBoundaries from "eslint-plugin-boundaries";
4-
import eslintPluginImport from "eslint-plugin-import";
1+
import js from "@eslint/js";
2+
import vitest from "@vitest/eslint-plugin";
3+
import { defineConfig } from "eslint/config";
4+
import boundaries from "eslint-plugin-boundaries";
5+
import importPlugin from "eslint-plugin-import";
6+
import jsdoc from "eslint-plugin-jsdoc";
57
import eslintPluginReactHooks from "eslint-plugin-react-hooks";
8+
import tsdoc from "eslint-plugin-tsdoc";
69
import globals from "globals";
7-
import typescriptEslintParser from "@typescript-eslint/parser";
8-
import typescriptEslintPlugin from "@typescript-eslint/eslint-plugin";
9-
import eslintPluginJsdoc from "eslint-plugin-jsdoc";
10-
import eslintPluginTsdoc from "eslint-plugin-tsdoc";
10+
import typescriptEslint from "typescript-eslint";
11+
1112
import { ELEMENT_SETTINGS, ELEMENT_TYPE_RULES, EXTERNAL_RULES } from "./boundaries.config.js";
12-
import eslintJs from "@eslint/js";
13-
import vitestEslintPlugin from "@vitest/eslint-plugin";
1413

15-
/** @type { import("eslint").Linter.Config[] } */
16-
export default [
14+
export default defineConfig([
1715
{ ignores: [".husky/", "coverage/", "docs/", "dist/", "node_modules/"] },
1816

19-
eslintJs.configs.recommended,
20-
eslintPluginImport.flatConfigs.recommended,
21-
...eslintConfigPreact.flat,
17+
{ plugins: { js }, extends: ["js/recommended"] },
18+
{ plugins: { jsdoc }, files: ["**/*.{js,jsx}"], extends: ["jsdoc/flat/recommended-error"] },
19+
{ plugins: { jsdoc }, files: ["**/*.{ts,tsx}"], extends: ["jsdoc/flat/recommended-typescript-error"] },
20+
{ plugins: { tsdoc }, files: ["**/*.{ts,tsx}"], rules: { "tsdoc/syntax": "error" } },
2221

2322
{
24-
files: ["*.config.js"],
25-
plugins: { jsdoc: eslintPluginJsdoc },
26-
languageOptions: { globals: { ...globals.node } },
27-
...eslintPluginJsdoc.configs["flat/recommended-error"],
28-
rules: {
29-
...eslintPluginJsdoc.configs["flat/recommended-error"].rules,
30-
"import/no-named-as-default": "off",
31-
"import/no-unresolved": "off",
32-
},
33-
settings: {
34-
"import/core-modules": ["eslint-config-preact", "eslint-plugin-boundaries", "eslint-plugin-import"],
23+
extends: [typescriptEslint.configs.recommendedTypeChecked],
24+
files: ["**/*.{ts,tsx}"],
25+
languageOptions: {
26+
parser: typescriptEslint.parser,
27+
parserOptions: { ecmaVersion: "latest", projectService: true, tsconfigRootDir: import.meta.dirname },
3528
},
3629
},
3730

3831
{
39-
files: ["src/**/*.{ts,tsx}"],
40-
...eslintPluginJsdoc.configs["flat/recommended-typescript-error"],
41-
plugins: {
42-
"@typescript-eslint": typescriptEslintPlugin,
43-
"jsdoc": eslintPluginJsdoc,
44-
"react-hooks": eslintPluginReactHooks,
45-
"tsdoc": eslintPluginTsdoc,
46-
},
47-
rules: {
48-
...typescriptEslintPlugin.configs.recommended.rules,
49-
...typescriptEslintPlugin.configs.strict.rules,
50-
...eslintPluginReactHooks.configs.recommended.rules,
51-
...eslintPluginJsdoc.configs["flat/recommended-typescript-error"].rules,
52-
53-
// https://tsdoc.org/pages/packages/eslint-plugin-tsdoc/
54-
"tsdoc/syntax": "error",
32+
extends: [eslintPluginReactHooks.configs["recommended-latest"]],
33+
files: ["**/*.{ts,tsx}"],
34+
},
5535

36+
{
37+
extends: [importPlugin.flatConfigs.recommended],
38+
rules: {
5639
"import/order": [
5740
"error",
5841
{
@@ -68,38 +51,33 @@ export default [
6851
},
6952
settings: {
7053
"import/core-modules": ["obsidian"],
71-
},
72-
languageOptions: {
73-
globals: { ...globals.browser },
74-
parser: typescriptEslintParser,
75-
parserOptions: { ecmaFeatures: { modules: true }, ecmaVersion: "latest" },
54+
"import/resolver": { typescript: { alwaysTryTypes: true } },
7655
},
7756
},
7857

7958
{
80-
files: ["src/**/*.test.{ts,tsx}"],
81-
...vitestEslintPlugin.configs.recommended,
82-
rules: {
83-
"vitest/expect-expect": ["off", { assertFunctionNames: ["expect", "expectTypeOf"] }],
84-
},
59+
files: ["*.config.js"],
60+
languageOptions: { globals: { ...globals.node }, ecmaVersion: "latest", sourceType: "module" },
8561
},
8662

87-
// Turns off all rules that are unnecessary or might conflict with Prettier.
88-
eslintConfigPrettier,
63+
{
64+
plugins: { vitest },
65+
extends: ["vitest/recommended"],
66+
files: ["**/*.test.{ts,tsx}"],
67+
rules: { "vitest/expect-expect": ["error", { assertFunctionNames: ["expect", "expectTypeOf"] }] },
68+
},
8969

9070
{
91-
files: ["src/**/*"],
92-
plugins: { boundaries: eslintPluginBoundaries },
71+
plugins: { boundaries },
72+
extends: ["boundaries/strict"],
9373
settings: {
94-
"boundaries/include": ["src/**/*"],
74+
"boundaries/include": ["**/*"],
9575
"boundaries/ignore": ["**/__tests__/**/*", "**/__mocks__/**/*"],
9676
"boundaries/elements": ELEMENT_SETTINGS,
97-
"import/resolver": { typescript: { alwaysTryTypes: true } },
9877
},
9978
rules: {
100-
...eslintPluginBoundaries.configs.strict.rules,
10179
"boundaries/element-types": ["error", { default: "disallow", rules: ELEMENT_TYPE_RULES }],
10280
"boundaries/external": ["error", { default: "disallow", rules: EXTERNAL_RULES }],
10381
},
10482
},
105-
];
83+
]);

0 commit comments

Comments
 (0)