#[cfg(target_arch = "wasm32")]
#[macro_use]
mod redefine;
mod lines;
mod lint;
mod report;
use std::ops;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Point {
pub row: usize,
pub col: usize,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Range {
pub bytes: ops::Range<usize>,
pub start_point: Point,
pub end_point: Point,
}
pub use crate::lint::Lint;
pub use crate::lint::LintMatch;
pub use crate::lint::builtin_lints;
pub use crate::lint::lint;
pub use crate::lint::lint_custom;
pub use crate::report::Opts;
pub use crate::report::report_terminal;
pub use crate::report::report_terminal_opts;
#[cfg(target_arch = "wasm32")]
mod wasm {
use std::io::Write as _;
use std::path::PathBuf;
use anyhow::Context as _;
use anyhow::Error;
use wasm_bindgen::prelude::wasm_bindgen;
use super::*;
#[wasm_bindgen]
pub fn lint_html(code: Vec<u8>, path: String, context: u8) -> Result<String, String> {
fn lint_impl(code: Vec<u8>, path: PathBuf, context: u8) -> Result<String, Error> {
let opts = Opts {
extra_lines: (context, context),
..Default::default()
};
let mut first = true;
let mut report = Vec::new();
let matches = lint(&code)?;
for m in matches {
if !first {
writeln!(&mut report)?;
} else {
first = false;
}
let () = report_terminal_opts(&m, &code, &path, &opts, &mut report)?;
}
let report =
String::from_utf8(report).context("generated report contains invalid UTF-8")?;
Ok(report)
}
lint_impl(code, PathBuf::from(path), context).map_err(|err| format!("{err:?}"))
}
}