LinguaCafe icon indicating copy to clipboard operation
LinguaCafe copied to clipboard

Code linting

Open cblanken opened this issue 6 months ago • 14 comments

Has there been any thought to add some linting to the project? I saw there's a brief mention of code style in CONTRIBUTING.md, but nothing about automatic linting. Personally I don't care about which style of linting is applied just that there is any regular formatting that can be automatically applied. That way I don't have to think so much about trying to match existing styles :)

I'm not sure what's preferred on the PHP/Laravel side, but for Python I know pylint and ruff are popular.

  • [x] PHP linting
  • [x] JS linting
  • [ ] Python linting

cblanken avatar Jul 31 '25 14:07 cblanken

Yes, I did want to add it in the last few weeks, just didn't get to it. For javascript I'll use prettier, I think with the default vscode settings. I don't know what to use for php yet, I'll look around. The one I use at work(I think its called psr-13) does not autoformat everything, like long lines. For python we can use whichever you prefer.

We can add it after I merged in your PR-s if it's important for you.

simjanos-dev avatar Jul 31 '25 16:07 simjanos-dev

Laravel pint looks nice.

simjanos-dev avatar Jul 31 '25 17:07 simjanos-dev

No rush. Just something I was thinking about as I was looking at the code more. I'll look into setting up something with ruff when the time comes.

cblanken avatar Jul 31 '25 17:07 cblanken

No rush.

I wanted to add it as well. Might try to add Pint and Prettier this weekend.

Also been thinking about breaking up the code a bit into folders. Currently everything is inside the Laravel folder.

Like something like this: . ├── .github ├── Backend │ ├── Laravel │ └── Python ├── Frontend │ ├── Vue2 │ └── Vue3 ├── Docker ├── GithubImages ├── Tools (the ancient python script I wrote for processing a raw jmdict file) └── Manual

But this would be a bit of work.

simjanos-dev avatar Jul 31 '25 17:07 simjanos-dev

Wouldn't be a bad idea the root is kinda cluttered. I'd normalize on snakecase for directory names instead of titlecase though.

cblanken avatar Jul 31 '25 18:07 cblanken

I'd normalize on snakecase for directory names instead of titlecase though.

That's fine too, I don't really have a preference.

I'll probably add the PHP and JS linters tomorrow or the day after.

simjanos-dev avatar Jul 31 '25 23:07 simjanos-dev

I've added Pint as a php linter. It does everything I would like, except breaking long lines.

I put it in a git stash. Can I apply it, or should I wait for your PR to avoid conflicts?

simjanos-dev avatar Aug 01 '25 16:08 simjanos-dev

Go ahead, I'll fixup the PR if there's anything that needs it.

cblanken avatar Aug 01 '25 17:08 cblanken

Thank you!

I've added both Pint and Prettier. At first glance it looks good, I'll add more rules if I find something missing.

Any suggestions for more rules for either of them?

And also thank you for suggesting it. It went a lot easier than expected.

simjanos-dev avatar Aug 01 '25 17:08 simjanos-dev

Looks good!

Any suggestions for more rules for either of them?

I'm personally a fan of a tabwidth of 2 for HTML and CSS/SCSS since it helps keep a lot of nested tags from going too wide. But like I said before, I don't have any strong preferences.

It would probably be a good idea to add a Github Action to check for linting before merges into dev or main too.

cblanken avatar Aug 01 '25 18:08 cblanken

I'm personally a fan of a tabwidth of 2

I've set it to 2, vscode will format it as 4 for me, so I don't mind. I also don't quite understand what does it mean, because it still uses 1 tab for identations if I look at the raw file on github, and in vscode it does not overwrite my displayed tab width setting.

This makes me so frustrated. I've just realized that Laravel Pint does not have a config option to use tabs, because it wants to provide as little config as possible, to make Laravel codebases more identical.

Should we also use spaces in js to make it identical to php? We could also replace Laravel Pint, but it is the easiest to setup. Or we can keep the 2 languages with different identations.

simjanos-dev avatar Aug 01 '25 21:08 simjanos-dev

I'd say stick with Pint unless you have serious misgivings with some of it's styling.

Not sure what you mean about the indentation in Github vs VSCode.

Probably best to pick either tabs or spaces for both languages imo.

cblanken avatar Aug 01 '25 23:08 cblanken

I'd say stick with Pint unless you have serious misgivings with some of it's styling.

Other than forced spaces it's perfect.

Not sure what you mean about the indentation in Github vs VSCode.

Laravel Pint forces spaces for indentation, but VSCode can render and handle them as tabs for me.

What I didn't understand is whether I set tabWidth to 2 or 4 in prettier, I didn't see any difference neither on GitHub and VSCode. But just looked it up again, and it matters only when calculating row lenghts (when useTabs is true).

Probably best to pick either tabs or spaces for both languages imo. But like I said before, I don't have any strong preferences.

In that case I'll set prettier to 4 spaces as well to make it identical with php, and because I couldn't get vscode to render 2 spaces the way I wanted.

simjanos-dev avatar Aug 02 '25 08:08 simjanos-dev

It looks like ruff has an official Github Action (https://github.com/astral-sh/ruff-action). That would probably be ideal for keeping PR's clean on the Python side.

I couldn't find anything official for prettier or pint, so they'll probably need something custom.

cblanken avatar Aug 11 '25 20:08 cblanken