83 lines
2.3 KiB
Rust
83 lines
2.3 KiB
Rust
// Copyright (c) 2024 Marceline Cramer
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
//
|
|
// This file is part of Saul.
|
|
//
|
|
// Saul is free software: you can redistribute it and/or modify it under the
|
|
// terms of the GNU Affero General Public License as published by the Free
|
|
// Software Foundation, either version 3 of the License, or (at your option) any
|
|
// later version.
|
|
//
|
|
// Saul is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
// details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with Saul. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
use std::{fs::File, io::BufReader, path::PathBuf};
|
|
|
|
use clap::Parser;
|
|
use ignore::Walk;
|
|
|
|
mod log;
|
|
mod parse;
|
|
|
|
#[derive(Debug, Parser)]
|
|
struct Args {
|
|
/// A list of paths to validate.
|
|
pub input: Vec<PathBuf>,
|
|
}
|
|
|
|
fn main() {
|
|
let mut args = Args::parse();
|
|
log::init_lints();
|
|
|
|
if args.input.is_empty() {
|
|
args.input = vec![".".into()];
|
|
}
|
|
|
|
for input in args.input {
|
|
for result in Walk::new(&input) {
|
|
let entry = match result {
|
|
Ok(entry) => entry,
|
|
Err(err) => {
|
|
eprintln!("error: {}", err);
|
|
continue;
|
|
}
|
|
};
|
|
|
|
let Some(ft) = entry.file_type() else {
|
|
continue;
|
|
};
|
|
|
|
if !ft.is_file() {
|
|
continue;
|
|
}
|
|
|
|
let path = entry.path();
|
|
let filename = path.to_string_lossy().to_owned();
|
|
|
|
log::with_context(&filename, || {
|
|
let f = File::open(path).unwrap();
|
|
let mut read = BufReader::new(f);
|
|
|
|
let lines = match parse::Language::RUST.read_header(&mut read) {
|
|
Ok(lines) => lines,
|
|
Err(err) => {
|
|
log::log(&format!("error parsing {:?}: {:?}", path, err));
|
|
return;
|
|
}
|
|
};
|
|
|
|
let header = parse::Header::parse(lines).unwrap();
|
|
|
|
if header.spdx.is_none() {
|
|
log::lint("missing_spdx", "header is missing SPDX license identifier");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|