Skip to content

Commit

Permalink
Fix CSS variable name + test to prevent failures. (#8120)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Oct 7, 2024
1 parent e74ee03 commit be26349
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/web_css/lib/src/_site_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
bottom: 0;
left: 0;
width: 80%;
background: var(pub-site_header_popup-background-color);
background: var(--pub-site_header_popup-background-color);
transform: translateX(-100%);
transition: transform 0.3s ease;
z-index: $z-index-nav-mask + 1;
Expand Down
23 changes: 23 additions & 0 deletions pkg/web_css/test/variables_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,28 @@ void main() {

expect(unused, isEmpty);
});

test('all variables used have definition', () async {
final files = await Directory('lib')
.list(recursive: true)
.where((f) => f is File && f.path.endsWith('.scss'))
.cast<File>()
.toList();
final varRegExp = RegExp(r'var\((.*?)\)');
for (final file in files) {
final content = await file.readAsString();
for (final m in varRegExp.allMatches(content)) {
final name = m.group(1)!.trim();
if (!variables.contains(name)) {
// exempt Material Design variables
if (name.startsWith('--mdc-')) {
continue;
}

fail('${file.path} references `$name` without definition.');
}
}
}
});
});
}

0 comments on commit be26349

Please sign in to comment.