Skip to content

Commit 2995b9c

Browse files
fix: Fixed css parsing case
1 parent 335a37e commit 2995b9c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "css-linter"
3-
version = "1.9.2"
3+
version = "1.9.3"
44
edition = "2021"
55

66
[dependencies]

src/parsers/css_parser.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@ fn is_first_char_numeric(buffer: &str) -> bool {
88
buffer.chars().next().map_or(false, |c| c.is_numeric())
99
}
1010

11+
fn contains_forbidden_characters(string: &str) -> bool {
12+
string
13+
.chars()
14+
.filter(|char| ['\'', '"', '=', '(', '['].contains(char))
15+
.collect::<Vec<char>>()
16+
.len()
17+
!= 0
18+
}
19+
1120
#[derive(Eq, Hash, PartialEq, Clone)]
1221
pub struct ClassName {
1322
pub class_name: String,
1423
pub line_index: usize,
1524
pub column_index: usize,
1625
}
1726

27+
// TODO: Do normal CSS parser
1828
pub fn extract_classes(css_content: &str) -> HashSet<ClassName> {
1929
let mut defined_classes: HashSet<ClassName> = HashSet::new();
2030
const DISABLE_RULE_FLAG: &str = "css-lint-disable-rule ";
@@ -41,12 +51,12 @@ pub fn extract_classes(css_content: &str) -> HashSet<ClassName> {
4151
continue;
4252
}
4353

44-
if !stripped_line.starts_with('.') {
54+
if !stripped_line.contains('.') || contains_forbidden_characters(stripped_line) {
4555
continue;
4656
}
4757

4858
let mut buffer: String = String::new();
49-
let mut is_class = true;
59+
let mut is_class = false;
5060
let mut start_index = 0;
5161
for (column_index, symbol) in stripped_line.chars().enumerate() {
5262
match symbol {

0 commit comments

Comments
 (0)