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

Fix: Exclude not working with absolute path in some cases (#593) #618

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dqkqd
Copy link

@dqkqd dqkqd commented Oct 12, 2024

Fix #593

Exclude files if they match exclude patterns using working directory (config directory if a config file is provided, otherwise it is the current directory) as a base.

I'm not sure whether I should add testcases for this, since this requires refactor into smaller functions.

@dqkqd dqkqd force-pushed the issue-593 branch 4 times, most recently from 5a5a878 to 4293812 Compare October 13, 2024 21:44
Copy link
Collaborator

@chriscerie chriscerie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Path::new(&config_file).parent().map(Path::to_path_buf),
),
Ok(config) => {
// Get config directory to using absolute path.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Get config directory to using absolute path.

Comment on lines +528 to +529
// There is case where `config = Some("selene.toml")`,
// which returns `""`` when getting parent directory.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

let config_directory = Path::new(&config_file)
.canonicalize()
.ok()
.and_then(|path| path.parent().map(|path| path.to_path_buf()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.and_then(|path| path.parent().map(|path| path.to_path_buf()));
.and_then(|path| path.parent().map(Path::to_path_buf));

@@ -512,6 +512,7 @@ fn start(mut options: opts::Options) {

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// User provides a config file. We must read it and report if it is misconfigured.

Comment on lines +646 to +647
// Directory for matching files pattern.
// If user provides a config file, we use that as our working directory, otherwise fallback to the current directory.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Directory for matching files pattern.
// If user provides a config file, we use that as our working directory, otherwise fallback to the current directory.

@@ -636,6 +643,26 @@ fn start(mut options: opts::Options) {

let pool = ThreadPool::new(options.num_threads);

// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't explain why relative path won't work. Can we either clarify that?

return false;
}

// File pattern between the path we are checking and current working directory.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// File pattern between the path we are checking and current working directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude not working with absolute path in some cases
3 participants