(&self, config: GlobalConfig)
| 89 | |
| 90 | impl Check { |
| 91 | pub fn run(&self, config: GlobalConfig) -> CliResult { |
| 92 | let Self { sheet, input, fix, deny_warnings, format } = self; |
| 93 | |
| 94 | if *fix { |
| 95 | todo!() |
| 96 | } |
| 97 | |
| 98 | if input.is_empty() { |
| 99 | hint_no_input(sheet, &config); |
| 100 | return Err(CliError::ParseFailed); |
| 101 | } |
| 102 | |
| 103 | let bump = Bump::new(); |
| 104 | |
| 105 | // Read and parse the csskit sheet |
| 106 | let rule_source = fs::read_to_string(sheet)?; |
| 107 | let rule_lexer = Lexer::new(CsskitAtomSet::get_dyn_set(), &rule_source); |
| 108 | let mut rule_parser = Parser::new(&bump, &rule_source, rule_lexer); |
| 109 | let rule_result = rule_parser.parse_entirely::<Sheet>(); |
| 110 | let parsed_rules = rule_result.output.ok_or_else(|| { |
| 111 | if let Some(e) = rule_result.errors.first() { |
| 112 | eprintln!("{}", format_diagnostic_error(e, &rule_source, sheet)); |
| 113 | } |
| 114 | hint_bad_sheet(sheet, input, &config); |
| 115 | CliError::ParseFailed |
| 116 | })?; |
| 117 | |
| 118 | let mut aggregated_stats: HashMap<_, (StatType, usize)> = HashMap::new(); |
| 119 | let mut error_count = 0; |
| 120 | let mut file_envelopes: Vec<CheckFileEnvelope> = Vec::new(); |
| 121 | |
| 122 | for css_file_path in input.iter() { |
| 123 | let css_source = match fs::read_to_string(css_file_path) { |
| 124 | Ok(s) => s, |
| 125 | Err(e) => { |
| 126 | match format { |
| 127 | OutputFormat::Json => { |
| 128 | file_envelopes.push(CheckFileEnvelope { |
| 129 | file: css_file_path.clone(), |
| 130 | ok: false, |
| 131 | error: Some(ErrorRecord { kind: ErrorKind::Io, message: e.to_string() }), |
| 132 | diagnostics: Vec::new(), |
| 133 | stats: Vec::new(), |
| 134 | }); |
| 135 | } |
| 136 | OutputFormat::Text => eprintln!("{css_file_path}: {e}"), |
| 137 | } |
| 138 | error_count += 1; |
| 139 | continue; |
| 140 | } |
| 141 | }; |
| 142 | |
| 143 | let css_lexer = Lexer::new(&CssAtomSet::ATOMS, &css_source); |
| 144 | let mut css_parser = Parser::new(&bump, &css_source, css_lexer); |
| 145 | let css_result = css_parser.parse_entirely(); |
| 146 | |
| 147 | let stylesheet = match css_result.output { |
| 148 | Some(s) => s, |
nothing calls this directly
no test coverage detected