@sonsu-lee/eslint-config 0.1.0 → 0.3.0

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @sonsu-lee/eslint-config
2
2
 
3
- Run the `sonsu-lee-eslint` rules that need TypeScript types and cannot run in Oxlint. Keep `@sonsu-lee/oxlint-config` for the rest of your lint rules.
3
+ The preset enables three type-aware rules from [`@sonsu-lee/eslint-plugin`](../eslint-plugin/README.md) as errors: `sonsu-lee-eslint/no-ignored-rejection`, `sonsu-lee-eslint/no-query-rest-destructuring`, and `sonsu-lee-eslint/no-void-query-fn`. These rules cannot run in Oxlint. Keep `@sonsu-lee/oxlint-config` for the rest of your lint rules.
4
4
 
5
5
  ## Install
6
6
 
@@ -22,9 +22,9 @@ export default preset();
22
22
 
23
23
  From the directory containing `tsconfig.json`, run `oxlint && eslint src`. Replace `src` with the source paths included in your TypeScript project. Running `eslint` without a path also picks up files like `oxlint.config.ts`, which the project service cannot lint unless a `tsconfig.json` includes them.
24
24
 
25
- The preset enables the typed ESLint rule only for `.ts`, `.tsx`, `.mts`, and `.cts` files. It also parses JSX in JavaScript files and ignores `dist` and `coverage` directories.
25
+ The preset enables the typed ESLint rules only for `.ts`, `.tsx`, `.mts`, and `.cts` files. It also parses JSX in JavaScript files and ignores `dist` and `coverage` directories.
26
26
 
27
- Pass project-specific ESLint config objects to `preset()` to apply them last. A severity override for `sonsu-lee-eslint/no-ignored-rejection` without `files` keeps the rule scoped to TypeScript files.
27
+ Pass project-specific ESLint config objects to `preset()` to apply them last. A severity override for a typed rule without `files` keeps the rule scoped to TypeScript files.
28
28
 
29
29
  Use `// oxlint-disable-next-line <rule> -- <reason>` for rules that run only in Oxlint. ESLint reports an unknown rule ID if you name an Oxlint-only rule in an `eslint-disable` comment, even though the preset turns off unused-disable reporting.
30
30
 
@@ -41,3 +41,44 @@ export default preset({
41
41
  ```
42
42
 
43
43
  For example, from `src`, run `eslint .`.
44
+
45
+ ## Astro
46
+
47
+ Oxlint does not parse `.astro` files, so their rules run in ESLint. Install ESLint 10 (the Astro plugin requires it) and the peers:
48
+
49
+ ```sh
50
+ pnpm add -D eslint@10 eslint-plugin-astro astro-eslint-parser @typescript-eslint/parser @sonsu-lee/eslint-config
51
+ ```
52
+
53
+ Compose the `astro` subpath after `preset()`:
54
+
55
+ ```js
56
+ import { preset } from '@sonsu-lee/eslint-config';
57
+ import { astro } from '@sonsu-lee/eslint-config/astro';
58
+
59
+ export default [...preset(), ...astro()];
60
+ ```
61
+
62
+ - The subpath applies the plugin's `recommended` config, keeps `set:html` and inline scripts as warnings, and turns off the style and deprecated rules.
63
+ - Frontmatter always uses `@typescript-eslint/parser`. The plugin picks the parser for a `<script>` block from the project root, so keep `@typescript-eslint/parser` in the project even when `typed` is off.
64
+ - Type-aware rules run on the frontmatter by default. The tsconfig must include the `.astro` files; Astro's default `include` covers them. Pass `{ typed: false }` when the project has no tsconfig, or `{ project: './tsconfig.eslint.json' }` to name one. `astro-eslint-parser` does not support `projectService`, so it forwards `project` and temporarily parses the component as a `.tsx` file.
65
+ - A severity override for a typed rule needs `files: ['**/*.astro']` and must come after `...astro()`. `preset()` moves typed rules in its own user config onto TypeScript files, so a config without `files` never reaches `.astro`:
66
+
67
+ ```js
68
+ export default [
69
+ ...preset(),
70
+ ...astro(),
71
+ { files: ['**/*.astro'], rules: { 'sonsu-lee-eslint/no-ignored-rejection': 'warn' } },
72
+ ];
73
+ ```
74
+
75
+ - `{ a11y: true }` adds the jsx-a11y rules; install `eslint-plugin-jsx-a11y-x` first (the fork that supports ESLint 10). The subpath throws when the peer is missing instead of silently adding no rules.
76
+ - `astro check` is Astro's official type checker. It does not replace these type-aware lint rules.
77
+
78
+ ## AI agents
79
+
80
+ The setup skill, which covers this package too, ships with `@sonsu-lee/oxlint-config`. Its README has the prompt.
81
+
82
+ ## Related
83
+
84
+ See the [architecture guide](../../ARCHITECTURE.md) for how the packages fit together.
@@ -0,0 +1,14 @@
1
+ import { Linter } from "eslint";
2
+ export interface AstroOptions {
3
+ /** Type-aware rules for frontmatter. Default `true`; needs a tsconfig that includes the component. */
4
+ typed?: boolean;
5
+ /** tsconfig path, or `true` for the nearest one. Default `true`. */
6
+ project?: string | true;
7
+ /** Add the jsx-a11y rules; needs eslint-plugin-jsx-a11y-x. */
8
+ a11y?: boolean;
9
+ }
10
+ /**
11
+ * ESLint config for Astro components. Oxlint cannot parse `.astro`, so these rules run only in
12
+ * ESLint. Compose the result after `preset()`.
13
+ */
14
+ export declare function astro(options?: AstroOptions): Linter.Config[];
package/dist/astro.mjs ADDED
@@ -0,0 +1,77 @@
1
+ import { n as typedRules, t as typedRuleNames } from "./typed-rules-DrXlHvd3.mjs";
2
+ import plugin from "@sonsu-lee/eslint-plugin";
3
+ import tsParser from "@typescript-eslint/parser";
4
+ import * as astroParser from "astro-eslint-parser";
5
+ import astroPlugin from "eslint-plugin-astro";
6
+ // src/a11y.ts
7
+ /** Rules the a11y config actually adds. The base configs also carry a `prettier/prettier` rule. */
8
+ function a11yRuleNames(configs) {
9
+ return configs.flatMap((config) => Object.keys(config.rules ?? {}).filter((rule) => rule.startsWith("astro/jsx-a11y/")));
10
+ }
11
+ // src/astro.ts
12
+ const astroFiles = ["**/*.astro"];
13
+ const astroRules = {
14
+ "astro/no-set-html-directive": "warn",
15
+ "astro/no-unsafe-inline-scripts": "warn",
16
+ "astro/no-set-text-directive": "off",
17
+ "astro/no-unused-css-selector": "off",
18
+ "astro/prefer-class-list-directive": "off",
19
+ "astro/prefer-object-class-list": "off",
20
+ "astro/prefer-split-class-list": "off",
21
+ "astro/sort-attributes": "off",
22
+ "astro/semi": "off",
23
+ "astro/no-omitted-end-tags": "off",
24
+ "astro/valid-compile": "off"
25
+ };
26
+ function a11yConfigs() {
27
+ const configs = astroPlugin.configs["jsx-a11y-recommended"];
28
+ if (a11yRuleNames(configs).length === 0) throw new Error("a11y needs eslint-plugin-jsx-a11y-x, but it is not installed.");
29
+ return configs;
30
+ }
31
+ function parserConfig(typed, project) {
32
+ const parserOptions = {
33
+ parser: tsParser,
34
+ extraFileExtensions: [".astro"],
35
+ projectService: false
36
+ };
37
+ if (typed) parserOptions.project = project;
38
+ return {
39
+ name: "sonsu-lee/astro/parser",
40
+ files: astroFiles,
41
+ languageOptions: {
42
+ parser: astroParser,
43
+ parserOptions
44
+ }
45
+ };
46
+ }
47
+ /**
48
+ * ESLint config for Astro components. Oxlint cannot parse `.astro`, so these rules run only in
49
+ * ESLint. Compose the result after `preset()`.
50
+ */
51
+ function astro(options = {}) {
52
+ const { typed = true, project = true, a11y = false } = options;
53
+ const configs = [...astroPlugin.configs.recommended];
54
+ if (a11y) configs.push(...a11yConfigs());
55
+ const own = [
56
+ {
57
+ name: "sonsu-lee/astro/rules",
58
+ files: astroFiles,
59
+ rules: astroRules
60
+ },
61
+ parserConfig(typed, project),
62
+ {
63
+ name: "sonsu-lee/astro/scripts",
64
+ files: ["**/*.astro/*.ts"],
65
+ languageOptions: { parserOptions: { projectService: false } },
66
+ rules: Object.fromEntries(typedRuleNames.map((rule) => [rule, "off"]))
67
+ }
68
+ ];
69
+ if (typed) own.push({
70
+ name: "sonsu-lee/astro/typed",
71
+ files: astroFiles,
72
+ plugins: { "sonsu-lee-eslint": plugin },
73
+ rules: typedRules
74
+ });
75
+ return [...configs, ...own];
76
+ }
77
+ export { astro };
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
+ import { n as typedRules, t as typedRuleNames } from "./typed-rules-DrXlHvd3.mjs";
1
2
  import plugin from "@sonsu-lee/eslint-plugin";
2
3
  import * as parser from "@typescript-eslint/parser";
3
4
  // src/preset.ts
4
5
  const typedFiles = ["**/*.{ts,tsx,mts,cts}"];
5
- const noIgnoredRejection = "sonsu-lee-eslint/no-ignored-rejection";
6
+ const typedRuleSet = new Set(typedRuleNames);
6
7
  function preset(...userConfigs) {
7
8
  return [
8
9
  {
@@ -26,18 +27,27 @@ function preset(...userConfigs) {
26
27
  parser,
27
28
  parserOptions: { projectService: true }
28
29
  },
29
- rules: { [noIgnoredRejection]: "error" }
30
+ rules: typedRules
30
31
  },
31
32
  ...userConfigs.flatMap((config) => {
32
- if (config.files || !config.rules || !(noIgnoredRejection in config.rules)) return [config];
33
- const { [noIgnoredRejection]: severity, ...rules } = config.rules;
33
+ if (config.files || !config.rules) return [config];
34
+ const overridden = Object.keys(config.rules).filter((rule) => typedRuleSet.has(rule));
35
+ if (overridden.length === 0) return [config];
36
+ const rules = { ...config.rules };
37
+ const typedRulesConfig = {};
38
+ for (const rule of overridden) {
39
+ const severity = rules[rule];
40
+ if (severity === void 0) continue;
41
+ typedRulesConfig[rule] = severity;
42
+ delete rules[rule];
43
+ }
34
44
  return [{
35
45
  ...config,
36
46
  rules
37
47
  }, {
38
48
  ...config,
39
49
  files: typedFiles,
40
- rules: { [noIgnoredRejection]: severity }
50
+ rules: typedRulesConfig
41
51
  }];
42
52
  })
43
53
  ];
@@ -0,0 +1,8 @@
1
+ // src/typed-rules.ts
2
+ const typedRuleNames = [
3
+ "sonsu-lee-eslint/no-ignored-rejection",
4
+ "sonsu-lee-eslint/no-query-rest-destructuring",
5
+ "sonsu-lee-eslint/no-void-query-fn"
6
+ ];
7
+ const typedRules = Object.fromEntries(typedRuleNames.map((rule) => [rule, "error"]));
8
+ export { typedRules as n, typedRuleNames as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonsu-lee/eslint-config",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "ESLint preset for type-aware rules that cannot run in Oxlint",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -16,20 +16,28 @@
16
16
  ".": {
17
17
  "types": "./dist/index.d.mts",
18
18
  "default": "./dist/index.mjs"
19
+ },
20
+ "./astro": {
21
+ "types": "./dist/astro.d.mts",
22
+ "default": "./dist/astro.mjs"
19
23
  }
20
24
  },
21
25
  "publishConfig": {
22
26
  "access": "public"
23
27
  },
24
28
  "dependencies": {
25
- "@sonsu-lee/eslint-plugin": "^0.1.0",
29
+ "@sonsu-lee/eslint-plugin": "^0.3.0",
26
30
  "@types/eslint": "9.6.1",
27
31
  "@typescript-eslint/parser": "8.74.0"
28
32
  },
29
33
  "devDependencies": {
30
- "@sonsu-lee/oxlint-config": "^0.1.0",
34
+ "@sonsu-lee/oxlint-config": "^0.3.0",
35
+ "@types/node": "26.6.11",
31
36
  "@typescript-eslint/rule-tester": "8.74.0",
37
+ "astro-eslint-parser": "3.2.0",
32
38
  "eslint": "10.15.0",
39
+ "eslint-plugin-astro": "3.2.3",
40
+ "eslint-plugin-jsx-a11y-x": "0.2.0",
33
41
  "oxlint": "1.90.0",
34
42
  "oxlint-tsgolint": "7.0.2005",
35
43
  "tsdown": "0.23.4",
@@ -37,9 +45,23 @@
37
45
  "vitest": "5.0.5"
38
46
  },
39
47
  "peerDependencies": {
48
+ "astro-eslint-parser": ">=3.2.0",
40
49
  "eslint": "^9.0.0 || ^10.0.0",
50
+ "eslint-plugin-astro": ">=3.2.3",
51
+ "eslint-plugin-jsx-a11y-x": ">=0.2.0",
41
52
  "typescript": ">=4.8.4 <6.1.0"
42
53
  },
54
+ "peerDependenciesMeta": {
55
+ "astro-eslint-parser": {
56
+ "optional": true
57
+ },
58
+ "eslint-plugin-astro": {
59
+ "optional": true
60
+ },
61
+ "eslint-plugin-jsx-a11y-x": {
62
+ "optional": true
63
+ }
64
+ },
43
65
  "scripts": {
44
66
  "build": "tsdown",
45
67
  "test": "vitest run",