You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Donotusespacesaround the `=` sign whenusedtoindicateadefaultparameter value
135
135
136
-
```coffeescript
137
-
test: (param=null) -> # Yes
138
-
test: (param = null) -> # No
139
-
```
136
+
```coffeescript
137
+
test: (param=null) -># Yes
138
+
test: (param=null) -># No
139
+
```
140
140
141
141
<aname="comments"/>
142
142
## Comments
@@ -156,18 +156,18 @@ Each line of a block comment starts with a `#` and a single space, and should be
156
156
157
157
Paragraphs inside of block comments are separated by a line containing a single `#`.
158
158
159
-
```coffeescript
160
-
# This is a block comment. Note that if this were a real block
161
-
# comment, we would actually be describing the proceeding code.
162
-
#
163
-
# This is the second paragraph of the same block comment. Note
164
-
# that this paragraph was separated from the previous paragraph
165
-
# by a line containing a single comment character.
166
-
167
-
init()
168
-
start()
169
-
stop()
170
-
```
159
+
```coffeescript
160
+
# This is a block comment. Note that if this were a real block
161
+
# comment, we would actually be describing the proceeding code.
162
+
#
163
+
# This is the second paragraph of the same block comment. Note
164
+
# that this paragraph was separated from the previous paragraph
165
+
# by a line containing a single comment character.
166
+
167
+
init()
168
+
start()
169
+
stop()
170
+
```
171
171
172
172
<a name="inline_comments"/>
173
173
###Inline Comments
@@ -180,17 +180,17 @@ The use of inline comments should be limited, because their existence is typical
180
180
181
181
Donotuseinline comments whentheystatetheobvious:
182
182
183
-
```coffeescript
184
-
# No
185
-
x = x + 1 # Increment x
186
-
```
183
+
```coffeescript
184
+
# No
185
+
x= x +1# Increment x
186
+
```
187
187
188
188
However, inline comments can be useful in certain scenarios:
189
189
190
-
```coffeescript
191
-
# Yes
192
-
x = x + 1 # Compensate for border
193
-
```
190
+
```coffeescript
191
+
# Yes
192
+
x= x +1# Compensate for border
193
+
```
194
194
195
195
<aname="naming_conventions"/>
196
196
## Naming Conventions
@@ -203,15 +203,15 @@ _(The **official** CoffeeScript convention is camelcase, because this simplifies
203
203
204
204
For constants, use all uppercase with underscores:
205
205
206
-
```coffeescript
207
-
CONSTANT_LIKE_THIS
208
-
```
206
+
```coffeescript
207
+
CONSTANT_LIKE_THIS
208
+
```
209
209
210
210
Methods and variables that are intended to be "private" should begin with a leading underscore:
211
211
212
-
```coffeescript
213
-
_privateMethod: ->
214
-
```
212
+
```coffeescript
213
+
_privateMethod:->
214
+
```
215
215
216
216
<aname="functions"/>
217
217
## Functions
@@ -220,58 +220,58 @@ _(These guidelines also apply to the methods of a class.)_
220
220
221
221
When declaring a function that takes arguments, always use a single space after the closing parenthesis of the arguments list:
222
222
223
-
```coffeescript
224
-
foo = (arg1, arg2) -> # Yes
225
-
foo = (arg1, arg2)-> # No
226
-
```
223
+
```coffeescript
224
+
foo= (arg1, arg2) -># Yes
225
+
foo= (arg1, arg2)-># No
226
+
```
227
227
228
228
Do not use parentheses when declaring functions that take no arguments:
229
229
230
-
```coffeescript
231
-
bar = -> # Yes
232
-
bar = () -> # No
233
-
```
230
+
```coffeescript
231
+
bar=-># Yes
232
+
bar= () -># No
233
+
```
234
234
235
235
In cases where method calls are being chained and the code does not fit on a single line, each call should be placed on a separate line and indented by one level (i.e., two spaces), with a leading `.`.
236
236
237
-
```coffeescript
238
-
[1..3]
239
-
.map((x) -> x * x)
240
-
.concat([10..12])
241
-
.filter((x) -> x < 11)
242
-
.reduce((x, y) -> x + y)
243
-
```
237
+
```coffeescript
238
+
[1..3]
239
+
.map((x) -> x * x)
240
+
.concat([10..12])
241
+
.filter((x) -> x <11)
242
+
.reduce((x, y) -> x + y)
243
+
```
244
244
245
245
When calling functions, omit the parentheses on the final method call in a chain. For example:
246
246
247
-
```coffeescript
248
-
baz 12
247
+
```coffeescript
248
+
baz12
249
249
250
-
foo(4).bar 8
251
-
```
250
+
foo(4).bar8
251
+
```
252
252
253
253
You will sometimes see parentheses used to group functions (instead of being used to group function parameters). Examples of using this style (hereafter referred to as the "function grouping style"):
254
254
255
-
```coffeescript
256
-
($ '#selektor').addClass 'klass'
255
+
```coffeescript
256
+
($'#selektor').addClass'klass'
257
257
258
-
(foo 4).bar 8
259
-
```
258
+
(foo4).bar8
259
+
```
260
260
261
261
This is in contrast to:
262
262
263
-
```coffeescript
264
-
$('#selektor').addClass 'klass'
263
+
```coffeescript
264
+
$('#selektor').addClass'klass'
265
265
266
-
foo(4).bar 8
267
-
```
266
+
foo(4).bar8
267
+
```
268
268
269
269
The correct way to apply the function grouping style when chaining is to use it for the initial call only:
270
270
271
-
```coffeescript
272
-
($ '#selektor').addClass('klass').hide() # Yes
273
-
($ '#selektor').(addClass 'klass').hide() # No
274
-
```
271
+
```coffeescript
272
+
($'#selektor').addClass('klass').hide() # Yes
273
+
($'#selektor').(addClass'klass').hide() # No
274
+
```
275
275
276
276
This guide does not prescribe the use of the function grouping style or the alternative. However, **if the function grouping style is adopted for a particular project, be consistent with its usage.**
277
277
@@ -280,10 +280,10 @@ This guide does not prescribe the use of the function grouping style or the alte
280
280
281
281
Use string interpolation instead of string concatenation:
282
282
283
-
```coffeescript
284
-
"this is an #{adjective} string" # Yes
285
-
"this is an " + adjective + " string" # No
286
-
```
283
+
```coffeescript
284
+
"this is an #{adjective} string"# Yes
285
+
"this is an "+ adjective +" string"# No
286
+
```
287
287
288
288
Prefer single quoted strings (`''`) instead of double quoted (`""`) strings, unless features like string interpolation are being used for the given string.
289
289
@@ -294,33 +294,33 @@ Favor `unless` over `if` for negative conditions.
294
294
295
295
Instead of using `unless...else`, use `if...else`:
296
296
297
-
```coffeescript
298
-
# Yes
299
-
if true
300
-
...
301
-
else
302
-
...
303
-
304
-
# No
305
-
unless false
306
-
...
307
-
else
308
-
...
309
-
```
297
+
```coffeescript
298
+
# Yes
299
+
iftrue
300
+
...
301
+
else
302
+
...
303
+
304
+
# No
305
+
unlessfalse
306
+
...
307
+
else
308
+
...
309
+
```
310
310
311
311
Multi-line if/else clauses should use indentation:
0 commit comments