Skip to content

Commit 7be4b6b

Browse files
added minify output
1 parent c1a8d0c commit 7be4b6b

File tree

3 files changed

+68
-31
lines changed

3 files changed

+68
-31
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode
22
target
33
Cargo.lock
4-
npm-package/src/bin
4+
npm-package/src/bin
5+
vscode-ext

src/main.rs

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ fn main() -> Result<()> {
6060
process::exit(1);
6161
});
6262

63+
let minify_output = args.get(2);
64+
6365
if let Err(e) = env::set_current_dir(Path::new(path)) {
6466
eprintln!(
6567
"\n{}Error{}: Failed to set current directory: {}",
@@ -109,6 +111,7 @@ fn main() -> Result<()> {
109111

110112
let mut files_count = 0;
111113
let mut errors_count = 0;
114+
let minify = minify_output.map_or("", |v| v) == "--minify";
112115

113116
for (css_file, mut classes_tsx) in defined_classnames.clone() {
114117
if let Some(used_css) = used_classnames.get(&css_file) {
@@ -124,20 +127,36 @@ fn main() -> Result<()> {
124127
files_count += 1;
125128
errors_count += classes_tsx.len();
126129

127-
println!("{}{}{}", COLOR_BLUE, css_file, COLOR_RESET);
130+
if !minify {
131+
println!("{}{}{}", COLOR_BLUE, css_file, COLOR_RESET);
132+
}
133+
128134
for extra in classes_tsx {
129-
println!(
130-
"{}{}:{} {}Warn{}: Unused class `{}` found",
131-
COLOR_YELLOW,
132-
extra.line_index + 1,
133-
extra.column_index + 1,
134-
COLOR_YELLOW,
135-
COLOR_RESET,
136-
extra.class_name
137-
);
135+
if !minify {
136+
println!(
137+
"{}{}:{} {}Warn{}: Unused class `{}` found",
138+
COLOR_YELLOW,
139+
extra.line_index + 1,
140+
extra.column_index + 1,
141+
COLOR_YELLOW,
142+
COLOR_RESET,
143+
extra.class_name
144+
);
145+
} else {
146+
println!(
147+
"{}:{}:{}:{}:Unused class `{}` found",
148+
css_file,
149+
extra.line_index + 1,
150+
extra.column_index + 1,
151+
extra.class_name.len(),
152+
extra.class_name
153+
);
154+
}
138155
}
139156

140-
println!();
157+
if !minify {
158+
println!();
159+
}
141160
}
142161

143162
let mut undefined_classes: HashMap<String, HashSet<UsedClassName>> = HashMap::new();
@@ -165,29 +184,46 @@ fn main() -> Result<()> {
165184
}
166185

167186
for undefined in undefined_classes {
168-
println!("{}{}{}", COLOR_BLUE, undefined.0, COLOR_RESET);
187+
if !minify {
188+
println!("{}{}{}", COLOR_BLUE, undefined.0, COLOR_RESET);
189+
}
169190
for extra in undefined.1 {
170-
println!(
171-
"{}{}:{} {}Warn{}: Undefined class `{}` used",
172-
COLOR_YELLOW,
173-
extra.line,
174-
extra.column + 1,
175-
COLOR_YELLOW,
176-
COLOR_RESET,
177-
extra.class_name
178-
);
191+
if !minify {
192+
println!(
193+
"{}{}:{} {}Warn{}: Undefined class `{}` used",
194+
COLOR_YELLOW,
195+
extra.line,
196+
extra.column + 1,
197+
COLOR_YELLOW,
198+
COLOR_RESET,
199+
extra.class_name
200+
);
201+
} else {
202+
println!(
203+
"{}:{}:{}:{}:Undefined class `{}` used",
204+
undefined.0,
205+
extra.line,
206+
extra.column + 1,
207+
extra.class_name.len(),
208+
extra.class_name
209+
);
210+
}
179211
}
180212

181-
println!();
213+
if !minify {
214+
println!();
215+
}
182216
}
183217

184-
if errors_count == 0 {
185-
println!("{}✔{} No CSS lint warnings found", COLOR_GREEN, COLOR_RESET);
186-
} else {
187-
println!(
188-
"Found {}{} warnings{} in {} files",
189-
COLOR_YELLOW, errors_count, COLOR_RESET, files_count
190-
);
218+
if !minify {
219+
if errors_count == 0 {
220+
println!("{}✔{} No CSS lint warnings found", COLOR_GREEN, COLOR_RESET);
221+
} else {
222+
println!(
223+
"Found {}{} warnings{} in {} files",
224+
COLOR_YELLOW, errors_count, COLOR_RESET, files_count
225+
);
226+
}
191227
}
192228

193229
Ok(())

src/tsx_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Visit for PropertyFinder {
4646
class_name: prop.sym.to_string(),
4747
file_name: self.file_name.clone(),
4848
line: loc.line,
49-
column: loc.col.0,
49+
column: self.variable_name.len() + loc.col.0,
5050
});
5151
}
5252
}

0 commit comments

Comments
 (0)