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

feat: support linting stdin #388

Merged
merged 2 commits into from
Oct 25, 2023
Merged

feat: support linting stdin #388

merged 2 commits into from
Oct 25, 2023

Conversation

llllvvuu
Copy link
Contributor

@llllvvuu llllvvuu commented Sep 6, 2023

Similarly for fixit fix. The API is inspired by Prettier.

Summary

Related to #122 but does not fully resolve it. It supports a lint-as-you-type workflow, whereas only a lint-on-save workflow could be supported before. Full resolution of #122 would require #387.

Test Plan

Extended smoke tests.

@facebook-github-bot
Copy link

Hi @llllvvuu!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@llllvvuu
Copy link
Contributor Author

llllvvuu commented Sep 6, 2023

CLA submitted

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 6, 2023
Copy link
Member

@amyreese amyreese left a comment

Choose a reason for hiding this comment

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

I like this as functionality to support, but I'd rather push this functionality into the supported API, rather than handling stdin at the CLI layer.

Take a look at how we did this for µfmt, where passing Path("-") (what you get from click.Path(allow_dash=True) as the first element of paths to ufmt_paths(...) triggers handling for stdin. https://github.com/omnilib/ufmt/blob/main/ufmt/core.py#L308

Adding fixit_stdin to the API to handle reading stdin and wrap fixit_bytes would be the first step, then update fixit_paths to detect the stdin sentinel and defer to fixit_stdin instead of normal file processing.

Is that something you would be interested in tackling, or would you rather I adapt your work accordingly?

@llllvvuu
Copy link
Contributor Author

llllvvuu commented Sep 27, 2023

Just took a look at ufmt CLI and happy to make the changes. So to confirm, intended usage is

fixit lint - path/to/foo.py  # formats stdin, treating it as if it is located at path/to/foo.py

@amyreese
Copy link
Member

Just took a look at ufmt CLI and happy to make the changes. So to confirm, intended usage is

fixit lint - path/to/foo.py  # formats stdin, treating it as if it is located at path/to/foo.py

Correct :)

@amyreese amyreese changed the title feat: support cat foo.py | fixit lint --stdin --stdin-filepath foo.py feat: support linting stdin Sep 28, 2023
@llllvvuu llllvvuu force-pushed the feat/stdin branch 4 times, most recently from 1b01d2f to 449c805 Compare September 30, 2023 09:00
@llllvvuu
Copy link
Contributor Author

Just made the changes, thanks again for the ufmt reference!

I wasn't able to leave cli.py 100% unchanged since fixit fix needs to disable --interactive (as STDIN is occupied) and redirect Results to STDERR (as STDOUT is occupied). But let me know what you think

@llllvvuu llllvvuu force-pushed the feat/stdin branch 2 times, most recently from 85ea7ae to d42fa15 Compare September 30, 2023 09:04
@amyreese amyreese merged commit 81fb393 into Instagram:main Oct 25, 2023
13 checks passed
@amyreese
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants