@xsynaptic/eslint-config 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ {
2
+ "cSpell.words": [
3
+ "xsynaptic"
4
+ ]
5
+ }
@@ -0,0 +1,3 @@
1
+ import { getConfig } from "./src/get-config";
2
+
3
+ export default getConfig();
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@xsynaptic/eslint-config",
3
+ "version": "0.0.1",
4
+ "description": "A common ESLint config for some personal projects",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "main": "./src/get-config.ts",
8
+ "scripts": {
9
+ "lint": "eslint",
10
+ "check-types": "tsc --noEmit --extendedDiagnostics"
11
+ },
12
+ "devDependencies": {
13
+ "@eslint/js": "^9.19.0",
14
+ "@types/eslint__js": "^8.42.3",
15
+ "eslint": "^9.19.0",
16
+ "eslint-plugin-astro": "^1.3.1",
17
+ "eslint-plugin-import": "^2.31.0",
18
+ "eslint-plugin-jsx-a11y": "^6.10.2",
19
+ "eslint-plugin-simple-import-sort": "^12.1.1",
20
+ "eslint-plugin-unicorn": "^56.0.1",
21
+ "globals": "^15.14.0",
22
+ "jiti": "^2.4.2",
23
+ "typescript": "^5.7.3",
24
+ "typescript-eslint": "^8.21.0"
25
+ },
26
+ "packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
27
+ }
package/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # ESLint Config
2
+
3
+ This is a shared ESLint config for use with several TypeScript projects, most of them related to Astro. It is not intended for public consumption.
@@ -0,0 +1,137 @@
1
+ import eslint from "@eslint/js";
2
+ import astroPlugin from "eslint-plugin-astro";
3
+ import simpleImportSortPlugin from "eslint-plugin-simple-import-sort";
4
+ import unicornPlugin from "eslint-plugin-unicorn";
5
+ import globals from "globals";
6
+ import tseslint, { ConfigArray } from "typescript-eslint";
7
+
8
+ export function getConfig(
9
+ customConfig?: ConfigArray,
10
+ options?: {
11
+ customGlobals?: Record<string, "readonly" | "writeable">;
12
+ withAstro?: boolean;
13
+ }
14
+ ) {
15
+ const customGlobals = options?.customGlobals ?? {};
16
+ const withAstro = options?.withAstro ?? false;
17
+
18
+ const baseConfig = [
19
+ eslint.configs.recommended,
20
+ ...tseslint.configs.strictTypeChecked,
21
+ ...tseslint.configs.stylisticTypeChecked,
22
+ {
23
+ languageOptions: {
24
+ parser: tseslint.parser,
25
+ parserOptions: {
26
+ // projectService: true, // Astro ecosystem tools can't use this yet; 2024Q4
27
+ project: ["./tsconfig.json"],
28
+ },
29
+ globals: {
30
+ ...globals.builtin,
31
+ ...globals.nodeBuiltin,
32
+ ...customGlobals,
33
+ },
34
+ },
35
+ plugins: {
36
+ "@typescript-eslint": tseslint.plugin,
37
+ },
38
+ rules: {
39
+ "@typescript-eslint/array-type": ["warn", { default: "generic" }],
40
+ "@typescript-eslint/no-unused-vars": [
41
+ "error",
42
+ {
43
+ argsIgnorePattern: "^_",
44
+ destructuredArrayIgnorePattern: "^_",
45
+ varsIgnorePattern: "^_",
46
+ caughtErrorsIgnorePattern: "^_",
47
+ ignoreRestSiblings: true,
48
+ },
49
+ ],
50
+ "@typescript-eslint/no-non-null-assertion": "off",
51
+ },
52
+ },
53
+
54
+ /**
55
+ * Simple import sort
56
+ */
57
+ {
58
+ plugins: {
59
+ "simple-import-sort": simpleImportSortPlugin,
60
+ },
61
+ rules: {
62
+ "simple-import-sort/imports": [
63
+ "warn",
64
+ {
65
+ groups: [
66
+ [String.raw`^@?\w`], // External packages
67
+ [String.raw`^.*\u0000$`], // Type imports
68
+ ["^(@/)(/.*|$)"], // Internal imports prefixed with `@/`
69
+ [String.raw`^\u0000`], // Side effect imports
70
+ [String.raw`^\.\.(?!/?$)`, String.raw`^\.\./?$`], // Parent imports; put `..` last
71
+ [
72
+ String.raw`^\./(?=.*/)(?!/?$)`,
73
+ String.raw`^\.(?!/?$)`,
74
+ String.raw`^\./?$`,
75
+ ], // Other relative imports; put same folder imports and `.` last
76
+ [String.raw`^.+\.s?css$`], // Style imports
77
+ ],
78
+ },
79
+ ],
80
+ "simple-import-sort/exports": "warn",
81
+ },
82
+ },
83
+
84
+ /**
85
+ * Unicorn
86
+ */
87
+ unicornPlugin.configs["flat/recommended"],
88
+ {
89
+ rules: {
90
+ "unicorn/filename-case": "warn",
91
+ "unicorn/no-array-callback-reference": "off", // I prefer this pattern for filtering/sorting content
92
+ "unicorn/prevent-abbreviations": "off", // I *like* abbreviations!
93
+ },
94
+ },
95
+ ] satisfies ConfigArray;
96
+
97
+ /**
98
+ * Astro support; with some help from...
99
+ * @reference - https://github.com/Princesseuh/erika.florist/blob/main/eslint.config.js
100
+ */
101
+ const astroConfig = [
102
+ ...astroPlugin.configs.recommended,
103
+ ...astroPlugin.configs["jsx-a11y-strict"],
104
+
105
+ // Remove some safety rules around `any` for various reasons
106
+ // Astro.props isn't typed correctly in some contexts, so a bunch of things ends up being `any`
107
+ {
108
+ files: ["**/*.astro"],
109
+ rules: {
110
+ "@typescript-eslint/no-unsafe-member-access": "off",
111
+ "@typescript-eslint/no-unsafe-call": "off",
112
+ "@typescript-eslint/no-unsafe-return": "off",
113
+ "@typescript-eslint/no-unsafe-assignment": "off",
114
+ "@typescript-eslint/no-unsafe-argument": "off",
115
+ },
116
+ },
117
+
118
+ // Disable typed rules for scripts inside Astro files
119
+ // https://github.com/ota-meshi/eslint-plugin-astro/issues/240
120
+ {
121
+ files: ["**/*.astro/*.ts"],
122
+ languageOptions: {
123
+ parserOptions: {
124
+ // eslint-disable-next-line unicorn/no-null
125
+ project: null,
126
+ },
127
+ },
128
+ ...tseslint.configs.disableTypeChecked,
129
+ },
130
+ ] satisfies ConfigArray;
131
+
132
+ return tseslint.config([
133
+ ...baseConfig,
134
+ ...(withAstro ? astroConfig : []),
135
+ ...(customConfig ?? []),
136
+ ]);
137
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "baseUrl": ".",
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true
10
+ },
11
+ "include": [
12
+ "**/*.ts"
13
+ ]
14
+ }