Fix: Exclude not working with absolute path in some cases (#593)#618
Fix: Exclude not working with absolute path in some cases (#593)#618dqkqd wants to merge 1 commit intoKampfkarren:mainfrom
Conversation
4293812 to
f606559
Compare
chriscerie
left a comment
There was a problem hiding this comment.
Thanks! Need changelogs for:
- the fix
- changing undocumented behavior that exclude paths are now relative to the config file instead of where selene is invoked
We should also properly document that in https://kampfkarren.github.io/selene/usage/configuration.html#excluding-files-from-being-linted
selene/src/main.rs
Outdated
| Path::new(&config_file).parent().map(Path::to_path_buf), | ||
| ), | ||
| Ok(config) => { | ||
| // Get config directory to using absolute path. |
There was a problem hiding this comment.
| // Get config directory to using absolute path. |
selene/src/main.rs
Outdated
| // There is case where `config = Some("selene.toml")`, | ||
| // which returns `""`` when getting parent directory. |
selene/src/main.rs
Outdated
| let config_directory = Path::new(&config_file) | ||
| .canonicalize() | ||
| .ok() | ||
| .and_then(|path| path.parent().map(|path| path.to_path_buf())); |
There was a problem hiding this comment.
| .and_then(|path| path.parent().map(|path| path.to_path_buf())); | |
| .and_then(|path| path.parent().map(Path::to_path_buf)); | |
selene/src/main.rs
Outdated
|
|
||
| let (config, config_directory): (CheckerConfig<toml::value::Value>, Option<PathBuf>) = | ||
| match options.config { | ||
| // User provides a config file. We must read it and report if it is misconfigured. |
There was a problem hiding this comment.
| // User provides a config file. We must read it and report if it is misconfigured. |
selene/src/main.rs
Outdated
| // Directory for matching files pattern. | ||
| // If user provides a config file, we use that as our working directory, otherwise fallback to the current directory. |
There was a problem hiding this comment.
| // Directory for matching files pattern. | |
| // If user provides a config file, we use that as our working directory, otherwise fallback to the current directory. |
selene/src/main.rs
Outdated
|
|
||
| // Directory for matching files pattern. | ||
| // If user provides a config file, we use that as our working directory, otherwise fallback to the current directory. | ||
| // The working directory needs to be an absolute path to match with paths in different directories. |
There was a problem hiding this comment.
This doesn't explain why relative path won't work. Can we either clarify that?
selene/src/main.rs
Outdated
| return false; | ||
| } | ||
|
|
||
| // File pattern between the path we are checking and current working directory. |
There was a problem hiding this comment.
| // File pattern between the path we are checking and current working directory. |
|
@dqkqd update on this? |
|
@barrett-ruth |
e7500af to
2dc6b60
Compare
|
@chriscerie
I thought that pattern matching on exclude paths should be relative to the config directory because:
However, this might have some edge cases:
What do you think? |
|
We should keep existing behavior if changing is not required to fix the issue. Changing it should have its own issue and discussion. |
|
Thank @chriscerie
Then, I use the current directory (where selene is invoked) to convert the absolute path to relative path. I updated the PR and the PR description as well. Please have a look. |
Fix #593
Exclude sometimes doesn't work with absolute path because it tries to match the pattern directly with the path itself.
Since the exclude option is relative, the absolute path to lint should be converted to relative path as well.
For example, if we are in
selene-testfolder with the following exclude option:Then, by converting this absolute path
/path/to/selene-test/src/file.luatosrc/file.lua, exclude can work properly.The problem is which path we should relate to, initially I thought using config directory (where
selene.tomllies) is a good place, but to keep it simple without unnecessary changes, I use the current directory (where selene is invoked) instead.