-
Notifications
You must be signed in to change notification settings - Fork 356
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
JS style guidelines (draft) #5045
Comments
For discussion, please see the original issue ManageIQ/manageiq#8781 ES6 update: the rules mentioned here (and in in cases where |
Cc @Hyperkid123 (just because you're also dealing with eslint now) |
@himdel what's the status on this issue? should we close it? |
@mfeifer this is a non-issue. The rules described here were already implemented, Maybe we should move the text to the wiki or guides instead, and close the issue, |
Yeah it should move out of issues into wiki or guides. |
Alright, closing, moved to https://github.com/ManageIQ/manageiq-ui-classic/wiki/JS-style-guidelines :) |
(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 .
This issue was moved to this repository from ManageIQ/manageiq#8781, originally opened by @himdel
The text was updated successfully, but these errors were encountered: