-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Formatting of the WebUI code base #1071
Comments
This was already started in #833 by @philippwaller and I believe the reason some ESLint rules were disabled was apparently because there were too many errors to fix at once (second table in #833). openhab-webui/bundles/org.openhab.ui/web/.eslintrc.js Lines 85 to 86 in 4c0f9fe
Also I absolutely want to keep the @vue/standard rules at least for now, which I believe are incompatible with Prettier. If there were a way to have both then why not. |
Thanks for taking the time to reply in detail what you think about this issue. I think we have to split this topic into 2 areas:
Historically, ESLint also has lots of rules that fall into the "formatting" category and (as you noted) sometimes conflict with prettier. Fortunately there is a plugin (https://github.com/prettier/eslint-config-prettier) that disables all formatting related rules from vue and leaves the formatting to prettier. Prettier can also be integrated in the eslint workflow as a eslint pluging (https://github.com/prettier/eslint-plugin-prettier#recommended-configuration). You can see the disabled rules here: https://github.com/prettier/eslint-config-prettier/blob/main/index.js Applicated to the current config the following rules would be removed because they are only formatting related and might conflict with prettier:
Regarding 1)
Regarding 2)
The following rules are already included in vue recommended, no need to declare seperately:
The following could be also activated (= removed here) if agreed upon:
Remaining project specific rules:
So how should we progress further with this? I can add stylus rules in a first PR since that seems not to need further discussion :-) I could also start with fixing some of the rules we already agree on (so that should be done anyways), but I think going through the full prettier formatting first would make the subsequent PRs already better readable (e.g. reordering lines should be easier to track) so I'm waiting on your feedback for now. |
Hey! I started playing around with prettier on this repo long time ago (Feb 2020) but haven't finished it (still dealing with cancer). Improvements there include adding
I'll see if there's something to salvage from this branch and make a proper PR, but first it would be great to consolidate what has been agreed on by you @eikowagenknecht and @ghys :-) Cheers! |
Closing my issues with openHAB that seem to have gone stale. |
The problem
Currently there are lots of different formatting styles in the WebUI code base. Example from app.vue:
Sometimes very long lines
Sometimes split by attribute.. mostly:
Formatting inconsistencies are present in HTML, JS, Stylus. This also makes the use of tools like VS Code "Format Document" hard to impossible.
Especially for beginners, it makes the code sometimes unneccessarily hard to read and comprehend.
In addition quite a few code quality ESLint rules are disabled. That leads for example to having a faulty html checked in right now (in app.vue there is a duplicate ).
Your suggestion
I could make a wordy case for why style guides are good here, but I think the guys from Prettier have summed it up quite well, so I'll refer to them instead: https://prettier.io/docs/en/why-prettier.html.
Prettier is an opinionated formatter that leaves only very few settings to be made, so the resulting code style is quite wide spread and easily recognizable for developers coming from other projects. For more information, see the link above.
Most Vue development is done with VSCode, Vetur package installed and the default formatting there is also to use Prettier, so it's integrated nicely with the dev environment used here.
I've toyed around with the ESLint settings a bit and a combination of using Prettier for HTML and JS and Stylus supremacy for stylus seems to work quite well.
ESLint
VSCode config:
The code examples above would for example be formatted to:
This has the added benefit that making changes is easier to track in git, because attributes are on their own line.
Regarding ESLint:
The ESLint rules with most errors are:
I think fixing these would be quite beneficial to the code base. Maybe there is some odd case where it's needed to break those rules, but that can be inline-commented for each occasion.
Of course there would need to be one major reformatting and enforcing of the rules and yes, open PRs would need to be refactored accordingly. But there are not so many open at the moment, so I think it should be as good a moment to do this as it will ever be ;-)
I see you have been working on ESLint recently, @ghys (e.g. #942). What is your stance on this?
I'd be happy to do the formatting and rule fixing for the whole code base, if you agree that it should be done.
The text was updated successfully, but these errors were encountered: