Skip to content

tsconfig / prettier 設定を最厳格化#372

Merged
ROhta merged 6 commits into
mainfrom
worktree-tsconfig-strict
May 23, 2026
Merged

tsconfig / prettier 設定を最厳格化#372
ROhta merged 6 commits into
mainfrom
worktree-tsconfig-strict

Conversation

@ROhta

@ROhta ROhta commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • tsconfig: `@tsconfig/strictest` と重複しない範囲で TypeScript 6.0 の厳格化フラグを全て有効化
  • prettier: CLI 専用項目を整理し、厳格化フラグを適用(HTML系の `"strict"` / `singleAttributePerLine` は実用バランスで不採用)
  • lint-staged: glob 整理で `.prettierignore` 不要化(設定ファイル削減)
  • いずれもソースコード修正は不要で `tsc --noEmit` / `prettier --check` ともに 0 errors

変更1: tsconfig 厳格化(49d25d5)

追加した厳格化(4項目)

項目 効果
`erasableSyntaxOnly: true` enum / namespace / parameter property 等、消去不能なTS固有実行時構文を禁止
`verbatimModuleSyntax: true` 型用途の import に `import type` を強制
`isolatedDeclarations: true` エクスポート宣言の型推論を許さず、ソース単独で `.d.ts` 生成可能に強制
`noUncheckedSideEffectImports: true` 副作用のみの import でも実体ファイル存在をチェック

デフォルト値の明示化(4項目/将来の挙動変更耐性)

  • `forceConsistentCasingInFileNames: true`
  • `useDefineForClassFields: true`
  • `allowJs: false`
  • `moduleDetection: "force"`

変更2: Prettier 厳格化(2b0fd2f, b0d5f7d, 7a21048

削除(CLI専用 / プロジェクト無関係)

  • `rangeStart` / `rangeEnd` / `filepath` — CLI 引数専用で設定ファイルでは無効
  • `vueIndentScriptAndStyle` / `jsxSingleQuote` — Vue/JSX 不使用

厳格化(既存設定の変更)

項目 Before → After 効果
`endOfLine` `"auto"` → `"lf"` クロスプラットフォームで LF 強制
`trailingComma` `"es5"` → `"all"` Prettier 3.0 デフォルト、TS末尾カンマ強制で diff 最小化
`htmlWhitespaceSensitivity` `"ignore"` → `"css"` デフォルト値を明示化
`proseWrap` `"never"` → `"always"` Markdown を printWidth で折り返す

新規追加(デフォルト値の明示化/将来耐性)

  • `bracketSameLine: false`
  • `singleAttributePerLine: false`
  • `embeddedLanguageFormatting: "auto"`
  • `objectWrap: "preserve"` (Prettier 3.5+)
  • `experimentalOperatorPosition: "end"` (Prettier 3.5+)

既存問題の解消と維持

  • `.github/workflows/dependabot-auto-merge.yml` — PR Dependabot auto-merge workflow追加 #365 由来のフォーマット不一致を解消。`if:` 条件の `&&` ごとの改行は `# prettier-ignore` で保持(commit 687aae9
  • `eslint.config.mjs` も `prettier --write` で整形
  • `src/index.html` は最終的に main と同形(singleAttributePerLine: false 回帰により)

変更3: lint-staged glob 整理+.prettierignore 廃止(c0932b7)

Before(問題点)

```json
"lint-staged": {
"src/ts/*.ts": [
"pnpm exec eslint . --fix",
"pnpm exec prettier --write ."
]
}
```

  • `prettier --write .` の `.` で 全ディレクトリ再走査 が発生(lint-staged が渡すファイルパスと二重走査)
  • `.prettierignore` が無いと `pnpm-lock.yaml` まで対象になり、独立した除外ファイルが必要

After

```json
"lint-staged": {
".{ts,mjs,cjs}": ["pnpm exec eslint --fix", "pnpm exec prettier --write"],
"
.{html,css,json,md}": ["pnpm exec prettier --write"],
"!(pnpm-lock).{yml,yaml}": ["pnpm exec prettier --write"]
}
```

  • 末尾の `.` を削除 → lint-staged が変更ファイルだけを引数として渡す(公式推奨の書き方)
  • ファイル種別ごとに glob を分割
  • 否定 glob `!(pnpm-lock)` で `pnpm-lock.yaml` をビルトイン除外
  • `.prettierignore` を削除(設定ファイルを1つ減らせた)

`lint-staged@17` は `matchBase: !pattern.includes("/")` を picomatch に渡すため、`*.ts` のような slash 無し glob は basename マッチで全階層に効きます(matchFiles.js 参照)。

除外した項目(理由付き)

tsconfig

  • `noErrorTruncation` — 診断オプションで厳格化ではない
  • strict ファミリーの明示指定 — `strict: true` 経由で既に有効
  • `checkJs` — `allowJs: false` で対象なし
  • `importsNotUsedAsValues` / `preserveValueImports` — `verbatimModuleSyntax` で代替(deprecated)

prettier

  • `experimentalTernaries` — 不安定機能
  • `printWidth` 変更 — 既存設定 `1000` は意図的な選択として尊重
  • `htmlWhitespaceSensitivity: "strict"` — `>text</tag\n>` の独特な書き方が生じるため不採用
  • `singleAttributePerLine: true` — diff の読みやすさより HTML 全体の縦長化が大きすぎるため不採用

Test plan

  • `npx tsc --noEmit` が 0 errors で通過
  • `npx tsc` フルビルドが 0 errors で通過
  • `npx prettier --check .` 全パス
  • lint-staged 実動作確認(pre-commit hook が正しく振り分け)
  • `src/index.html` は main と同形に回帰(描画影響ゼロ)
  • CI(lint / type-check / build / deploy)通過確認

@tsconfig/strictest と重複しない範囲で TypeScript 6.0 が提供する最厳格化フラグを
全て有効化。erasableSyntaxOnly / verbatimModuleSyntax / isolatedDeclarations /
noUncheckedSideEffectImports に加え、デフォルト値の項目も明示化して将来の挙動
変更に備える。tsc は 0 errors で通過。
Copilot AI review requested due to automatic review settings May 23, 2026 03:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@ROhta

ROhta commented May 23, 2026

Copy link
Copy Markdown
Owner Author

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@ROhta ROhta self-assigned this May 23, 2026
- 削除: rangeStart / rangeEnd / filepath (CLI専用で設定ファイルでは無効)
- 削除: vueIndentScriptAndStyle / jsxSingleQuote (フレームワーク無関係)
- 厳格化: endOfLine "auto" → "lf"
- 厳格化: trailingComma "es5" → "all" (Prettier 3.0 デフォルト)
- 厳格化: htmlWhitespaceSensitivity "ignore" → "strict"
- 厳格化: proseWrap "never" → "always"
- 新規: singleAttributePerLine: true (HTML属性を縦並びに)
- 新規: bracketSameLine / embeddedLanguageFormatting / objectWrap /
  experimentalOperatorPosition を明示化(将来のデフォルト変更耐性)

.prettierignore を新設し pnpm-lock.yaml / src/js/ を対象外に。
prettier --write で eslint.config.mjs / src/index.html /
dependabot-auto-merge.yml(PR #365由来の既存未整形) を整形。
prettier --check と tsc --noEmit はともに 0 errors。
@ROhta ROhta changed the title tsconfig: strict/strictest外の厳格化フラグを全て追加 tsconfig / prettier 設定を最厳格化 May 23, 2026
ROhta added 4 commits May 23, 2026 13:08
prettier --write の末尾の "." を削除し、lint-staged が渡す
変更ファイルだけを整形する正しい形式に修正。glob を
ファイル種別ごとに分割し、否定 glob !(pnpm-lock) で
pnpm-lock.yaml をビルトイン除外。設定ファイルを1つ削減。

副次効果:
- ESLint も "." 廃止で変更ファイルのみ lint (二重走査解消)
- .github/ 配下の yml と md も自動整形対象に拡大
- ルート直下の yaml (pnpm-lock を除く) も対象に
printWidth: 1000 配下では Prettier が >- 折り畳みスカラーの中身を
1行に統合してしまうため、可読性のために && ごとに改行していた if 句が
潰されていた。# prettier-ignore コメントで該当ブロックだけ整形対象外にし、
YAML 意味論(>- = 改行→空白)と GitHub Actions の評価互換性を保ったまま、
ソース上の改行を維持する。
strict は閉じタグの > を独立行に切り出す独特なフォーマットを生み、
diff/可読性ともに代償が大きかった。デフォルトの css に戻して
通常の <tag>\n  text\n</tag> 形式へ。singleAttributePerLine: true は
維持し、属性縦並びの厳格化は引き続き有効。
属性縦並びは diff の読みやすさを得る代わりに HTML 全体が縦に
長くなり、初見の可読性を損なう側面が大きかった。デフォルトの
false に戻して属性横並びに復帰。src/index.html は main と同形に
戻る。デフォルト値の明示化方針は維持。
@ROhta
ROhta merged commit 9d47afc into main May 23, 2026
7 checks passed
@ROhta
ROhta deleted the worktree-tsconfig-strict branch May 23, 2026 11:45
@ROhta ROhta added the bug-3 改善 割れ窓で直す label May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-3 改善 割れ窓で直す

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants