Skip to content

Commit 7f982a1

Browse files
authored
Only emit each warning once per source location (#1322)
1 parent 112aaa6 commit 7f982a1

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.33.1
2+
3+
* Don't emit the same warning in the same location multiple times.
4+
15
## 1.33.0
26

37
* Deprecate the use of `/` for division. The new `math.div()` function should be

lib/src/visitor/async_evaluate.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ class _EvaluateVisitor
148148
/// The logger to use to print warnings.
149149
final Logger _logger;
150150

151+
/// A set of message/location pairs for warnings that have been emitted via
152+
/// [_warn].
153+
///
154+
/// We only want to emit one warning per location, to avoid blowing up users'
155+
/// consoles with redundant warnings.
156+
final _warningsEmitted = <Tuple2<String, SourceSpan>>{};
157+
151158
/// Whether to track source map information.
152159
final bool _sourceMap;
153160

@@ -1936,7 +1943,7 @@ class _EvaluateVisitor
19361943
}
19371944

19381945
if (node.isGlobal && !_environment.globalVariableExists(node.name)) {
1939-
_logger.warn(
1946+
_warn(
19401947
_environment.atRoot
19411948
? "As of Dart Sass 2.0.0, !global assignments won't be able to\n"
19421949
"declare new variables. Since this assignment is at the root "
@@ -1946,8 +1953,7 @@ class _EvaluateVisitor
19461953
"declare new variables. Consider adding "
19471954
"`${node.originalName}: null` at the root of the\n"
19481955
"stylesheet.",
1949-
span: node.span,
1950-
trace: _stackTrace(node.span),
1956+
node.span,
19511957
deprecation: true);
19521958
}
19531959

@@ -3087,9 +3093,11 @@ class _EvaluateVisitor
30873093
}
30883094

30893095
/// Emits a warning with the given [message] about the given [span].
3090-
void _warn(String message, FileSpan span, {bool deprecation = false}) =>
3091-
_logger.warn(message,
3092-
span: span, trace: _stackTrace(span), deprecation: deprecation);
3096+
void _warn(String message, FileSpan span, {bool deprecation = false}) {
3097+
if (!_warningsEmitted.add(Tuple2(message, span))) return;
3098+
_logger.warn(message,
3099+
span: span, trace: _stackTrace(span), deprecation: deprecation);
3100+
}
30933101

30943102
/// Returns a [SassRuntimeException] with the given [message].
30953103
///

lib/src/visitor/evaluate.dart

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_evaluate.dart.
66
// See tool/grind/synchronize.dart for details.
77
//
8-
// Checksum: 1fc6b9e6018eba3ac520464abb56e686f4cb9886
8+
// Checksum: 7eb518e3fd9269a2117e8f4a4b4149ca05e3ec25
99
//
1010
// ignore_for_file: unused_import
1111

@@ -156,6 +156,13 @@ class _EvaluateVisitor
156156
/// The logger to use to print warnings.
157157
final Logger _logger;
158158

159+
/// A set of message/location pairs for warnings that have been emitted via
160+
/// [_warn].
161+
///
162+
/// We only want to emit one warning per location, to avoid blowing up users'
163+
/// consoles with redundant warnings.
164+
final _warningsEmitted = <Tuple2<String, SourceSpan>>{};
165+
159166
/// Whether to track source map information.
160167
final bool _sourceMap;
161168

@@ -1928,7 +1935,7 @@ class _EvaluateVisitor
19281935
}
19291936

19301937
if (node.isGlobal && !_environment.globalVariableExists(node.name)) {
1931-
_logger.warn(
1938+
_warn(
19321939
_environment.atRoot
19331940
? "As of Dart Sass 2.0.0, !global assignments won't be able to\n"
19341941
"declare new variables. Since this assignment is at the root "
@@ -1938,8 +1945,7 @@ class _EvaluateVisitor
19381945
"declare new variables. Consider adding "
19391946
"`${node.originalName}: null` at the root of the\n"
19401947
"stylesheet.",
1941-
span: node.span,
1942-
trace: _stackTrace(node.span),
1948+
node.span,
19431949
deprecation: true);
19441950
}
19451951

@@ -3058,9 +3064,11 @@ class _EvaluateVisitor
30583064
}
30593065

30603066
/// Emits a warning with the given [message] about the given [span].
3061-
void _warn(String message, FileSpan span, {bool deprecation = false}) =>
3062-
_logger.warn(message,
3063-
span: span, trace: _stackTrace(span), deprecation: deprecation);
3067+
void _warn(String message, FileSpan span, {bool deprecation = false}) {
3068+
if (!_warningsEmitted.add(Tuple2(message, span))) return;
3069+
_logger.warn(message,
3070+
span: span, trace: _stackTrace(span), deprecation: deprecation);
3071+
}
30643072

30653073
/// Returns a [SassRuntimeException] with the given [message].
30663074
///

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.33.0
2+
version: 1.33.1-dev
33
description: A Sass implementation in Dart.
44
author: Sass Team
55
homepage: https://github.com/sass/dart-sass

0 commit comments

Comments
 (0)