Skip to content

Commit

Permalink
minor api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
connorskees committed May 19, 2024
1 parent de68f3f commit b636975
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion crates/compiler/src/evaluate/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
18 changes: 10 additions & 8 deletions crates/compiler/src/logger.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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,
Expand All @@ -37,7 +39,7 @@ impl Logger for StdLogger {
}
}

/// Discards all log events
/// Discards all logs
#[derive(Debug)]
pub struct NullLogger;

Expand All @@ -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) {}
}
29 changes: 12 additions & 17 deletions crates/compiler/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct Options<'a> {
pub(crate) load_paths: Vec<PathBuf>,
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<InputSyntax>,
pub(crate) custom_fns: HashMap<String, Builtin>,
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit b636975

Please sign in to comment.