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 "--force-exclude" option #837

Merged
merged 2 commits into from Oct 9, 2023
Merged

Add "--force-exclude" option #837

merged 2 commits into from Oct 9, 2023

Conversation

Delgan
Copy link
Contributor

@Delgan Delgan commented Sep 30, 2023

Hi.

As discussed in #347, I'm proposing here a simple --force-exclude option if that sounds good to you.

Regarding the implementation, I had to use Override.matched() because the Walk class unconditionally includes the initial path it receives. This means that any explicitly passed file we might want to exclude would not have a chance to be filtered.

I'm not very familiar with Rust so let me know if there are things you want me to improve.

Copy link
Collaborator

@epage epage left a comment

Choose a reason for hiding this comment

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

Thanks for moving this forward!

@@ -98,6 +98,8 @@ impl Config {
#[serde(rename_all = "kebab-case")]
pub struct Walk {
pub extend_exclude: Vec<String>,
// Exclude files even if passed explicitly.
pub force_exclude: Option<bool>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

To me, this feature seems more situational rather than being a fixed state, so I think it should be cli only and not in config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I moved force_exclude from WalkArgs to Args (since parsed WalkArgs are only publicly accessible through Config). This implies means that --force-exclude option will not appear immediately after --exclude in the --help.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that'll be ok. I'm working on #846 which will make it easier to review help output changes and, in looking at it, I think this works well for the new top section

crates/typos-cli/tests/cmd/force-exclude.toml Show resolved Hide resolved
@@ -216,6 +216,12 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
let overrides = overrides
.build()
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
if walk_policy.force_exclude() && path.is_file() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the file check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question... I think I over-focused on my specific use case, sorry.

@@ -216,6 +216,12 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
let overrides = overrides
.build()
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
if walk_policy.force_exclude() && path.is_file() {
match overrides.matched(path, false) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something I need to double check is that some of these APIs expect you to call them as you recurse into a directory and return confusing results if you only call them on the final path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum... I think you're correct. If I have foo/bar/baz.file directory structure and extend-exclude = ["bar/*.file"] configuration, using typos foo will ignore the file properly but typos foo/bar/baz.file --force-exclude won't (using extend-exclude = ["foo/bar/*.file"] or extend-exclude = ["baz.file"] works, though). 😕

Not sure how to fix it. Maybe we should propose a feature to ignore crate so that it optionally checks root entry as well: walk.rs#L936-L938?
I don't know how likely is it to be accepted, knowing that Walk is supposed to be used with directory as argument (from the docs at least), and we're using it with file path as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You likely need to do path.ancestors().rev(), calling matched` on each

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies, I think I just did something wrong during my test. The file is not excluded in any case, which is the expected behavior.

@epage
Copy link
Collaborator

epage commented Oct 9, 2023

Sorry about the spelling failure in CI; I had a bad merge which introduced this workflow when it shouldn't be here. Fixed in master

@Delgan
Copy link
Contributor Author

Delgan commented Oct 9, 2023

Sorry about the spelling failure in CI; I had a bad merge which introduced this workflow when it shouldn't be here. Fixed in master

No problem. I rebased the PR. 👍

@epage epage merged commit 2303689 into crate-ci:master Oct 9, 2023
13 of 14 checks passed
@epage
Copy link
Collaborator

epage commented Oct 9, 2023

Thanks!

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.

None yet

2 participants