Linting and Formatting with Biome
Relevant source files
The following files were used as context for generating this wiki page:
The nth-check project utilizes Biome as a modern, high-performance toolchain for maintaining code quality and consistency. Biome is integrated into the development workflow to handle linting, formatting, and automated code organization (assists). It complements other tools in the repository, such as ESLint and TypeScript, to ensure the codebase adheres to strict stylistic and logical standards.
Sources: package.json:44, biome.json:1-122
Core Configuration
The Biome configuration is centralized in biome.json. This file defines the scope of the tool, its integration with version control, and specific rules for different file types.
Global Settings
Biome is configured to recognize the project's Git environment and ignore files specified in the .gitignore. It includes a wide range of file extensions for processing, including TypeScript, Markdown, JSON, and YAML.
Sources: biome.json:3-17
Formatter and Linter Rules
The project enables both the formatter and the linter with specific overrides for code style and potential logic errors.
| Category | Setting | Description |
|---|---|---|
| Formatter | indentStyle: space | Uses spaces for indentation. |
| Formatter | indentWidth: 4 | Sets indentation level to 4 spaces. |
| Linter | recommended: true | Enables Biome's recommended rule set. |
| Assist | organizeImports: on | Automatically sorts and organizes import statements. |
Sources: biome.json:18-22, biome.json:26-28, biome.json:76-82
Workflow Integration
Biome is integrated into the project's lifecycle via NPM scripts. It serves as a verification layer during testing and a correction layer during formatting.
The diagram shows how Biome is invoked for both passive linting and active formatting within the CLI environment.
Sources: package.json:28-36
Script Definitions
| Script | Command | Purpose |
|---|---|---|
lint:biome | biome check . | Checks the project for linting issues and formatting violations. |
format:biome | biome check --write . | Automatically fixes linting errors and reformats code. |
lint | ... && npm run lint:biome | Aggregate script that runs all linters, including Biome. |
test | ... && npm run lint | Ensures linting passes as part of the test suite. |
Sources: package.json:31-37
Specialized Rule Sets
The project enforces specific linter rules categorized by complexity, performance, and style to maintain the "highly optimized" nature of the nth-check library.
Key Linter Categories
- Complexity: Enforces simplified logic expressions and discourages useless string concatenations or
undefinedassignments. - Performance: Requires the use of top-level regular expressions to avoid unnecessary recompilation.
- Suspicious: Catches potential bugs like constant binary expressions and missing
awaitkeywords. - Style: Enforces consistent type definitions, arrow function returns, and naming conventions.
Sources: biome.json:30-74
Target-Specific Overrides
Biome applies different rules based on the file context, particularly for test files and TypeScript modules.
This structure ensures that development-only utilities or specific TypeScript patterns do not trigger false positives.
Sources: biome.json:83-121
Conclusion
Biome provides a unified toolchain for the nth-check project, handling formatting and linting with a focus on performance and strict stylistic consistency. By integrating Biome into the package.json scripts, the project ensures that every contribution is automatically verified against the established ruleset defined in biome.json.
Sources: package.json:31-37, biome.json:1-5