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: allow empty result from changed vcs files #1776

Merged
merged 4 commits into from
Mar 4, 2024

Conversation

antogyn
Copy link
Contributor

@antogyn antogyn commented Feb 9, 2024

Summary

Allow an empty result when checking for changed files, which can later be allowed or not depending on the --no-errors-on-unmatched flag

Fixes #1774

Test Plan

To be done

Copy link

netlify bot commented Feb 9, 2024

Deploy Preview for biomejs ready!

Name Link
🔨 Latest commit 5e3fe48
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/65e5f357982d7000082cf803
😎 Deploy Preview https://deploy-preview-1776--biomejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (🟢 up 1 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 93 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the A-CLI Area: CLI label Feb 9, 2024
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

This looks good to me, I am happy to merge it whenever you want

@antogyn
Copy link
Contributor Author

antogyn commented Feb 17, 2024

It doesn't actually fix the issue, and returns an other error:

flags/invalid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Missing argument <INPUT>

It seems to be returned at the start of traverse, I'm looking into it

@antogyn
Copy link
Contributor Author

antogyn commented Feb 17, 2024

In my opinion this check should instead be done at the parsing level if possible, for example in crates/biome_cli/src/commands/mod.rs:

        /// Single file, single path or list of paths
        #[bpaf(positional("PATH"), many)]
        paths: Vec<OsString>,

paths should ideally be validated right here, eg something like this, using some from bpaf:

        /// Single file, single path or list of paths
        #[bpaf(positional("PATH"), some("No path was specified"))]
        paths: Vec<OsString>,

unless there are cases where it's ok to have no path? Wdyt?

@antogyn antogyn force-pushed the fix/allow-empty-changed branch from b7b96c5 to 60eeb88 Compare February 17, 2024 19:37
@antogyn
Copy link
Contributor Author

antogyn commented Feb 17, 2024

I've updated the PR with a new proposal

It slightly changes the output if there is no provided path, as it's directly validated by bpaf:

Error: No path was provided

instead of

flags/invalid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Missing argument <INPUT>

and it does fix the issue this time 🎉

@ematipico
Copy link
Member

unless there are cases where it's ok to have no path?

There's a case, which is when users need/want to process files via standard in.

@antogyn
Copy link
Contributor Author

antogyn commented Feb 17, 2024

Well, it breaks tests that make use of --stdin-file-path, and it looks like a legit case of not providing paths, so my proposal doesn't work

I guess this check:

if inputs.is_empty() && execution.as_stdin_file().is_none() {
        return Err(CliDiagnostic::missing_argument(
            "<INPUT>",
            format!("{}", execution.traversal_mode),
        ));
    }

must stay somewhere

@antogyn antogyn force-pushed the fix/allow-empty-changed branch from 60eeb88 to 2afa1d5 Compare February 17, 2024 20:05
@antogyn
Copy link
Contributor Author

antogyn commented Feb 17, 2024

I've updated the PR with the most straightforward solution, which allows empty paths if --no-errors-on-unmatched is set, by just updating the condition

inputs.is_empty() && execution.as_stdin_file().is_none()

to

inputs.is_empty() && execution.as_stdin_file().is_none() && !cli_options.no_errors_on_unmatched

It fixes the issue, but I'm not sure it's acceptable

@@ -24,9 +24,5 @@ pub(crate) fn get_changed_files(

let filtered_changed_files = changed_files.iter().map(OsString::from).collect::<Vec<_>>();

if filtered_changed_files.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

I believe this check should stay, but we need to add the check if no_errors_on_unmatched is true

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've re-added this check, but now it's done twice - once here, and once in traverse.rs

@antogyn antogyn force-pushed the fix/allow-empty-changed branch from 60e6940 to eef046a Compare February 21, 2024 18:17
@antogyn antogyn force-pushed the fix/allow-empty-changed branch from eef046a to 047c8b1 Compare February 21, 2024 18:20
@antogyn antogyn marked this pull request as ready for review February 28, 2024 09:00
@antogyn
Copy link
Contributor Author

antogyn commented Mar 1, 2024

Is there anything else preventing it from being merged?

@ematipico
Copy link
Member

Is there anything else preventing it from being merged?

A test plan :)

@ItamarShDev
Copy link

I have it too and it prevents me from integrating Biome to the company sadly. will wait

@ray-peters
Copy link

In the same boat with @ItamarShDev
Would love to see this bug fix sooner than later

@github-actions github-actions bot added A-Core Area: core A-Website Area: website A-Changelog Area: changelog labels Mar 4, 2024
@ematipico ematipico merged commit b95f83e into biomejs:main Mar 4, 2024
13 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-CLI Area: CLI A-Core Area: core A-Website Area: website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 --changed doesn't work when run on the base branch even if --no-errors-on-unmatched is enabled
4 participants