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

Add exclude option in selene.toml #425

Merged
merged 5 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased](https://github.com/Kampfkarren/selene/compare/0.21.0...HEAD)

### Added
- Added exclude option to selene.toml for excluding files from lints

## [0.21.1](https://github.com/Kampfkarren/selene/releases/tag/0.21.0) - 2022-09-19
### Fixed
- Fixed not being able to use projects without selene.toml.
Expand Down
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions docs/src/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ For example, if we had `game.toml` and `engine.toml` standard libraries, we coul
```toml
std = "game+engine"
```

### Excluding files from being linted
It is possible to exclude files from being linted using the exclude option:

```toml
exclude = ["external/*", "*.spec.lua"]
```
3 changes: 3 additions & 0 deletions selene-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct CheckerConfig<V> {
pub config: HashMap<String, V>,
pub rules: HashMap<String, RuleVariation>,
pub std: Option<String>,
pub exclude: Vec<String>,

// Not locked behind Roblox feature so that selene.toml for Roblox will
// run even without it.
Expand All @@ -83,6 +84,8 @@ impl<V> Default for CheckerConfig<V> {
config: HashMap::new(),
rules: HashMap::new(),
std: None,
exclude: Vec::new(),

roblox_std_source: RobloxStdSource::default(),
}
}
Expand Down
1 change: 1 addition & 0 deletions selene/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ color-eyre = "0.6.1"
dirs = "4.0.0"
full_moon = "0.15.1"
glob = "0.3"
globset = "0.4.9"
Kampfkarren marked this conversation as resolved.
Show resolved Hide resolved
lazy_static = "1.4"
num_cpus = "1.10"
profiling = { version = "1.0.6" }
Expand Down
23 changes: 23 additions & 0 deletions selene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,25 @@ fn start(mut matches: opts::Options) {
}
};

let mut builder = globset::GlobSetBuilder::new();
for pattern in &config.exclude {
builder.add(match globset::Glob::new(pattern) {
Ok(glob) => glob,
Err(error) => {
error!("Invalid glob pattern: {error}");
return;
}
});
}

let exclude_set = match builder.build() {
Ok(globset) => globset,
Err(error) => {
error!("{error}");
return;
}
};

let checker = Arc::new(match Checker::new(config, standard_library) {
Ok(checker) => checker,
Err(error) => {
Expand Down Expand Up @@ -510,6 +529,10 @@ fn start(mut matches: opts::Options) {
for entry in glob {
match entry {
Ok(path) => {
if exclude_set.is_match(&path) {
continue;
}
captalbator marked this conversation as resolved.
Show resolved Hide resolved

let checker = Arc::clone(&checker);

pool.execute(move || read_file(&checker, &path));
Expand Down