Does ESLint offer a built‑in plain‑text formatter that disables ANSI colors for screen‑reader accessibility?
0 reputation · 16 Sept 2024, 05:24 UTC
0 reputation · 16 Sept 2024, 05:24 UTC
Determine whether ESLint can be configured to output lint results in a plain‑text, color‑free format that retains the same structural information (file path, line number, rule ID, message) for users who rely on screen readers or need non‑color‑dependent output.
The default CLI uses ANSI colors when a TTY is detected; the --format flag offers JSON, JUnit, HTML, or custom formatters, but none of the built‑in formatters explicitly strip colors while preserving the human‑readable layout. There is an unresolved discussion about enabling color output by default in non‑TTY environments, and no consensus on a default accessible format.
Does ESLint provide a built‑in formatter that disables ANSI colors while keeping the same plain‑text layout? If not, what would be required to add such a formatter or to make the default output accessible in CI and local terminals?
35275 reputation · 16 Sept 2024, 08:33 UTC
ESLint does not provide a specific "plain-text" formatter that replicates the exact visual layout of the default stylish formatter while stripping colors. However, it provides the compact formatter, which outputs lint results in a standardized, color-free, single-line format that retains all critical structural information.
Depending on whether you need a different structural layout or simply want to remove colors from the existing layout, use one of the following methods:
The compact formatter is the built-in solution for non-color-dependent, human-readable output. It prints one problem per line in the format: file:line:column severity - rule-id: message.
eslint . --format compact
If you prefer the structural layout of the default stylish formatter but need to disable ANSI escape sequences for screen readers or CI logs, ESLint respects the NO_COLOR environment variable standard. Setting this variable forces the formatter to omit color codes regardless of the TTY status.
NO_COLOR=1 eslint .
| Method | Layout | ANSI Colors | Best Use Case |
|---|---|---|---|
--format compact |
Single-line per error | No | Screen readers, grep, simple logs |
NO_COLOR=1 |
Grouped by file (Stylish) | No | Human review without color dependency |
To verify that ANSI escape sequences have been successfully removed, pipe the output to cat -v. If colors are present, you will see sequences like ^[[31m; if they are disabled, the output will be clean text.
eslint . --format compact | cat -v
Note: If you require a specific column-aligned layout that is not provided by compact or stylish, you would need to implement a custom formatter function and pass it via the --format flag.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.