diff --git a/crates/biome_analyze/src/lib.rs b/crates/biome_analyze/src/lib.rs index 6602027a8aa2..071b25ced0c5 100644 --- a/crates/biome_analyze/src/lib.rs +++ b/crates/biome_analyze/src/lib.rs @@ -81,7 +81,7 @@ pub struct AnalyzerContext<'a, L: Language> { pub root: LanguageRoot, pub services: ServiceBag, pub range: Option, - pub options: &'a AnalyzerOptions, + pub options: &'a AnalyzerOptions<'a>, } impl<'analyzer, L, Matcher, Break, Diag> Analyzer<'analyzer, L, Matcher, Break, Diag> @@ -224,7 +224,7 @@ struct PhaseRunner<'analyzer, 'phase, L: Language, Matcher, Break, Diag> { /// Optional text range to restrict the analysis to range: Option, /// Analyzer options - options: &'phase AnalyzerOptions, + options: &'phase AnalyzerOptions<'phase>, } /// Single entry for a suppression comment in the `line_suppressions` buffer @@ -787,7 +787,7 @@ pub struct SuppressionCommentEmitterPayload<'a, L: Language> { /// The original range of the diagnostic where the rule was triggered pub diagnostic_text_range: &'a TextRange, /// Explanation for the suppression to be used with `--suppress` and `--reason` - pub suppression_reason: String, + pub suppression_reason: &'a str, } type SignalHandler<'a, L, Break> = &'a mut dyn FnMut(&dyn AnalyzerSignal) -> ControlFlow; diff --git a/crates/biome_analyze/src/matcher.rs b/crates/biome_analyze/src/matcher.rs index 375986298b5d..e7284270bc40 100644 --- a/crates/biome_analyze/src/matcher.rs +++ b/crates/biome_analyze/src/matcher.rs @@ -26,7 +26,7 @@ pub struct MatchQueryParams<'phase, 'query, L: Language> { pub services: &'phase ServiceBag, pub signal_queue: &'query mut BinaryHeap>, pub suppression_action: &'phase dyn SuppressionAction, - pub options: &'phase AnalyzerOptions, + pub options: &'phase AnalyzerOptions<'phase>, } /// Wrapper type for a [QueryMatch] diff --git a/crates/biome_analyze/src/options.rs b/crates/biome_analyze/src/options.rs index b8a6d3d11c19..ec0b6f4b37ef 100644 --- a/crates/biome_analyze/src/options.rs +++ b/crates/biome_analyze/src/options.rs @@ -71,7 +71,7 @@ pub struct AnalyzerConfiguration { /// A set of information useful to the analyzer infrastructure #[derive(Debug, Default)] -pub struct AnalyzerOptions { +pub struct AnalyzerOptions<'a> { /// A data structured derived from the [`biome.json`] file pub configuration: AnalyzerConfiguration, @@ -79,10 +79,10 @@ pub struct AnalyzerOptions { pub file_path: PathBuf, /// Suppression reason to be used with `--suppress` and `--reason` - pub suppression_reason: Option, + pub suppression_reason: Option<&'a str>, } -impl AnalyzerOptions { +impl<'a> AnalyzerOptions<'a> { pub fn globals(&self) -> Vec<&str> { self.configuration .globals diff --git a/crates/biome_analyze/src/rule.rs b/crates/biome_analyze/src/rule.rs index c5e0b024f1c7..3e87b45128f3 100644 --- a/crates/biome_analyze/src/rule.rs +++ b/crates/biome_analyze/src/rule.rs @@ -881,7 +881,7 @@ pub trait Rule: RuleMeta + Sized { ctx: &RuleContext, text_range: &TextRange, suppression_action: &dyn SuppressionAction>, - suppression_reason: Option, + suppression_reason: Option<&str>, ) -> Option>> where Self: 'static, @@ -902,7 +902,7 @@ pub trait Rule: RuleMeta + Sized { mutation: &mut mutation, token_offset: token, diagnostic_text_range: text_range, - suppression_reason: suppression_reason.unwrap_or("".to_string()), + suppression_reason: suppression_reason.unwrap_or(""), }); Some(SuppressAction { diff --git a/crates/biome_analyze/src/signals.rs b/crates/biome_analyze/src/signals.rs index e532db333172..d13b2f0638aa 100644 --- a/crates/biome_analyze/src/signals.rs +++ b/crates/biome_analyze/src/signals.rs @@ -311,9 +311,9 @@ pub(crate) struct RuleSignal<'phase, R: Rule> { /// An optional action to suppress the rule. suppression_action: &'phase dyn SuppressionAction>, /// An optional explanation for the suppression to be used with `--suppress` and `--reason` - suppression_reason: Option, + suppression_reason: Option<&'phase str>, /// A list of strings that are considered "globals" inside the analyzer - options: &'phase AnalyzerOptions, + options: &'phase AnalyzerOptions<'phase>, } impl<'phase, R> RuleSignal<'phase, R> @@ -328,7 +328,7 @@ where suppression_action: &'phase dyn SuppressionAction< Language = <::Query as Queryable>::Language, >, - suppression_reason: Option, + suppression_reason: Option<&'phase str>, options: &'phase AnalyzerOptions, ) -> Self { Self { @@ -409,7 +409,7 @@ where &ctx, &text_range, self.suppression_action, - self.suppression_reason.clone(), + self.suppression_reason, ) { let action = AnalyzerAction { rule_name: Some((::NAME, R::METADATA.name)), diff --git a/crates/biome_analyze/src/suppression_action.rs b/crates/biome_analyze/src/suppression_action.rs index 3f4629ddc518..77359a95f085 100644 --- a/crates/biome_analyze/src/suppression_action.rs +++ b/crates/biome_analyze/src/suppression_action.rs @@ -78,7 +78,7 @@ pub trait SuppressionAction { mutation: &mut BatchMutation, apply_suppression: ApplySuppression, suppression_text: &str, - suppression_reason: String, + suppression_reason: &str, ); } diff --git a/crates/biome_analyze/src/visitor.rs b/crates/biome_analyze/src/visitor.rs index 9abfc0821f47..f2acf84a3793 100644 --- a/crates/biome_analyze/src/visitor.rs +++ b/crates/biome_analyze/src/visitor.rs @@ -16,7 +16,7 @@ pub struct VisitorContext<'phase, 'query, L: Language> { pub range: Option, pub(crate) query_matcher: &'query mut dyn QueryMatcher, pub(crate) signal_queue: &'query mut BinaryHeap>, - pub options: &'phase AnalyzerOptions, + pub options: &'phase AnalyzerOptions<'phase>, } impl<'phase, 'query, L: Language> VisitorContext<'phase, 'query, L> { diff --git a/crates/biome_cli/src/execute/process_file/lint.rs b/crates/biome_cli/src/execute/process_file/lint.rs index 7e23729f6c3a..916ae8832839 100644 --- a/crates/biome_cli/src/execute/process_file/lint.rs +++ b/crates/biome_cli/src/execute/process_file/lint.rs @@ -15,7 +15,7 @@ pub(crate) fn lint<'ctx>( ctx: &'ctx SharedTraversalOptions<'ctx, '_>, path: &Path, suppress: bool, - suppression_reason: &Option, + suppression_reason: Option<&String>, ) -> FileResult { let mut workspace_file = WorkspaceFile::new(ctx, path)?; lint_with_guard( diff --git a/crates/biome_css_analyze/src/suppression_action.rs b/crates/biome_css_analyze/src/suppression_action.rs index 25f29e8ff5d6..40025ca101e7 100644 --- a/crates/biome_css_analyze/src/suppression_action.rs +++ b/crates/biome_css_analyze/src/suppression_action.rs @@ -41,7 +41,7 @@ impl SuppressionAction for CssSuppressionAction { mutation: &mut BatchMutation, apply_suppression: ApplySuppression, suppression_text: &str, - suppression_reason: String, + suppression_reason: &str, ) { let ApplySuppression { token_to_apply_suppression, diff --git a/crates/biome_graphql_analyze/src/suppression_action.rs b/crates/biome_graphql_analyze/src/suppression_action.rs index 08f997e6f5a2..bb6da195ec9d 100644 --- a/crates/biome_graphql_analyze/src/suppression_action.rs +++ b/crates/biome_graphql_analyze/src/suppression_action.rs @@ -39,7 +39,7 @@ impl SuppressionAction for GraphqlSuppressionAction { mutation: &mut BatchMutation, apply_suppression: ApplySuppression, suppression_text: &str, - suppression_reason: String, + suppression_reason: &str, ) { let ApplySuppression { token_to_apply_suppression, diff --git a/crates/biome_js_analyze/src/suppression_action.rs b/crates/biome_js_analyze/src/suppression_action.rs index 4cd8a996b7ca..43d21b9001c3 100644 --- a/crates/biome_js_analyze/src/suppression_action.rs +++ b/crates/biome_js_analyze/src/suppression_action.rs @@ -129,7 +129,7 @@ impl SuppressionAction for JsSuppressionAction { mutation: &mut BatchMutation, apply_suppression: ApplySuppression, suppression_text: &str, - suppression_reason: String, + suppression_reason: &str, ) { let ApplySuppression { token_to_apply_suppression, diff --git a/crates/biome_js_transform/src/lib.rs b/crates/biome_js_transform/src/lib.rs index 62b855f8d70c..f6a8255cf56b 100644 --- a/crates/biome_js_transform/src/lib.rs +++ b/crates/biome_js_transform/src/lib.rs @@ -66,7 +66,7 @@ where _: &mut BatchMutation, _: ApplySuppression, _: &str, - _: String, + _: &str, ) { unreachable!("") } diff --git a/crates/biome_json_analyze/src/suppression_action.rs b/crates/biome_json_analyze/src/suppression_action.rs index 70decf433c9d..9d28e9ee1f48 100644 --- a/crates/biome_json_analyze/src/suppression_action.rs +++ b/crates/biome_json_analyze/src/suppression_action.rs @@ -20,7 +20,7 @@ impl SuppressionAction for JsonSuppressionAction { _mutation: &mut BatchMutation, _apply_suppression: ApplySuppression, _suppression_text: &str, - _suppression_reason: String, + _suppression_reason: &str, ) { unreachable!("find_token_to_apply_suppression return None") } diff --git a/crates/biome_migrate/src/lib.rs b/crates/biome_migrate/src/lib.rs index 9e744a3f5062..08262ccbba92 100644 --- a/crates/biome_migrate/src/lib.rs +++ b/crates/biome_migrate/src/lib.rs @@ -74,7 +74,7 @@ where _: &mut BatchMutation, _: ApplySuppression, _: &str, - _: String, + _: &str, ) { unreachable!("") } diff --git a/crates/biome_service/src/file_handlers/css.rs b/crates/biome_service/src/file_handlers/css.rs index e76ce0c130fa..c71e634e7315 100644 --- a/crates/biome_service/src/file_handlers/css.rs +++ b/crates/biome_service/src/file_handlers/css.rs @@ -115,15 +115,15 @@ impl ServiceLanguage for CssLanguage { } } - fn resolve_analyzer_options( - global: Option<&Settings>, - _linter: Option<&LinterSettings>, - _overrides: Option<&OverrideSettings>, - _language: Option<&Self::LinterSettings>, - file_path: &BiomePath, - _file_source: &DocumentFileSource, - suppression_reason: Option, - ) -> AnalyzerOptions { + fn resolve_analyzer_options<'a>( + global: Option<&'a Settings>, + _linter: Option<&'a LinterSettings>, + _overrides: Option<&'a OverrideSettings>, + _language: Option<&'a Self::LinterSettings>, + file_path: &'a BiomePath, + _file_source: &'a DocumentFileSource, + suppression_reason: Option<&'a str>, + ) -> AnalyzerOptions<'a> { let preferred_quote = global .and_then(|global| { global diff --git a/crates/biome_service/src/file_handlers/graphql.rs b/crates/biome_service/src/file_handlers/graphql.rs index 147cfa916332..de548be5f8ad 100644 --- a/crates/biome_service/src/file_handlers/graphql.rs +++ b/crates/biome_service/src/file_handlers/graphql.rs @@ -134,15 +134,15 @@ impl ServiceLanguage for GraphqlLanguage { } } - fn resolve_analyzer_options( - _global: Option<&Settings>, - _linter: Option<&LinterSettings>, - _overrides: Option<&OverrideSettings>, - _language: Option<&Self::LinterSettings>, - path: &BiomePath, - _file_source: &DocumentFileSource, - suppression_reason: Option, - ) -> AnalyzerOptions { + fn resolve_analyzer_options<'a>( + _global: Option<&'a Settings>, + _linter: Option<&'a LinterSettings>, + _overrides: Option<&'a OverrideSettings>, + _language: Option<&'a Self::LinterSettings>, + path: &'a BiomePath, + _file_source: &'a DocumentFileSource, + suppression_reason: Option<&'a str>, + ) -> AnalyzerOptions<'a> { AnalyzerOptions { configuration: AnalyzerConfiguration::default(), file_path: path.to_path_buf(), diff --git a/crates/biome_service/src/file_handlers/grit.rs b/crates/biome_service/src/file_handlers/grit.rs index 95cd975926b7..aee452d1f1f5 100644 --- a/crates/biome_service/src/file_handlers/grit.rs +++ b/crates/biome_service/src/file_handlers/grit.rs @@ -88,15 +88,15 @@ impl ServiceLanguage for GritLanguage { } } - fn resolve_analyzer_options( - _global: Option<&crate::settings::Settings>, - _linter: Option<&crate::settings::LinterSettings>, - _overrides: Option<&crate::settings::OverrideSettings>, - _language: Option<&Self::LinterSettings>, - path: &biome_fs::BiomePath, - _file_source: &super::DocumentFileSource, - suppression_reason: Option, - ) -> biome_analyze::AnalyzerOptions { + fn resolve_analyzer_options<'a>( + _global: Option<&'a crate::settings::Settings>, + _linter: Option<&'a crate::settings::LinterSettings>, + _overrides: Option<&'a crate::settings::OverrideSettings>, + _language: Option<&'a Self::LinterSettings>, + path: &'a biome_fs::BiomePath, + _file_source: &'a super::DocumentFileSource, + suppression_reason: Option<&'a str>, + ) -> biome_analyze::AnalyzerOptions<'a> { AnalyzerOptions { configuration: AnalyzerConfiguration::default(), file_path: path.to_path_buf(), diff --git a/crates/biome_service/src/file_handlers/html.rs b/crates/biome_service/src/file_handlers/html.rs index 7eb19dde58ec..eacf7afc0ff3 100644 --- a/crates/biome_service/src/file_handlers/html.rs +++ b/crates/biome_service/src/file_handlers/html.rs @@ -91,15 +91,15 @@ impl ServiceLanguage for HtmlLanguage { } } - fn resolve_analyzer_options( - _global: Option<&crate::settings::Settings>, - _linter: Option<&crate::settings::LinterSettings>, - _overrides: Option<&crate::settings::OverrideSettings>, - _language: Option<&Self::LinterSettings>, - path: &biome_fs::BiomePath, - _file_source: &super::DocumentFileSource, - suppression_reason: Option, - ) -> AnalyzerOptions { + fn resolve_analyzer_options<'a>( + _global: Option<&'a crate::settings::Settings>, + _linter: Option<&'a crate::settings::LinterSettings>, + _overrides: Option<&'a crate::settings::OverrideSettings>, + _language: Option<&'a Self::LinterSettings>, + path: &'a biome_fs::BiomePath, + _file_source: &'a super::DocumentFileSource, + suppression_reason: Option<&'a str>, + ) -> AnalyzerOptions<'a> { AnalyzerOptions { configuration: AnalyzerConfiguration::default(), file_path: path.to_path_buf(), diff --git a/crates/biome_service/src/file_handlers/javascript.rs b/crates/biome_service/src/file_handlers/javascript.rs index ced5e392c16f..c4a7fe90262e 100644 --- a/crates/biome_service/src/file_handlers/javascript.rs +++ b/crates/biome_service/src/file_handlers/javascript.rs @@ -186,15 +186,15 @@ impl ServiceLanguage for JsLanguage { } } - fn resolve_analyzer_options( - global: Option<&Settings>, - _linter: Option<&LinterSettings>, - overrides: Option<&OverrideSettings>, - _language: Option<&Self::LinterSettings>, - path: &BiomePath, - _file_source: &DocumentFileSource, - suppression_reason: Option, - ) -> AnalyzerOptions { + fn resolve_analyzer_options<'a>( + global: Option<&'a Settings>, + _linter: Option<&'a LinterSettings>, + overrides: Option<&'a OverrideSettings>, + _language: Option<&'a Self::LinterSettings>, + path: &'a BiomePath, + _file_source: &'a DocumentFileSource, + suppression_reason: Option<&'a str>, + ) -> AnalyzerOptions<'a> { let preferred_quote = global .and_then(|global| { diff --git a/crates/biome_service/src/file_handlers/json.rs b/crates/biome_service/src/file_handlers/json.rs index 94fa7ce424c5..e94b12951cbd 100644 --- a/crates/biome_service/src/file_handlers/json.rs +++ b/crates/biome_service/src/file_handlers/json.rs @@ -125,15 +125,15 @@ impl ServiceLanguage for JsonLanguage { } } - fn resolve_analyzer_options( - global: Option<&Settings>, - _linter: Option<&LinterSettings>, - _overrides: Option<&OverrideSettings>, - _language: Option<&Self::LinterSettings>, - path: &BiomePath, - _file_source: &DocumentFileSource, - suppression_reason: Option, - ) -> AnalyzerOptions { + fn resolve_analyzer_options<'a>( + global: Option<&'a Settings>, + _linter: Option<&'a LinterSettings>, + _overrides: Option<&'a OverrideSettings>, + _language: Option<&'a Self::LinterSettings>, + path: &'a BiomePath, + _file_source: &'a DocumentFileSource, + suppression_reason: Option<&'a str>, + ) -> AnalyzerOptions<'a> { let configuration = AnalyzerConfiguration { rules: global .map(|g| to_analyzer_rules(g, path.as_path())) diff --git a/crates/biome_service/src/file_handlers/mod.rs b/crates/biome_service/src/file_handlers/mod.rs index a0d35b2c1597..574b08001db7 100644 --- a/crates/biome_service/src/file_handlers/mod.rs +++ b/crates/biome_service/src/file_handlers/mod.rs @@ -402,7 +402,7 @@ pub struct FixAllParams<'a> { pub(crate) only: Vec, pub(crate) skip: Vec, pub(crate) rule_categories: RuleCategories, - pub(crate) suppression_reason: Option, + pub(crate) suppression_reason: Option<&'a str>, } #[derive(Default)] @@ -460,7 +460,7 @@ pub(crate) struct LintParams<'a> { pub(crate) skip: Vec, pub(crate) categories: RuleCategories, pub(crate) manifest: Option, - pub(crate) suppression_reason: Option, + pub(crate) suppression_reason: Option<&'a str>, } pub(crate) struct LintResults { @@ -478,7 +478,7 @@ pub(crate) struct CodeActionsParams<'a> { pub(crate) language: DocumentFileSource, pub(crate) only: Vec, pub(crate) skip: Vec, - pub(crate) suppression_reason: Option, + pub(crate) suppression_reason: Option<&'a str>, } type Lint = fn(LintParams) -> LintResults; diff --git a/crates/biome_service/src/settings.rs b/crates/biome_service/src/settings.rs index 58096748d5e6..66f074d8accd 100644 --- a/crates/biome_service/src/settings.rs +++ b/crates/biome_service/src/settings.rs @@ -702,15 +702,15 @@ pub trait ServiceLanguage: biome_rowan::Language { /// Resolve the linter options from the global (workspace level), /// per-language and editor provided formatter settings - fn resolve_analyzer_options( - global: Option<&Settings>, - linter: Option<&LinterSettings>, - overrides: Option<&OverrideSettings>, - language: Option<&Self::LinterSettings>, - path: &BiomePath, - file_source: &DocumentFileSource, - suppression_reason: Option, - ) -> AnalyzerOptions; + fn resolve_analyzer_options<'a>( + global: Option<&'a Settings>, + linter: Option<&'a LinterSettings>, + overrides: Option<&'a OverrideSettings>, + language: Option<&'a Self::LinterSettings>, + path: &'a BiomePath, + file_source: &'a DocumentFileSource, + suppression_reason: Option<&'a str>, + ) -> AnalyzerOptions<'a>; } #[derive(Debug, Default)] @@ -845,14 +845,14 @@ impl<'a> WorkspaceSettingsHandle<'a> { L::resolve_format_options(formatter, overrides, editor_settings, path, file_source) } - pub(crate) fn analyzer_options( - &self, - path: &BiomePath, - file_source: &DocumentFileSource, - suppression_reason: Option, - ) -> AnalyzerOptions + pub(crate) fn analyzer_options<'b, L>( + &'b self, + path: &'b BiomePath, + file_source: &'b DocumentFileSource, + suppression_reason: Option<&'b str>, + ) -> AnalyzerOptions<'b> where - L: ServiceLanguage, + L: ServiceLanguage + 'b, { let settings = self.inner.get_current_settings(); let linter = settings.map(|s| &s.linter); diff --git a/crates/biome_service/src/workspace.rs b/crates/biome_service/src/workspace.rs index 075eabce639e..66867863dd29 100644 --- a/crates/biome_service/src/workspace.rs +++ b/crates/biome_service/src/workspace.rs @@ -672,14 +672,14 @@ pub enum FixFileMode { #[derive(Debug, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -pub struct FixFileParams { +pub struct FixFileParams<'a> { pub path: BiomePath, pub fix_file_mode: FixFileMode, pub should_format: bool, pub only: Vec, pub skip: Vec, pub rule_categories: RuleCategories, - pub suppression_reason: Option, + pub suppression_reason: Option<&'a str>, } #[derive(Debug, serde::Serialize, serde::Deserialize)] @@ -1107,7 +1107,7 @@ impl<'app, W: Workspace + ?Sized> FileGuard<'app, W> { rule_categories: RuleCategories, only: Vec, skip: Vec, - suppression_reason: Option, + suppression_reason: Option<&str>, ) -> Result { self.workspace.fix_file(FixFileParams { path: self.path.clone(), diff --git a/crates/biome_test_utils/src/lib.rs b/crates/biome_test_utils/src/lib.rs index 6191e2eccc95..e18a601c0c5f 100644 --- a/crates/biome_test_utils/src/lib.rs +++ b/crates/biome_test_utils/src/lib.rs @@ -27,10 +27,10 @@ pub fn scripts_from_json(extension: &OsStr, input_code: &str) -> Option, -) -> AnalyzerOptions { +pub fn create_analyzer_options<'a>( + input_file: &'a Path, + diagnostics: &'a mut Vec, +) -> AnalyzerOptions<'a> { let options = AnalyzerOptions { file_path: input_file.to_path_buf(), ..Default::default()