Skip to content

Commit

Permalink
Astroプリセットを FlatConfig に対応 (#288)
Browse files Browse the repository at this point in the history
* fix: astro config works correctly

* デフォルトで TS プリセットを同梱する

* chore: update snapshot (github-actions)

* Create orange-crabs-fetch.md

Signed-off-by: Kentaro Suzuki <[email protected]>

---------

Signed-off-by: Kentaro Suzuki <[email protected]>
Co-authored-by: actions-miku[bot] <185786754+actions-miku[bot]@users.noreply.github.com>
  • Loading branch information
sushichan044 and actions-miku[bot] authored Oct 26, 2024
1 parent d3ddb73 commit d4ac1db
Show file tree
Hide file tree
Showing 7 changed files with 2,527 additions and 276 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-crabs-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@virtual-live-lab/eslint-config": patch
---

Astroプリセットを FlatConfig に移行
6 changes: 5 additions & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
"eslint": "^9.13.0"
},
"dependencies": {
"@astrojs/compiler": "^2.10.3",
"@eslint/compat": "^1.2.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
"@stylistic/eslint-plugin-ts": "^2.9.0",
"@typescript-eslint/utils": "^8.11.0",
"astro-eslint-parser": "^1.0.3",
"astrojs-compiler-sync": "^1.0.1",
"eslint": "^9.13.0",
"eslint-config-flat-gitignore": "^0.3.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -49,7 +52,8 @@
"eslint-plugin-tailwindcss": "^3.17.5",
"globals": "^15.11.0",
"pkg-dir": "^8.0.0",
"typescript-eslint": "^8.11.0"
"typescript-eslint": "^8.11.0",
"typescript-eslint-parser-for-extra-files": "^0.7.0"
},
"devDependencies": {
"@types/eslint": "9.6.1",
Expand Down
62 changes: 51 additions & 11 deletions packages/eslint-config/src/base/astro.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
import * as astroESLintParser from "astro-eslint-parser";
import astroPlugin from "eslint-plugin-astro";
import tseslint from "typescript-eslint";
import * as typescriptESLintParserForExtraFiles from "typescript-eslint-parser-for-extra-files";

import eslintPluginAstro from "eslint-plugin-astro";
import { __dirname } from "../lib/dir";
import { astroFiles, tsFiles } from "../utils/files";
import { jsConfig } from "./js";
import { stylisticConfig } from "./stylistic";
import { tsConfig } from "./typescript";

const astroConfig = [
// eslint-plugin-astroの型定義の都合上anyと判定されてしまうので、asを使って型を指定する
...eslintPluginAstro.configs["flat/recommended"],
// flat/jsx-a11y-strictは、eslint-plugin-jsx-a11yの設定をベースにしているので、
// インストールされていないとエラーになるが、このパッケージはdependenciesに含まれているので問題ない
...eslintPluginAstro.configs["flat/jsx-a11y-strict"],
] satisfies FlatConfig.ConfigArray;

export { astroConfig };
export const astroConfig = tseslint.config(
{
files: [tsFiles],
languageOptions: {
parser: typescriptESLintParserForExtraFiles,
parserOptions: {
project: true,
projectService: false,
tsconfigRootDir: __dirname,
},
},
},
{
extends: [
...jsConfig,
...stylisticConfig,
...tsConfig,
...astroPlugin.configs.recommended,
...astroPlugin.configs["jsx-a11y-strict"],
],
files: [astroFiles],
languageOptions: {
parser: astroESLintParser,
parserOptions: {
parser: typescriptESLintParserForExtraFiles,
project: true,
projectService: false,
tsconfigRootDir: __dirname,
},
},
name: "@virtual-live-lab/eslint-config/astro",
rules: {
"astro/no-set-html-directive": "error",
"astro/no-set-text-directive": "error",
"astro/no-unused-css-selector": "error",
"astro/prefer-class-list-directive": "error",
"astro/prefer-object-class-list": "error",
"astro/prefer-split-class-list": "error",
"astro/sort-attributes": "error",
},
},
);
9 changes: 2 additions & 7 deletions packages/eslint-config/src/presets/astro.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";

import tseslint from "typescript-eslint";

import { astroConfig } from "../base/astro";
import react from "./react";
import ts from "./ts";

const astro = tseslint.config(
...react,
...astroConfig,
) satisfies FlatConfig.ConfigArray;
const astro = tseslint.config(...ts, ...astroConfig);

export default astro;
1 change: 1 addition & 0 deletions packages/eslint-config/src/utils/files.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const tsFiles = "**/*.{ts,tsx,mts,cts}";
export const jsFiles = "**/*.{js,jsx,mjs,cjs}";
export const jsxFiles = "**/*.{jsx,tsx}";
export const astroFiles = "**/*.astro";
Loading

0 comments on commit d4ac1db

Please sign in to comment.