Biome Configuration
Relevant source files
The following files were used as context for generating this wiki page:
Biome is utilized in the cheerio-select project as a comprehensive toolchain for formatting, linting, and providing coding assistance. It replaces or complements traditional tools like ESLint and Prettier to ensure code consistency across TypeScript, Markdown, JSON, and YAML files. The configuration is centralized in the biome.json file, which defines the rules for code style, performance optimizations, and complexity management.
Sources: biome.json:1-97, package.json:49-61
Core Configuration Modules
The Biome configuration is structured into several functional modules that govern how the tool interacts with the codebase and how it enforces specific standards.
Version Control System (VCS) Integration
Biome is configured to recognize the project's Git repository. It is specifically set to use the .gitignore file to determine which files should be excluded from processing, ensuring that build artifacts and dependency folders are not linted or formatted.
Sources: biome.json:3-7
File Handling and Scoping
The configuration defines specific inclusion and exclusion patterns. It targets TypeScript (.ts), Markdown (.md), JSON (.json), and YAML (.yml) files while explicitly ignoring node_modules, coverage, lib (build output), and hidden dot-files.
Sources: biome.json:8-17
Formatting and Linting Rules
Biome enforces a strict set of formatting and linting rules to maintain high code quality and readability.
Formatter Settings
The project uses space-based indentation with a width of 4 spaces. This applies generally to all supported file types, with additional empty configuration blocks provided for JavaScript-specific formatting overrides.
Sources: biome.json:18-25
Linter Rulesets
The linter is enabled with recommended rules as a baseline. Specific categories are further tuned:
| Category | Rule | Severity/Status | Description |
|---|---|---|---|
| Suspicious | noConstantBinaryExpressions | Error | Prevents expressions that always evaluate to the same result. |
| Suspicious | useAwait | Error | Ensures await is used in async functions. |
| Complexity | useWhile | Error | Prefers while loops over for loops where appropriate. |
| Performance | useTopLevelRegex | Error | Encourages moving Regex definitions to the top level for optimization. |
| Style | useConsistentTypeDefinitions | Error | Enforces uniform interface vs type usage. |
| Style | useFilenamingConvention | Error | Ensures file names follow project standards. |
Sources: biome.json:26-72
Architecture of Tooling Integration
The following diagram illustrates how Biome integrates into the development workflow alongside other project tools.
The package.json file integrates Biome via scripts, allowing developers to run npm run lint:biome for checking and npm run format:biome for automatic code correction.
Sources: package.json:54-58, biome.json:26-30
Environment-Specific Overrides
Biome allows for specific rule adjustments based on file patterns. This is primarily used in cheerio-select to handle test environments and specific TypeScript variations.
Test Environment Globals
For files matching **/*.{test,spec}.ts or within the test/ directory, Biome defines global variables to prevent linting errors related to undefined testing framework functions.
- Globals:
jest,describe,it,beforeEach,afterEach,expect,vi.
TypeScript Complexity Overrides
A specific override is applied to all TypeScript file variations (.ts, .cts, .mts, .tsx) to disable the useLiteralKeys complexity rule, likely to allow flexible property access required by the DOM manipulation logic in src/index.ts.
Sources: biome.json:80-97, src/index.ts:1-20
Implementation in Scripts
The Biome configuration is executed through the following package.json commands:
"scripts": {
"format:biome": "biome check --write .",
"lint:biome": "biome check .",
"lint": "npm run lint:es && npm run lint:biome"
}
Sources: package.json:54-58
Conclusion
The Biome configuration in cheerio-select provides a robust, high-performance alternative to traditional linting and formatting suites. By centralizing rules in biome.json and integrating them directly into the npm workflow, the project ensures consistent style and prevents common programming errors through its extensive suite of "Style," "Performance," and "Complexity" rules.
Sources: biome.json:1-97, package.json:54-58