Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support files.include from .denolint.json #645

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions packages/deno-lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::env;
use std::fs;
use std::path;
use std::path::Path;
use std::path::PathBuf;
use std::str;

use deno_ast::MediaType;
Expand All @@ -32,6 +33,29 @@ fn get_media_type(p: &Path) -> MediaType {
}
}

fn make_absolute(p: &String, cwd: &Path) -> PathBuf {
let path = Path::new(p);
if path.is_absolute() {
return PathBuf::from(path);
}
let mut buf = cwd.to_path_buf();
buf.push(path);
match fs::canonicalize(buf) {
Ok(p) => {
// workaround for UNC path see https://github.com/rust-lang/rust/issues/42869
if p.starts_with(r"\\?\") {
match p.to_str() {
Some(s) => PathBuf::from(&s[4..]),
None => p,
}
} else {
p
}
}
Err(_) => PathBuf::from(p),
}
}

#[napi]
fn lint(
file_name: String,
Expand Down Expand Up @@ -85,11 +109,11 @@ fn denolint(__dirname: String, config_path: String) -> Result<bool> {
.map(|m| m.is_file())
.unwrap_or(false);

let (rules, cfg_ignore_files) = if config_existed {
let (rules, cfg_ignore_files, cfg_add_files) = if config_existed {
let cfg = config::load_from_json(path::Path::new(&config_path))?;
(cfg.get_rules(), cfg.files.exclude)
(cfg.get_rules(), cfg.files.exclude, cfg.files.include)
} else {
(get_recommended_rules(), vec![])
(get_recommended_rules(), vec![], vec![])
};

let mut eslint_ignore_file = cwd.clone();
Expand Down Expand Up @@ -133,11 +157,19 @@ fn denolint(__dirname: String, config_path: String) -> Result<bool> {
Err(_) => __dirname.as_str(),
},
};
let mut dir_walker = WalkBuilder::new(cwd);
let dir = if !cfg_add_files.is_empty() {
make_absolute(&cfg_add_files[0], &cwd)
} else {
cwd.clone()
};
let mut dir_walker = WalkBuilder::new(dir);
dir_walker
.add_custom_ignore_filename(ignore_file_path)
.types(types)
.follow_links(true);
for i in cfg_add_files.iter().skip(1) {
dir_walker.add(&make_absolute(i, &cwd));
}
for i in cfg_ignore_files {
dir_walker.add_ignore(i);
}
Expand Down