From b63697548da4cef13c00f7b5069d8b4f7de93f1e Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Sun, 19 May 2024 03:54:54 +0000 Subject: [PATCH] minor api changes --- crates/compiler/src/evaluate/visitor.rs | 2 +- crates/compiler/src/logger.rs | 18 ++++++++------- crates/compiler/src/options.rs | 29 ++++++++++--------------- crates/lib/tests/macros.rs | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/crates/compiler/src/evaluate/visitor.rs b/crates/compiler/src/evaluate/visitor.rs index 248778d..e95ce20 100644 --- a/crates/compiler/src/evaluate/visitor.rs +++ b/crates/compiler/src/evaluate/visitor.rs @@ -1578,7 +1578,7 @@ impl<'a> Visitor<'a> { return; } let loc = self.map.look_up_span(span); - self.options.logger.warning(loc, message); + self.options.logger.warn(loc, message); } fn visit_warn_rule(&mut self, warn_rule: AstWarn) -> SassResult<()> { diff --git a/crates/compiler/src/logger.rs b/crates/compiler/src/logger.rs index e31109a..be3713a 100644 --- a/crates/compiler/src/logger.rs +++ b/crates/compiler/src/logger.rs @@ -1,16 +1,18 @@ use codemap::SpanLoc; use std::fmt::Debug; -/// Sink for log messages +/// A trait to allow replacing logging mechanisms pub trait Logger: Debug { - /// Logs message from a `@debug` statement + /// Logs message from a [`@debug`](https://sass-lang.com/documentation/at-rules/debug/) + /// statement fn debug(&self, location: SpanLoc, message: &str); - /// Logs message from a `@warn` statement - fn warning(&self, location: SpanLoc, message: &str); + /// Logs message from a [`@warn`](https://sass-lang.com/documentation/at-rules/warn/) + /// statement + fn warn(&self, location: SpanLoc, message: &str); } -/// Logs events to standard error +/// Logs events to standard error, through [`eprintln!`] #[derive(Debug)] pub struct StdLogger; @@ -26,7 +28,7 @@ impl Logger for StdLogger { } #[inline] - fn warning(&self, location: SpanLoc, message: &str) { + fn warn(&self, location: SpanLoc, message: &str) { eprintln!( "Warning: {}\n ./{}:{}:{}", message, @@ -37,7 +39,7 @@ impl Logger for StdLogger { } } -/// Discards all log events +/// Discards all logs #[derive(Debug)] pub struct NullLogger; @@ -46,5 +48,5 @@ impl Logger for NullLogger { fn debug(&self, _location: SpanLoc, _message: &str) {} #[inline] - fn warning(&self, _location: SpanLoc, _message: &str) {} + fn warn(&self, _location: SpanLoc, _message: &str) {} } diff --git a/crates/compiler/src/options.rs b/crates/compiler/src/options.rs index 44e896f..71bae8a 100644 --- a/crates/compiler/src/options.rs +++ b/crates/compiler/src/options.rs @@ -17,7 +17,6 @@ pub struct Options<'a> { pub(crate) load_paths: Vec, pub(crate) allows_charset: bool, pub(crate) unicode_error_messages: bool, - // TODO: remove in favor of NullLogger pub(crate) quiet: bool, pub(crate) input_syntax: Option, pub(crate) custom_fns: HashMap, @@ -76,32 +75,28 @@ impl<'a> Options<'a> { self } - /// This flag tells Sass not to emit any warnings - /// when compiling. By default, Sass emits warnings - /// when deprecated features are used or when the - /// `@warn` rule is encountered. It also silences the - /// `@debug` rule. Setting this option to `true` will - /// stop all events from reaching the assigned [`logger`]. + /// This flag tells Sass not to emit any warnings when compiling. By default, + /// Sass emits warnings when deprecated features are used or when the `@warn` + /// rule is encountered. It also silences the `@debug` rule. + /// + /// Setting this option to `true` will stop all logs from reaching the [`crate::Logger`]. /// /// By default, this value is `false` and warnings are emitted. #[must_use] - #[deprecated = "use `logger(&NullLogger)` instead"] #[inline] pub const fn quiet(mut self, quiet: bool) -> Self { self.quiet = quiet; self } - /// All Sass implementations allow users to provide - /// load paths: paths on the filesystem that Sass - /// will look in when locating modules. For example, - /// if you pass `node_modules/susy/sass` as a load path, - /// you can use `@import "susy"` to load `node_modules/susy/sass/susy.scss`. + /// All Sass implementations allow users to provide load paths: paths on the + /// filesystem that Sass will look in when locating modules. For example, if + /// you pass `node_modules/susy/sass` as a load path, you can use + /// `@import "susy"` to load `node_modules/susy/sass/susy.scss`. /// - /// Imports will always be resolved relative to the current - /// file first, though. Load paths will only be used if no - /// relative file exists that matches the module's URL. This - /// ensures that you can't accidentally mess up your relative + /// Imports will always be resolved relative to the current file first, though. + /// Load paths will only be used if no relative file exists that matches the + /// module's URL. This ensures that you can't accidentally mess up your relative /// imports when you add a new library. /// /// This method will append a single path to the list. diff --git a/crates/lib/tests/macros.rs b/crates/lib/tests/macros.rs index 7d77690..e7d1bca 100644 --- a/crates/lib/tests/macros.rs +++ b/crates/lib/tests/macros.rs @@ -189,7 +189,7 @@ impl Logger for TestLogger { self.0.borrow_mut().debug_messages.push(message.into()); } - fn warning(&self, _location: SpanLoc, message: &str) { + fn warn(&self, _location: SpanLoc, message: &str) { self.0.borrow_mut().warning_messages.push(message.into()); } }