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: add more default settings for VSCode #388

Merged
merged 8 commits into from
Nov 28, 2022
Merged

feat: add more default settings for VSCode #388

merged 8 commits into from
Nov 28, 2022

Conversation

thbeu
Copy link
Contributor

@thbeu thbeu commented Nov 17, 2022

This is for #386.

Copy link
Owner

@jenstroeger jenstroeger 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, thank you @thbeu. Also notice that I had added these two git hooks to my PR #386:

- id: check-json
- id: pretty-format-json
args: [--autofix]

Looks like your git hooks didn’t run locally on commit?

Please note that I just closed my own PR #386 and changed the base of your, this PR to our staging branch. We can use this PR and merge it straight into our mainstream.

One more question below.

.vscode/settings.json Show resolved Hide resolved
@jenstroeger jenstroeger changed the base branch from add-vscode-settings to staging November 17, 2022 21:49
@thbeu
Copy link
Contributor Author

thbeu commented Nov 17, 2022

Both check-json and pretty-format-json fail on settings.json and extensions.json where I added line comments. Not sure what to do?

@jenstroeger
Copy link
Owner

Both check-json and pretty-format-json fail on settings.json and extensions.json where I added line comments. Not sure what to do?

To be honest, I’m not certain either. I’m a little surprised that VSCode produces incorrect JSON (i.e. JavaScript style comments inside JSON) and the git hooks have a different opinion wrt. formatting. I’m a bit worried that forcing the git hooks over the VSCode generated files will continue to be headache, because every time a user changes the VSCode settings the hooks will complain.

We could consider using exclude in the configuration, for example here

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_install_hook_types: [pre-commit, commit-msg, pre-push]
default_stages: [commit]
minimum_pre_commit_version: 2.18.0

we’d add

exclude: ^.vscode/

That way VSCode can just own these files without the git hooks changing & checking them.

@thbeu
Copy link
Contributor Author

thbeu commented Nov 18, 2022

We could consider using exclude in the configuration, for example here

I already played with that exclude setting but did not get it running:

Check hooks apply to the repository......................................Failed
- hook id: check-hooks-apply
- exit code: 1

check-json does not apply to this repository
pretty-format-json does not apply to this repository

@jenstroeger
Copy link
Owner

check-json does not apply to this repository
pretty-format-json does not apply to this repository

Yup that’s expected output from this hook

- id: check-hooks-apply

Because we’ve excluded all JSON files using a global exclude: we now don’t need those hooks anymore.

@thbeu
Copy link
Contributor Author

thbeu commented Nov 18, 2022

Argh, there is an EOL issue now in .pre-commit-config.yaml. It really would be helpful to have a .gitattributes file within the repo to avoid such kind of EOL conversion. See https://rehansaeed.com/gitattributes-best-practices/

# Set default behavior to automatically normalize line endings.
* text=auto

# Force batch scripts to always use CRLF line endings so that if a repo is accessed
# in Windows via a file share from Linux, the scripts will work.
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf

# Force bash scripts to always use LF line endings so that if a repo is accessed
# in Unix via a file share from Windows, the scripts will work.
*.sh text eol=lf

@jenstroeger
Copy link
Owner

jenstroeger commented Nov 18, 2022

Argh, there is an EOL issue now in .pre-commit-config.yaml.

Probably caused by this hook:

- id: end-of-file-fixer
stages: [commit]

It really would be helpful to have a .gitattributes file within the repo to avoid such kind of EOL conversion. See https://rehansaeed.com/gitattributes-best-practices/

Oh sure, I’ll take a look, thanks! (Opened issue #389.)

@thbeu
Copy link
Contributor Author

thbeu commented Nov 18, 2022

we now don’t need those hooks anymore.

And removed again.

@thbeu thbeu requested a review from jenstroeger November 18, 2022 06:16
Copy link
Owner

@jenstroeger jenstroeger left a comment

Choose a reason for hiding this comment

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

These are the original VSCode files, yes?

@thbeu
Copy link
Contributor Author

thbeu commented Nov 18, 2022

These are the original VSCode files, yes?

What do you mean by original? EOL of the three JSON files is mixed, it seems.

@jenstroeger
Copy link
Owner

What do you mean by original?

I mean that if a user opens the project using VSCode then they’ll work? If a user changes their settings and saves then it won’t impact any other aspect of the repo considering we’ve excluded the entire .vscode/ directory.

Let’s wait what @behnazh says but I’m ok with this change 👍🏼

@thbeu
Copy link
Contributor Author

thbeu commented Nov 18, 2022

I mean that if a user opens the project using VSCode then they’ll work?

Yes, they will work on Linux provided the venv is correctly setup. For Windows the python.defaultInterpreterPath needs to be adapted since there is no platform specfic setting in VS code (which is a pitty).

Copy link
Collaborator

@behnazh behnazh left a comment

Choose a reason for hiding this comment

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

Looks like you've removed the exclude: ^.vscode/ from .pre-commit-config.yaml?

@thbeu
Copy link
Contributor Author

thbeu commented Nov 21, 2022

.pre-commit-config.yaml is no longer touched by this PR.

@behnazh
Copy link
Collaborator

behnazh commented Nov 21, 2022

.pre-commit-config.yaml is no longer touched by this PR.

Because the VSCode configuration JSON file contains comments, our pre-commit hooks should fail. Did it pass for you? It would be good to exclude the .vscode/ from .pre-commit-config.yaml in this PR.

@jenstroeger
Copy link
Owner

Because the VSCode configuration JSON file contains comments, our pre-commit hooks should fail. Did it pass for you? It would be good to exclude the .vscode/ from .pre-commit-config.yaml in this PR.

The current pre-commit configuration does not check JSON files (there’s some forth and back on that in the above comments).

However, if a user would add e.g. the check-json hook then yes, that hook would fail on the VSCode files (which aren’t actually valid JSON). So we should probably add

exclude: ^.vscode/

back into .pre-commit-config.yaml as a preventative measure and also to make sure that pre-commit doesn’t ever consider the .vscode/ folder (which should be solely owned by VSCode).

@behnazh
Copy link
Collaborator

behnazh commented Nov 22, 2022

The current pre-commit configuration does not check JSON files

Oops, my bad. I thought we already had added a check.

to make sure that pre-commit doesn’t ever consider the .vscode/ folder (which should be solely owned by VSCode).

👍

@jenstroeger
Copy link
Owner

@thbeu does pre-commit work if you add

exclude: ^.vscode/

back to the top of the .pre-commit-config.yaml?

@thbeu
Copy link
Contributor Author

thbeu commented Nov 28, 2022

Yes, that works, see 676ff34.

@jenstroeger
Copy link
Owner

@thbeu feel free to Squash and merge your PR now 👍🏼

@thbeu
Copy link
Contributor Author

thbeu commented Nov 28, 2022

@thbeu feel free to Squash and merge your PR now 👍🏼

Only contributors /w write access can do so.

@jenstroeger jenstroeger merged commit 10154b3 into jenstroeger:staging Nov 28, 2022
@jenstroeger
Copy link
Owner

Good, you’re still the author of the merged commit 10154b3 — I wanted to ensure that you get the fame and blame for this change 😉

@thbeu thbeu deleted the add-more-vscode-settings branch November 28, 2022 10:02
@thbeu
Copy link
Contributor Author

thbeu commented Nov 28, 2022

When will it go from jenstroeger:staging to main?

@jenstroeger
Copy link
Owner

We’ve not planned a new release yet. Do you have a desired date or a deadline?

@thbeu
Copy link
Contributor Author

thbeu commented Nov 28, 2022

No, just being curious.

@jenstroeger
Copy link
Owner

@thbeu, we just published v2.5.0 with your change 🤓

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.

3 participants