Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

indentier/.idea

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Indentier (インデンティア) 総合仕様書

"A silly formatter that hides braces, semicolons and commas in the right margin — letting curly-brace languages pretend they're Python or Ruby." Indentier は、{ } ; , を右端に隠して、波括弧言語に Python や Ruby のフリをさせる、ふざけたフォーマッターです。

1. サポート言語と処理アーキテクチャ

Indentier は AST(抽象構文木)による厳密なパースを行わず、行ベースの正規表現とスタック走査によるヒューリスティックな処理を採用しています。これにより、C 系構文を持つほぼすべての言語をサポートします。

カテゴリ 対象拡張子 対応状況と特徴
JS / TS系 .js, .cjs, .mjs, .jsx, .ts, .cts, .mts, .tsx コアで完全対応ruby モードの隠蔽宣言は let end=null;
System .rs, .go, .c, .h, .cpp, .hpp プラグインで対応 (@indentier/plugin-rust / @indentier/plugin-go / @indentier/plugin-c)。Rust の match 内のコンマなども綺麗に右へ飛ぶ。
Server Side .php, .java, .cs プラグインで対応 (@indentier/plugin-php / @indentier/plugin-java / @indentier/plugin-cs)。PHP の ruby モードの宣言は $end=null; に置き換わる。Java / C# は ruby モード非対応。
Web Styling .css, .scss, .less プラグインで対応 (@indentier/plugin-css)。{}; を右に飛ばすことで Sass(インデント構文)のように見せる。ruby モード非対応。

2. .indentierrc の仕様 (Configuration)

2.1. サポートするファイル形式 (Cosmiconfig互換)

Indentier はプロジェクトルートから以下の設定ファイルを自動探索します。

  • package.json"indentier" プロパティ)
  • .indentierrc.{json,yaml,yml}
  • .indentierrc.{js,cjs,mjs,ts,cts,mts}
  • indentier.config.{js,cjs,mjs,ts,cts,mts}

2.2. 設定項目とデフォルト値

プロパティ デフォルト 効果・説明
mode string "default" フォーマットの挙動モード(後述)。"default" または "ruby"
tabWidth number 2 基準となるインデントのスペース数。記号を飛ばす前にこの幅でコードを正規化します。
useTabs boolean false true の場合、コード本体のインデントをタブ文字で構成します(右の余白はスペースを使用)。
offset number 20 ファイル内の最長行(記号除去後)の末尾から、記号を配置する列までのスペース数。
minColumn number 80 記号を配置する最低保証カラム位置。短いファイルでもこの位置までは記号を右へ追いやります。
brackets boolean true {} を右端へ移動させます。([ ] は idempotency 維持のため移動しません)
semicolon boolean true 文末の ; を右端へ移動させます。}; のように密着している場合はセットで移動します。
comma boolean true マルチライン時のみ、行末の , を右端へ移動させます。1行の配列内のコンマは移動しません。
ruby object (後述) mode: "ruby" の際の詳細設定オブジェクト。
overrides array [] 特定のファイルや拡張子に対する設定の上書き。Prettier の overrides と同等。
plugins string[] [] 読み込む @indentier/plugin-* パッケージ名の配列。

2.3. ruby オブジェクトの詳細

プロパティ デフォルト 効果・説明
variableName string "end" ブロック終了を示す変数名。
injectDeclaration boolean true true の場合、ファイル内で最初に出現した { の直後に let end=null; を自動挿入し、JS としての構文エラーを防ぎます。
smartEnd boolean true true の場合、else / catch / finally / while の直前では end を挿入しません。

3. モード (Modes) の解説

3.1. default モード

構文上の記号({}, ;, ,)を指定のカラムまで右に移動させるだけの、純粋な「隠蔽」モードです。 元のコードの言語仕様を一切壊さず、ただ見た目だけをインデントベースのように見せかけます。

3.2. ruby モード

default の挙動に加え、ブロックの終端にRuby風の end キーワード(実態はダミー変数)を視覚的に配置するモードです。 インデントが下がる(ブロックが閉じる)タイミングで、次の行に end を単独で配置し、完璧なRuby擬態を行います。


4. .indentierignore の仕様

Prettier と同様に、フォーマットを除外する対象を指定します。

  • .gitignore と完全互換の glob 構文を使用。
  • 暗黙的な除外は行わない.indentierignore が存在しなければ何も除外されない。
  • indentier --init で生成される .indentierignore の雛形には以下のパスが含まれる:
    • node_modules/
    • dist/, build/, out/
    • .git/, .next/, .nuxt/

5. CLI 仕様 (Command Line Interface)

Node.js 22+ 環境で動作し、Prettier の DX を踏襲した CLI を提供します。

5.1. コマンド一覧

  • indentier --init プロジェクトに Indentier を導入します。 対話型、あるいは自動で .indentierrc.json.indentierignore をプロジェクトルートに生成します。
  • indentier --write <path> (エイリアス: -w) 指定されたファイルやディレクトリのファイルをフォーマットし、上書き保存します。 例: indentier --write "src/**/*.ts"
  • indentier --check <path> (エイリアス: -c) ファイルがすでにフォーマットされているか確認します。フォーマットされていないファイルがあれば標準出力にリストアップし、終了コード 1 を返します(CI 環境での検証用)。
  • indentier <path> ファイルをフォーマットし、結果を標準出力(stdout)に表示します。ファイルの上書きは行いません。

5.2. その他のオプション

  • --mode <mode>: RC ファイルを無視してモードを指定。
  • --offset <number>: オフセット幅を一時的に上書き。
  • --no-semi: セミコロンの移動を一時的に無効化。
  • --no-comma: 行末カンマの移動を一時的に無効化。

6. 実装・依存ライブラリ計画

Node.js 22 以降のモダンな API(node:fs/promises, ESM)をベースに構築します。

  • CLI パーサー: commander (標準的な CLI 引数解析)
  • ファイル探索: fast-glob + ignore (.indentierignore の解釈と高速な検索)
  • 設定ファイル読み込み: cosmiconfig (各種 RC ファイルの自動解決)
  • 色付け・UI: picocolors (軽量な CLI カラーリング)

処理フローの要件

  1. Read: ファイルを行ごとに分割してメモリに読み込む。
  2. Normalize Indent: tabWidth に合わせて行頭の空白を正規化。
  3. Extract: 各行の末尾から正規表現で [{},;]+ を抽出して分離。
  4. Measure: 記号を取り除いた後の全行のうち、最大の長さを取得 (maxLen)。
  5. Align: Math.max(maxLen + offset, minColumn) の位置に、抽出した記号を padEnd などを利用して配置。
  6. Ruby Inject: mode: "ruby" かつ smartEnd: true の条件に従い、ブロックの深さを計算して end 行を挿入。

About

The initial idea. Created in collaboration with Gemini.

Resources

License

CC-BY-4.0, MIT licenses found

Licenses found

CC-BY-4.0
LICENSE-CC-BY-4.0
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors