-
Notifications
You must be signed in to change notification settings - Fork 900
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
[WIP] JS style guidelines (draft) #8781
Comments
@martinpovolny , @romanblanco do you have anything to add/comments/..? |
TODO: |
@abonas, @skateman, @AparnaKarve : comments? @himdel, @skateman: how many of these rules can we get checked on each commit? |
@martinpovolny almost all of them, just a bit of a pain to configure properly.. |
@himdel Why is this discouraged? // discouraged
{
foo: bar,
baz: quux
} |
@AparnaKarve missing coma after // wrong
{
foo: bar,
baz: quux
} // right
{
foo: bar,
baz: quux,
} |
@romanblanco A comma even for the last item? Somehow that does not sound right. |
Exactly that :) .. because then you add a new line and the diff can look either like this... {
foo: bar,
- baz: quux
+ baz: quux,
+ something: new
} .. or like this .. {
foo: bar,
baz: quux,
+ something: new,
} Also.. https://github.com/airbnb/javascript#commas--dangling and http://www.2ality.com/2013/07/trailing-commas.html ;) |
yay, weird 🍭 |
+1 this is weird. it is even more weird to follow it only in js code. |
@abonas the main advantage is that it can avoid merge conflicts |
I understand but it's not really standard, and the ruby code doesn't follow it, so it can just create headache for developers due to inconsistency. |
On the contrary, it is recommended by multiple JS standard guides, including the aforementioned Airbnb guide.. John Papa's Angular Style Guide also mentions
We definitely can't use the preferred Ruby style, that's simply not done in the JS world.. Besides, it's not quite true, there are 1700 (!) occurences of the trailing comma in our Ruby code.. ( |
Not sure I understand - is this for manual checking or there will be some kind of automatic validation of those rules? |
@abonas miq-bot will do the checking, the same way as for ruby |
@abonas that part I'm still working on.. It will be one or more of |
|
@zeari What's murphy.sh? |
Its does a rubocop check but just on lines in files added on the last commit. Same as miq-bot but locally on your own machine. |
Right, nice .. could be even useful to put it in the miq repo.. I'll point you to the relevant miq-bot patches when they exist, so that you can do the same thing.. |
great, thanks. |
+1 on doing as much as possible the same way as https://github.com/airbnb/javascript |
What about single and double quotes? Sometimes I stumble across file where there's both of them used and it does not look good. We should agree on one or another and force to use it. I'd prefer single quotes since we were using them in hawkular. |
I'd rather not force single vs double, there are uses for both.. Especially in our code where we still manipulate the dom, etc... We could do it for specific purposes, like force double quotes in object literals if you need any, or things like that, but I'm not sure we can actually check those without checking the rest.. |
I'd prefer single quotes, also in our rubocop config |
+1 for single quotes |
Chained methodsProbably arranging the dots? $http.get('/foo')
.then(callback)
.catch(errback); If blocksWhat about short one liners? if (something) do_awesome_stuff(); |
Oh my, hasn't been touched in almost a year!! ! 😲 Aside from the no comma dangle, anyone have major issues with https://standardjs.com/ ? for the lazy Edit: and by issues, I mean problem with say the sui using standardjs, at the cost of any unwilling individual's efforts (unless ya want to 🌮 🍮 💃 ) |
@AllenBW does standardjs ❤️ typescript? |
@AllenBW well, standard js is just eslint under the hood, but the configuration.. Some parts are quite different from ours (no semicolons, space after function name), while the rest we already have in our eslint config. So... what's the benefit? And is it really that much better than eslint to justify removing all semicolons? :) |
I think that the biggest benefit is what Standard says. No configuration, no maintaining various linting files. We don’t need to keep those files in each repo and keep them in sync...which I think is a big plus. |
@skateman funny you should ask.... https://standardjs.com/#can-i-use-a-javascript-language-variant-like-flow-or-typescript (there's always a plugin for that) 🤣 😍 🤧 @himdel Agreed, some parts are quite different and with standard you can't really turn stuff off or on, its kinda THIS IS THE WAY so that's kinda a con... kinda... Benefits are:
|
What is the effort to reformat our sources to the "Standard"? Is there a tool to do that for us? |
@martinpovolny Minimal effort...just need to run:
|
@AllenBW a PR to see how this would work can go a long way ;) |
🤔 @mtho11 see how what would work? |
👍 And if you're doing a PR, please be aware of these in ui-classic:
If some of those seem a bit hard without a config file, we're in agreement ;D |
@AllenBW how standard.js would work with typescript plugin. |
Another plus for |
And IDEs like webstorm support it highlighting all rule violations inline with the code. Here is video showing the integration: https://blog.jetbrains.com/webstorm/2015/11/webstorm-11-released/ |
Oh apologies for the murky sentiment, @mtho11 I'm proposing this for the https://github.com/ManageIQ/manageiq-ui-service discussion is here cuz its the only place code style has been discussed, as mentioned above, standard does support plugins, and there are typescript plugins @himdel duly noted!! saving this, just cuz its valuable info about classic 😍 |
@AllenBW thanks for the clarification 😺 |
Oh well, then I have no objections. In the OPS UI we might need to take a more step by step approach as usual. |
FYSA for anyone who likes to 👓 ManageIQ/manageiq-ui-service#886 🍷 🤽♂️ |
This issue has been automatically marked as stale because it has not been updated for at least 6 months. If you can still reproduce this issue on the current release or on Thank you for all your contributions! |
@himdel is this issue still relevant. If not, please close. Otherwise, please remove the "stale" label. |
I think the discussion is still relevant, even though the rules mentioned above were already converted to the various Adding |
Oh, except this is still in the core repo. In that case.. @miq-bot move_issue ManageIQ/manageiq-ui-classic |
This issue has been moved to ManageIQ/manageiq-ui-classic#5045 |
(This is a draft of a future docs document detailing our Javascript style guidelines for ManageIQ and SSUI.)
formatting
indentation
Use 2 spaces per indent level, not 4, nor tabs..
object and array literals
trailing commas
Please prefer trailing commas in multiline object or array literals, they are fully supported now and make nicer diffs..
function calls
No spaces surrounding the brackets, split long lines after
{
or[
. If you're splitting the call into multiple lines close the parenthesis right after the last argument (same line), and try to keep each argument on a separate line.chained methods (esp. then/catch/done/success/etc.)
Please always split chained method calls into multiple lines, starting continuing lines with the dot, and use one indent level for these lines.
if/while blocks
Please use a space before the first parenthesis, use egyptian brackets, and prefer brackets even for single-statement bodies.
expressions
Always surround binary operators with spaces.
switch statements
Unlike in ruby, indent
case
one indent level more thanswitch
. Also, please explicitly mark case-to-case fall-through with// pass
.naming
functions
Use
camelCase
for function/method names.angular
Prefer full
FooController
for controllers,FooService
for services,FooFactory
for factories,foo
for directives andfoo
orfoo.bar
for modules.globals
don't
Don't use global global variables, ever.
Also, please try not to create them accidentally by omitting
var
.ManageIQ
global objectIf you really have to keep global state, add it to the
ManageIQ
global object, defined inmiq_global.js
, and add a comment with a purpose.But please think twice before introducing a new one.
general
comparison operators
Please prefer
===
and!==
to==
and!=
, but only when it makes sense.quoting
Prefer single quotes, unless really inconvenient.
es6
We do support ES6 now (or a subset thereof - via babel 5) provided the file has an
.es6
extension. Please use your judgement and consultconfig/initializers/sprockets-es6.rb
. Also, we support all ES6 library methods (includingPromise
) in.js
files viaes6-shim
.linting
In manageiq-ui-self_service, you can run
gulp vet
, which runsjshint
andjscs
- but the configuration is currently too opinionated. (TODO)In manageiq, you can run linters manually, as soon as we add their config files.. (TODO)
For anything not specified here, please consult https://github.com/airbnb/javascript .
The text was updated successfully, but these errors were encountered: