swc_css_lints/rules/
no_empty_source.rs

1use swc_css_ast::*;
2use swc_css_visit::{Visit, VisitWith};
3
4use crate::rule::{visitor_rule, LintRule, LintRuleContext};
5
6pub fn no_empty_source(ctx: LintRuleContext<()>) -> Box<dyn LintRule> {
7    visitor_rule(ctx.reaction(), NoEmptySource { ctx })
8}
9
10const MESSAGE: &str = "Unexpected empty source.";
11
12#[derive(Debug, Default)]
13struct NoEmptySource {
14    ctx: LintRuleContext<()>,
15}
16
17impl Visit for NoEmptySource {
18    fn visit_stylesheet(&mut self, stylesheet: &Stylesheet) {
19        // TODO: we should allow comments here,
20        // but parser doesn't handle comments currently.
21        if stylesheet.rules.is_empty() {
22            self.ctx.report(stylesheet, MESSAGE);
23        }
24
25        stylesheet.visit_children_with(self);
26    }
27}