Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/smooth-dots-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@biomejs/biome": minor
---

Added the new linter domain `types`. This is a domain that enables all rules that require the type inference engine.

As opposed to the `project` domain, which only enables rules that require the module graph to function.

The following **nursery** rules have been moved to the `types` domain:
- `useArraySortCompare`
- `useAwaitThenable`
- `useFind`
- `useRegexpExec`
- `noUnnecessaryConditions`
- `noMisusedPromises`
- `noFloatingPromises`
7 changes: 7 additions & 0 deletions crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ pub enum RuleDomain {
Tailwind,
/// Turborepo build system rules
Turborepo,
/// Rules that require type inference
Types,
}

impl Display for RuleDomain {
Expand All @@ -490,6 +492,7 @@ impl Display for RuleDomain {
Self::Project => fmt.write_str("project"),
Self::Tailwind => fmt.write_str("tailwind"),
Self::Turborepo => fmt.write_str("turborepo"),
Self::Types => fmt.write_str("types"),
}
}
}
Expand Down Expand Up @@ -530,6 +533,7 @@ impl RuleDomain {
Self::Project => &[],
Self::Tailwind => &[&("tailwindcss", ">=3.0.0")],
Self::Turborepo => &[&("turbo", ">=1.0.0")],
Self::Types => &[],
}
}

Expand All @@ -556,6 +560,7 @@ impl RuleDomain {
Self::Project => &[],
Self::Tailwind => &[],
Self::Turborepo => &[],
Self::Types => &[],
}
}

Expand All @@ -570,6 +575,7 @@ impl RuleDomain {
Self::Project => "project",
Self::Tailwind => "tailwind",
Self::Turborepo => "turborepo",
Self::Types => "types",
}
}
}
Expand All @@ -588,6 +594,7 @@ impl FromStr for RuleDomain {
"project" => Ok(Self::Project),
"tailwind" => Ok(Self::Tailwind),
"turborepo" => Ok(Self::Turborepo),
"types" => Ok(Self::Types),

_ => Err("Invalid rule domain"),
}
Expand Down
10 changes: 6 additions & 4 deletions crates/biome_cli/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ use biome_fs::{BiomePath, FileSystem};
use biome_resolver::FsWithResolverProxy;
use biome_service::configuration::{LoadedConfiguration, ProjectScanComputer, load_configuration};
use biome_service::projects::ProjectKey;
use biome_service::settings::ModuleGraphResolutionKind;
use biome_service::workspace::{
OpenProjectParams, ScanKind, ScanProjectParams, UpdateSettingsParams,
};
Expand Down Expand Up @@ -405,6 +406,10 @@ pub(crate) trait CommandRunner {
self.minimal_scan_kind(),
);

// Scan the project
let scan_kind =
execution.compute_scan_kind(paths.as_slice(), working_dir.as_path(), scan_kind);

// Update the settings of the project
let result = workspace.update_settings(UpdateSettingsParams {
project_key: open_project_result.project_key,
Expand All @@ -414,6 +419,7 @@ pub(crate) trait CommandRunner {
.into_iter()
.map(|(path, config)| (BiomePath::from(path), config))
.collect(),
module_graph_resolution_kind: ModuleGraphResolutionKind::from(&scan_kind),
})?;
if self.should_validate_configuration_diagnostics() {
print_diagnostics_from_workspace_result(
Expand All @@ -423,10 +429,6 @@ pub(crate) trait CommandRunner {
)?;
}

// Scan the project
let scan_kind =
execution.compute_scan_kind(paths.as_slice(), working_dir.as_path(), scan_kind);

let result = workspace.scan_project(ScanProjectParams {
project_key: open_project_result.project_key,
watch: cli_options.use_server,
Expand Down
22 changes: 14 additions & 8 deletions crates/biome_configuration/src/generated/domain_selector.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/biome_configuration/tests/invalid/domains.json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ domains.json:4:7 deserialize ━━━━━━━━━━━━━━━━━
- project
- tailwind
- turborepo
- types



Expand Down
1 change: 1 addition & 0 deletions crates/biome_css_formatter/tests/spec_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, _f
},
workspace_directory: None,
extended_configurations: vec![],
module_graph_resolution_kind: Default::default(),
})
};

Expand Down
1 change: 1 addition & 0 deletions crates/biome_graphql_formatter/tests/spec_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, _f
},
workspace_directory: None,
extended_configurations: vec![],
module_graph_resolution_kind: Default::default(),
})
};

Expand Down
1 change: 1 addition & 0 deletions crates/biome_html_formatter/tests/spec_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, _f
project_key,
workspace_directory: Some(BiomePath::new(test_directory)),
extended_configurations: vec![],
module_graph_resolution_kind: Default::default(),
})
}) else {
panic!("Failed to set up snapshot test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ declare_lint_rule! {
recommended: true,
sources: &[RuleSource::EslintTypeScript("no-floating-promises").same()],
fix_kind: FixKind::Unsafe,
domains: &[RuleDomain::Project],
domains: &[RuleDomain::Types],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ declare_lint_rule! {
recommended: true,
sources: &[RuleSource::EslintTypeScript("no-misused-promises").same()],
fix_kind: FixKind::Unsafe,
domains: &[RuleDomain::Project],
domains: &[RuleDomain::Types],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ declare_lint_rule! {
sources: &[RuleSource::EslintTypeScript("no-unnecessary-condition").inspired()],
recommended: false,
severity: Severity::Warning,
domains: &[RuleDomain::Project],
domains: &[RuleDomain::Types],
issue_number: Some("6611"),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare_lint_rule! {
language: "js",
recommended: false,
sources: &[RuleSource::EslintTypeScript("require-array-sort-compare").same()],
domains: &[RuleDomain::Project],
domains: &[RuleDomain::Types],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ declare_lint_rule! {
language: "js",
recommended: false,
sources: &[RuleSource::EslintTypeScript("use-await-thenable").inspired()],
domains: &[RuleDomain::Project],
domains: &[RuleDomain::Types],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ declare_lint_rule! {
recommended: true,
sources: &[RuleSource::EslintTypeScript("switch-exhaustiveness-check").same()],
fix_kind: FixKind::Unsafe,
domains: &[RuleDomain::Project],
domains: &[RuleDomain::Types],
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/lint/nursery/use_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ declare_lint_rule! {
language: "js",
recommended: false,
sources: &[RuleSource::EslintTypeScript("prefer-find").same()],
domains: &[RuleDomain::Project],
domains: &[RuleDomain::Types],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare_lint_rule! {
language: "js",
recommended: false,
sources: &[RuleSource::EslintTypeScript("prefer-regexp-exec").same(), RuleSource::EslintRegexp("prefer-regexp-exec").same()],
domains: &[RuleDomain::Project],
domains: &[RuleDomain::Types],
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/services/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl FromServices for ModuleGraphService {
.any(|d| d == &RuleDomain::Project);
if !has_project_domain {
panic!(
"The rule {rule_key} uses ModuleGraphService, but it is not in the project domain."
"The rule {rule_key} uses ModuleGraphService, but it is not in the Project domain."
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/services/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ impl FromServices for TypedService {
let has_project_domain = rule_metadata
.domains
.iter()
.any(|d| d == &RuleDomain::Project);
.any(|d| d == &RuleDomain::Types);
if !has_project_domain {
panic!(
"The rule {rule_key} uses TypedService, but it is not in the project domain."
"The rule {rule_key} uses TypedService, but it is not in the TypeAware domain."
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/biome_js_analyze/tests/spec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl RegistryVisitor<JsLanguage> for NeedsModuleGraph<'_> {
if self
.enabled_rules
.is_some_and(|enabled_rules| enabled_rules.contains(&filter))
&& R::METADATA.domains.contains(&RuleDomain::Project)
&& (R::METADATA.domains.contains(&RuleDomain::Project)
|| R::METADATA.domains.contains(&RuleDomain::Types))
{
self.needs_module_graph = true;
}
Expand Down
4 changes: 3 additions & 1 deletion crates/biome_lsp/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use biome_service::configuration::{
LoadedConfiguration, ProjectScanComputer, load_configuration, load_editorconfig,
};
use biome_service::projects::ProjectKey;
use biome_service::settings::ModuleGraphResolutionKind;
use biome_service::workspace::{
FeaturesBuilder, OpenProjectParams, OpenProjectResult, PullDiagnosticsParams,
SupportsFeatureParams,
Expand Down Expand Up @@ -741,7 +742,7 @@ impl Session {
spawn_blocking(move || {
let result = session.workspace.scan_project(ScanProjectParams {
project_key,
watch: scan_kind.is_project(),
watch: scan_kind.is_project() || scan_kind.is_type_aware(),
force,
scan_kind,
verbose: false,
Expand Down Expand Up @@ -960,6 +961,7 @@ impl Session {
.map(BiomePath::from),
configuration,
extended_configurations: Default::default(),
module_graph_resolution_kind: ModuleGraphResolutionKind::from(&scan_kind),
});

self.insert_and_scan_project(project_key, path.into(), scan_kind, force)
Expand Down
1 change: 1 addition & 0 deletions crates/biome_module_graph/benches/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fn bench_index_d_ts(bencher: Bencher, name: &str) {
&fs,
&ProjectLayout::default(),
&[(&path, root)],
true,
);
divan::black_box(&module_graph);
});
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_module_graph/src/js_module_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ pub struct JsModuleInfoInner {

/// Diagnostics emitted during the resolution of the module
pub(crate) diagnostics: Vec<ModuleDiagnostic>,

/// Whether type inference was enabled when this module info was created
pub(crate) infer_types: bool,
}

#[derive(Debug, Default)]
Expand Down
23 changes: 15 additions & 8 deletions crates/biome_module_graph/src/js_module_info/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ pub(super) struct JsModuleInfoCollector {

/// Diagnostics emitted during the collection of module graph information
diagnostics: Vec<JsModuleInfoDiagnostic>,

/// Whether to enable type inference when finalizing the module info
infer_types: bool,
}

/// Intermediary representation for an exported symbol.
Expand Down Expand Up @@ -556,14 +559,16 @@ impl JsModuleInfoCollector {
.collect(),
);

self.infer_all_types(&scope_by_range);
self.resolve_all_and_downgrade_project_references();
if self.infer_types {
self.infer_all_types(&scope_by_range);
self.resolve_all_and_downgrade_project_references();

// Purging before flattening will save us from duplicate work during
// flattening. We'll purge again after for a final cleanup.
self.purge_redundant_types();
self.flatten_all();
self.purge_redundant_types();
// Purging before flattening will save us from duplicate work during
// flattening. We'll purge again after for a final cleanup.
self.purge_redundant_types();
self.flatten_all();
self.purge_redundant_types();
}

let exports = self.collect_exports();

Expand Down Expand Up @@ -1114,7 +1119,8 @@ impl TypeResolver for JsModuleInfoCollector {
}

impl JsModuleInfo {
pub(super) fn new(mut collector: JsModuleInfoCollector) -> Self {
pub(super) fn new(mut collector: JsModuleInfoCollector, infer_types: bool) -> Self {
collector.infer_types = infer_types;
let (exports, scope_by_range) = collector.finalise();

Self(Arc::new(JsModuleInfoInner {
Expand All @@ -1129,6 +1135,7 @@ impl JsModuleInfo {
scope_by_range,
types: collector.types.into(),
diagnostics: collector.diagnostics.into_iter().map(Into::into).collect(),
infer_types: collector.infer_types,
}))
}
}
Expand Down
Loading