class BiomeFormatter(LanguageFormatter):
"""TypeScript/JavaScript/JSON formatter using biome."""
@property
def name(self) -> str:
return "TypeScript"
@property
def command(self) -> str:
return "biome"
@property
def extensions(self) -> list[str]:
return [".ts", ".tsx", ".js", ".jsx", ".json", ".jsonc"]
@property
def pygments_lexers(self) -> list[str]:
return ["typescript", "ts", "javascript", "js", "jsx", "tsx", "json"]
async def format(self, path: Path) -> FormatResult:
cmd = ["biome", "format", "--write", str(path)]
success, stdout, stderr, duration, error_type = await self._execute_command(cmd)
return FormatResult(
success=success,
output=stdout,
errors=stderr,
formatted=success,
duration=duration,
error_type=error_type,
)
async def lint(self, path: Path, fix: bool = False) -> LintResult:
cmd = ["biome", "lint"]
if fix:
cmd.append("--write")
cmd.append(str(path))
success, stdout, stderr, duration, error_type = await self._execute_command(cmd)
return LintResult(
success=success,
output=stdout,
errors=stderr,
duration=duration,
error_type=error_type,
)