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 .editorconfig to keep project files consistent #960

Merged
merged 15 commits into from
May 1, 2024

Conversation

Cruikshanks
Copy link
Member

@Cruikshanks Cruikshanks commented Apr 30, 2024

DEFRA/water-abstraction-team#115

We've been fortunate enough to grow as a team this year which means we've had several new developers join us! 🥳

Unfortunately, it has exposed our onboarding still leaves a lot to be desired. We find we keep having to highlight the same coding convention or stylistic issues in new members' initial PRs. This is irrespective of whether we have written up the convention or not.

Wouldn't it be great if we used all this computing power we interact with daily to help them get it right the first time? That we help them fall into the pit of success?

One idea is to add an .editorconfig to the repo. Depending on folks IDE choice it will either be recognised out-of-the-box or they'll need an extension.

Unlike other tools having the file doesn't do anything directly to your project. Instead, it tells your chosen editor how to behave when working with the files. For example, when you indent something whether to use tabs or spaces and how many. If your editor can remove whitespace on save, the .editorconfig will tell it whether to do that or not.

Even for folks using an incompatible editor or who choose not to install the extension, we at least have something that defines what we expect and can be used in our CI pipeline.

This change adds an initial version generated using the VSCode extension based on current editor settings.

It also updates our GitHub CI workflow to check that pushed changes match our conventions.


This change highlighted that the line endings in our migrations were inconsistent. So, the fix for those is included.

DEFRA/water-abstraction-team#115

We've been fortunate enough to grow as a team this year which means we've had several new developers join us! 🥳

Unfortunately, it has exposed our onboarding still leaves a lot to be desired. We find we keep having to highlight the same coding convention or stylistic issues in new members' initial PRs. This is irrespective of whether we have written up the convention or not.

Wouldn't it be great if we used all this computing power we interact with daily to help them get it right the first time? That we help them fall into the [pit of success](https://www.hackterms.com/pit%20of%20success)?

One idea is to add an [.editorconfig](https://editorconfig.org/) to the repo. Folks have the choice to add the extension (some IDEs will use it out of the box) but it at least defines some basics for any code files folks wish to add.

This change adds an initial version generated using the [VSCode extension](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) based on current editor settings.
@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Apr 30, 2024
@Cruikshanks Cruikshanks self-assigned this Apr 30, 2024
Though it has the most stars maintenance for [EditorConfig-Action](https://github.com/marketplace/actions/editorconfig-action) seems to have stopped. People have been pushing fixes but no one is merging them in. When we tried this action we got

```
ERROR: failed to solve: process "/bin/sh -c npm install --no-save . && \tln -s $(npm bin)/eclint /usr/local/bin && \tnpm audit && \techo \"eclint version: $(eclint --version)\"" did not complete successfully: exit code: 1
Warning: Docker build failed with exit code 1, back off 7.523 seconds before retry.
```

So, we're trying the next most popular result from the marketplace!
Nothing got flagged by the checker. So, following docs even though VSCode is screaming that `run:` shouldn't be there!
Now the checker seems to be picking up the issues
By going through the files VSCode displays the line endings for the current file in the status bar. Switching that from `CRLF` to `LF` cause git to see a change though there is nothing discernable from the editor itself!
It seems 2, 4, 6 etc indents are not picked up but 1, 3, 5 etc are.
This one doesn't require both a `use`` and a `run` step.
It might require 2 steps, but at least it is dependent on a maintained editorconfig linter. The rest of the options in the marketplace seemed to be dependent on ECLint which is now archived.
@Cruikshanks
Copy link
Member Author

This looks like a scary amount of changes. But when you go to look at the files, close the db folder and just focus on the other files.

Screenshot 2024-04-30 at 21 47 13

Adding this and the CI action highlighted that the migration files had inconsistent line endings. I've corrected them in this change to get CI to pass and to start with no errors. But that means Git thinks I've changed thousands of lines of code!

@Cruikshanks Cruikshanks marked this pull request as ready for review April 30, 2024 20:51
@Cruikshanks Cruikshanks changed the title Add .editorconfig Add .editorconfig to keep project files consistent Apr 30, 2024
Copy link
Collaborator

@jonathangoulding jonathangoulding 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 it works for me in Webstorm.

I think we merge this to main then check with eslint branch to make sure they are consistent and not fighting each other. ( I will hold off the eslint branch merge until this is in)

We can investigate the use of https://www.npmjs.com/package/eslint-plugin-editorconfig if necessary.

@Cruikshanks
Copy link
Member Author

Agreed @jonathangoulding . I'm not over the moon about the CI choice/option. There seems little support for using a stock GitHub action when it comes to linting based on your .editorconfig. But that might be because everyone is using their stock linter + plugin/extension like you suggest.

So, defo once this and the ESlint branch are merged we should look into whether eslint-plugin-editorconfig is a better solution.

@Cruikshanks Cruikshanks merged commit 38c572a into main May 1, 2024
6 checks passed
@Cruikshanks Cruikshanks deleted the add-editor-config branch May 1, 2024 15:22
Cruikshanks added a commit to DEFRA/water-abstraction-service that referenced this pull request Nov 21, 2024
https://eaflood.atlassian.net/browse/WATER-4729

When working on updating the environment to Node v22 we encountered an error with the `entrypoint.sh`. Docker compose couldn't find the file when rebuilding the new image.

Huh?

We know! Countless numbers of us have built this environment successfully, but the error was there plain and clear. Perhaps its a change in docker compose?

Anyway, miraculously one of the team tracked it down to the file having a mix of `LF` and `CRLF` line endings. Once they updated the line endings in the file to always be `LF`, docker compose succeeded in building the image.

So, this change corrects all files with mixed line endings. We then add a [.editorconfig](https://editorconfig.org/) file to the repo. We did this to [water-abstraction-system](DEFRA/water-abstraction-system#960) as part of helping to ensure consistency in our code and the same applies here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants