class PrettierFormatter(LanguageFormatter):
"""Multi-language formatter using prettier."""
@property
def name(self) -> str:
return "Prettier"
@property
def command(self) -> str:
return "prettier"
@property
def extensions(self) -> list[str]:
return [".html", ".css", ".scss", ".less", ".md", ".markdown", ".yaml", ".yml", ".graphql"]
@property
def pygments_lexers(self) -> list[str]:
return ["html", "css", "scss", "less", "markdown", "md", "yaml", "graphql"]
async def format(self, path: Path) -> FormatResult:
cmd = ["prettier", "--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:
# Prettier is format-only, check mode reports if file is formatted
cmd = ["prettier", "--check", 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,
)