format_directory.ts

view source

Declarations
#

3 declarations

format_directory
#

format_directory.ts view source

(log: Logger, dir: string, check?: boolean, filter?: PathFilter | PathFilter[] | undefined, patterns?: string[] | undefined): Promise<FormatDirectoryResult> import {format_directory} from '@fuzdev/gro/format_directory.js';

Formats files on the filesystem in-process via format_file. When patterns is provided, formats those specific files/globs. Otherwise formats dir (recursively, respecting filter) plus the root files when dir is paths.source. In both modes, files matched by the project root's .formatignore or .prettierignore are skipped.

Files the formatter rejects (e.g. a syntax error) are reported and fail the run in both modes rather than being silently skipped.

This is separated from ./format_file so modules that only need directory traversal don't pull in the formatter (which loads the tsv native addon).

log

type Logger

dir

type string

check

when true, reports unformatted files instead of writing them

type boolean
default false

filter?

directory filters (e.g. config.search_filters) to skip; also prunes patterns results so an explicit glob can't reach node_modules

type (PathFilter) | (PathFilter)[]
optional

patterns?

type string[]
optional

returns

Promise<FormatDirectoryResult>

FormatDirectoryResult
#

format_directory.ts view source

FormatDirectoryResult import type {FormatDirectoryResult} from '@fuzdev/gro/format_directory.js';

ok

type boolean

formatted

The files that were formatted (or, in check mode, that need formatting).

type string[]

errored

Files the formatter rejected (e.g. a syntax error), left untouched.

type { id: string; error: unknown; }[]

read_format_ignore
#

format_directory.ts view source

(root: string): Set<string> import {read_format_ignore} from '@fuzdev/gro/format_directory.js';

Reads the root ignore files (.formatignore and .prettierignore) and expands their merged gitignore-style globs to a set of absolute paths the format sweep skips. A pattern with no / matches at any depth (*.md becomes ** /*.md); a pattern with / is anchored to the root. Blank lines and # comments are ignored, and absent files yield an empty set (skip nothing).

root

type string

returns

Set<string>

Depends on
#

Imported by
#