Back to Biomejs

Diagnostics

src/content/docs/reference/diagnostics.mdx

latest5.2 KB
Original Source

import DiagnosticFatal from "@/components/generated/diagnostics/DiagnosticFatal.md"; import DiagnosticError from "@/components/generated/diagnostics/DiagnosticError.md"; import DiagnosticWarning from "@/components/generated/diagnostics/DiagnosticWarning.md"; import DiagnosticInformation from "@/components/generated/diagnostics/DiagnosticInformation.md"; import DiagnosticVerbose from "@/components/generated/diagnostics/DiagnosticVerbose.md"; import DiagnosticInternal from "@/components/generated/diagnostics/DiagnosticInternal.md"; import DiagnosticFixable from "@/components/generated/diagnostics/DiagnosticFixable.md"; import DiagnosticDeprecated from "@/components/generated/diagnostics/DiagnosticDeprecated.md"; import DiagnosticCategorySimple from "@/components/generated/diagnostics/DiagnosticCategorySimple.md"; import DiagnosticCategoryLink from "@/components/generated/diagnostics/DiagnosticCategoryLink.md"; import DiagnosticLocFile from "@/components/generated/diagnostics/DiagnosticLocFile.md"; import DiagnosticLocFrame from "@/components/generated/diagnostics/DiagnosticLocFrame.md"; import DiagnosticLocAll from "@/components/generated/diagnostics/DiagnosticLocAll.md"; import DiagnosticLocMultiline from "@/components/generated/diagnostics/DiagnosticLocMultiline.md"; import DiagnosticWithAdvice from "@/components/generated/diagnostics/DiagnosticWithAdvice.md";

Biome's diagnostics are full of information, and they usually provide all the information you need to understand errors, and fix them.

Diagnostics aren't only used for errors, but they are also used to provide structured information, warnings and tips.information

This page provide a break down of all the information that a diagnostic can contain. Learning all the different parts of a diagnostic can help you to identify the important parts, and some "secrets" behind them.

Diagnostic severity

The severity of the diagnostic can affect the CLI. For example, error diagnostics will force the CLI to exit with an error code.

Fatal

Error diagnostics have red text. Fatal diagnostics are usually emitted when an unexpected error occurred inside Biome. Compared to errors, they have the fatal tag.

<DiagnosticFatal />

Error

Error diagnostics have red text. Usually, they should be addressed because they will emit an error code when encountered by the CLI.

<DiagnosticError />

Warning

Warning diagnostics have yellow text. Usually, they should be addressed. Warnings are not blockers, and they won't stop the CLI from working.

<DiagnosticWarning />

Information

Information diagnostics have green text. They provide useful information and they aren't meant to block the CLI.

<DiagnosticInformation />

Diagnostic tags

Tags can be seen as metadata attached to a diagnostic, and they can affect the clients in different ways.

Verbose

Verbose diagnostics are usually hidden. Via CLI, you can show these diagnostics using the --verbose option.

<DiagnosticVerbose />

Internal

Internal diagnostics are emitted when an internal error occurred. Users are usually encourage to file a bug when they see one.

<DiagnosticInternal />

Fixable

Fixable diagnostics are emitted for those particular situations that can be fixed by the user. They are usually used for lint diagnostics that have a code action.

<DiagnosticFixable />

Deprecated

Diagnostics that contain code that is deprecated

<DiagnosticDeprecated />

Diagnostic category

The category serves to group diagnostics. Optionally, a category can have a link, for example, for categories that belong to lint rules, like in the example below.

Simple category

This diagnostic belongs to the category "check", which means that it is emitted when executing the check command:

<DiagnosticCategorySimple />

This diagnostics belongs to the category "lint/a11y/noAccessKey". The link takes the user to the webpage of the lint rule noAccessKey.

<DiagnosticCategoryLink />

Diagnostic location

Diagnostics can have a "location". A location is made by three, optional, parts:

  • a resource, which is the origin that emitted the diagnostic;
  • source code of the file;
  • a span (or text range), usually the line and column inside the file.

Diagnostic file path

The file path is usually the first information you see, at the top left of the diagnostic.

<DiagnosticLocFile />

Diagnostic source code

This shows how the source code associated to a file is shown. Notice that the line and columns aren't shown.

<DiagnosticLocFrame />

Diagnostic line and column

Line and column is usually printed beside the file path, and it's shown only when there's some source code associated to it.

<DiagnosticLocAll />

When the diagnostics are printed inside the terminal of an IDE, you can click path/to/file.js:2:2, and the IDE will open the relative file, and place cursor at the beginning of the span.

<DiagnosticLocMultiline />

Diagnostic advices

Additionally, our diagnostics can store advices. Advices are additionally messages that can be appended after the original message.

These advices comes with different kinds and shapes. Usually, advices are always printed, unless they are verbose advices.

<DiagnosticWithAdvice />