-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1669 lines (1617 loc) · 76.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>CoffeeLint - Lint your CoffeeScript</title>
<link rel="stylesheet" type="text/css" href="css/coffeelint.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
<!-- HEADER -->
<div class="header">
<div class="container">
<h1 class="title">
CoffeeLint
<span class="version"></span>
</h1>
<ul class="header_links">
<li><a href="#overview">Overview</a></li>
<li><a href="#install">Install</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="#options">Options</a></li>
<li><a href="#api">API</a></li>
<li><a href="#plugins">Plugins</a></li>
<li><a href="#about">About</a></li>
<li><a href="#changelog">Change Log</a></li>
<li><a href="https://github.com/coffeelint/coffeelint">Source</a></li>
</ul>
</div>
</div>
<div class="container">
<!-- EDITOR -->
<div class="row editor_row configuration_row">
<div class="run">Run</div>
<textarea class="editor run_editor" spellcheck="false">
# Lint your CoffeeScript!
class Gangster
wasItAGoodDay : () ->
yes
</textarea>
</div>
<div class="row editor_row">
<div class="configuration">Configuration</div>
<div class="config_editor_toggle">
<textarea class="editor config_editor" spellcheck="false"></textarea>
</div>
</div>
<!-- LINT REPORT -->
<div class="row report_row">
<div class="report_container section_container">
<div class="report">
<h1 class="section_title"></h1>
<div class="section_body"></div>
</div>
</div>
</div>
<!-- DOCUMENTATION -->
<div class="row doc_row">
<section>
<h2 class="section_title" id="overview">Overview</h2>
<div class="paragraph">
CoffeeLint is a style checker that helps keep
<a href="https://coffeescript.org">CoffeeScript</a>
code clean and consistent. CoffeeScript does a great job at
insulating programmers from many of JavaScript's bad parts, but it
won't help enforce a consistent style across a code base. CoffeeLint
can help with that.
</div>
<div class="paragraph">
If you have an idea, a bug report or anything else to say, reach out
on the
<a href="https://github.com/coffeelint/coffeelint/issues"
>issues page</a
>.
</div>
</section>
<section>
<h2 class="section_title" id="install">Installation</h2>
<div class="paragraph">
To install, make sure you have a working version of the latest
stable version of <a href="https://nodejs.org/">Node</a> and
<a href="https://npmjs.org/">NPM</a> (the Node Package Manager) and
then run:
</div>
<code>npm install -g @coffeelint/cli</code>
<div class="paragraph">
Remove the <tt>-g</tt> if you do not want to install globally.
</div>
</section>
<section>
<h2 class="section_title">Getting Started</h2>
<ul>
<li>
<a
href="https://github.com/coffeelint/coffeelint/blob/master/doc/user.md"
>Users</a
>
</li>
<li>
<a
href="https://github.com/coffeelint/coffeelint/blob/master/doc/integration.md"
>Plugin Developers</a
>
</li>
</ul>
</section>
<section>
<h2 class="section_title" id="usage">Usage</h2>
<div class="paragraph">
Once you have Coffeelint installed, to lint your scripts, run:
</div>
<code>coffeelint application.coffee</code>
<div class="paragraph">
To specify your own configuration file, do the following:
</div>
<code>coffeelint -f coffeelint.json application.coffee</code>
<div class="paragraph">
If any errors were found, a non-zero code will be returned.
</div>
<div class="paragraph">To generate a configuration file, do</div>
<code>coffeelint --makeconfig > coffeelint.json</code>
<div class="paragraph">
You can then configure the rules to your liking.
</div>
<div class="paragraph">
New in 1.0: CoffeeLint will automatically pick up config files. When
linting a file (as opposed to stdin) it will walk up the directory
tree looking for a coffeelint.json or a package.json that has a
"coffeelintConfig" object. If neither of those are found or you're
linting from stdin it will check your home for a coffeelint.json
file.
</div>
</section>
<section>
<h2 class="section_title" id="options">Options</h2>
<div class="paragraph">
By default, CoffeeLint will help ensure you are writing idiomatic
CoffeeScript, but every rule is optional and configurable so it can
be tuned to fit your preferred coding style. To override any of
CoffeeLint's default options,
<a href="#usage">generate a configuration file</a> and tweak it as
needed. To enable an option, set its level to <tt>error</tt>, and to
disable an option, set its level to <tt>ignore</tt>. If you set the
level to <tt>warn</tt>, violations will be reported, but won't cause
a non-zero exit code.
</div>
<div class="paragraph">
To disable a rule inline use the following:
</div>
<pre><code>
# coffeelint: disable=max_line_length
foo = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width"
# coffeelint: enable=max_line_length
</code></pre>
<div class="paragraph">
You can also disable all checks for a single line by appending
<tt># noqa</tt> at the end of the line:
</div>
<code>
throw "I should be an Error not a string but YOLO" # noqa
</code>
<div class="paragraph">Here's a rundown of CoffeeLint's rules:</div>
<table class="options">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="rule">arrow_spacing</td>
<td class="description">
<p>This rule checks to see that there is spacing before and after
the arrow operator that declares a function. This rule is disabled
by default.</p> <p>Note that if arrow_spacing is enabled, and you
pass an empty function as a parameter, arrow_spacing will accept
either a space or no space in-between the arrow operator and the
parenthesis</p>
<pre><code># Both of this will not trigger an error,
# even with arrow_spacing enabled.
x(-> 3)
x( -> 3)
# However, this will trigger an error
x((a,b)-> 3)
</code>
</pre>
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">braces_spacing</td>
<td class="description">
This rule checks to see that there is the proper spacing inside
curly braces. The spacing amount is specified by "spaces".
The spacing amount for empty objects is specified by
"empty_object_spaces".
The spacing amount for objects containing a single item is
specified by "mono_object_spaces".
<pre><code>
# Spaces is 0
{a: b} # Good
{a: b } # Bad
{ a: b} # Bad
{ a: b } # Bad
# Spaces is 1
{a: b} # Bad
{a: b } # Bad
{ a: b} # Bad
{ a: b } # Good
{ a: b } # Bad
{ a: b } # Bad
{ a: b } # Bad
# Empty Object Spaces is 0
{} # Good
{ } # Bad
# Empty Object Spaces is 1
{} # Bad
{ } # Good
# Mono Object Spaces is 0
{a} # Good
{ a } # Bad
# Mono Object Spaces is 1
{a} # Bad
{ a } # Good
</code></pre>
This rule is disabled by default.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">bracket_spacing</td>
<td class="description">
This rule checks to see that there is the proper spacing inside
square brackets. The spacing amount is specified by "spaces".
The spacing amount for empty arrays is specified by
"empty_array_spaces".
The spacing amount for arrays containing a single item is
specified by "mono_array_spaces".
Specified characters will be ignored if listed in "exceptions".
<pre><code>
# Spaces is 0
[a, b] # Good
[a, b ] # Bad
[ a, b] # Bad
[ a, b ] # Bad
# Except brackets
[ [a, b] ] # Good
[[ a, b ]] # Bad
# Spaces is 1
[a, b] # Bad
[a, b ] # Bad
[ a, b] # Bad
[ a, b ] # Good
[ a, b ] # Bad
[ a, b ] # Bad
[ a, b ] # Bad
# Except braces
[{ a: b }] # Good
[ {a: b} ] # Bad
# Empty Array Spaces is 0
[] # Good
[ ] # Bad
# Empty Array Spaces is 1
[] # Bad
[ ] # Good
# Mono Array Spaces is 0
[a] # Good
[ a ] # Bad
# Mono Array Spaces is 1
[a] # Bad
[ a ] # Good
</code></pre>
This rule is disabled by default.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">camel_case_classes</td>
<td class="description">
This rule mandates that all class names are UpperCamelCased.
Camel casing class names is a generally accepted way of
distinguishing constructor functions - which require the 'new'
prefix to behave properly - from plain old functions.
<pre>
<code># Good!
class BoaConstrictor
# Bad!
class boaConstrictor
</code>
</pre>
This rule is enabled by default.
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">coffeescript_error</td>
<td class="description">
[no description provided]
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">colon_assignment_spacing</td>
<td class="description">
<p>This rule checks to see that there is spacing before and
after the colon in a colon assignment (i.e., classes, objects).
The spacing amount is specified by
spacing.left and spacing.right, respectively.
A zero value means no spacing required.
</p>
<pre><code>
#
# If spacing.left and spacing.right is 1
#
# Doesn't throw an error
object = {spacing : true}
class Dog
canBark : true
# Throws an error
object = {spacing: true}
class Cat
canBark: false
</code></pre>
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">cyclomatic_complexity</td>
<td class="description">
Examine the complexity of your function.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">duplicate_key</td>
<td class="description">
Prevents defining duplicate keys in object literals and classes
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">empty_constructor_needs_parens</td>
<td class="description">
Requires constructors with no parameters to include the parens
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">ensure_comprehensions</td>
<td class="description">
This rule makes sure that parentheses are around comprehensions.
<p><em>default level: warn</em></p>
</td>
</tr>
<tr>
<td class="rule">eol_last</td>
<td class="description">
Checks that the file ends with a single newline
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">indentation</td>
<td class="description">
This rule imposes a standard number of spaces(tabs) to be used for
indentation. Since whitespace is significant in CoffeeScript, it's
critical that a project chooses a standard indentation format and
stays consistent. Other roads lead to darkness. <pre> <code>#
Enabling this option will prevent this ugly
# but otherwise valid CoffeeScript.
twoSpaces = () ->
fourSpaces = () ->
eightSpaces = () ->
'this is valid CoffeeScript'
</code>
</pre>
Two space indentation is enabled by default.
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">line_endings</td>
<td class="description">
This rule ensures your project uses only <tt>windows</tt> or
<tt>unix</tt> line endings. This rule is disabled by default.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">max_line_length</td>
<td class="description">
This rule imposes a maximum line length on your code. <a
href="https://www.python.org/dev/peps/pep-0008/">Python's style
guide</a> does a good job explaining why you might want to limit the
length of your lines, though this is a matter of taste.
Lines can be no longer than eighty characters by default.
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">missing_fat_arrows</td>
<td class="description">
Warns when you use `this` inside a function that wasn't defined
with a fat arrow. This rule does not apply to methods defined in a
class, since they have `this` bound to the class instance (or the
class itself, for class methods). The option `is_strict` is
available for checking bindings of class methods.
It is impossible to statically determine whether a function using
`this` will be bound with the correct `this` value due to language
features like `Function.prototype.call` and
`Function.prototype.bind`, so this rule may produce false positives.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">missing_parseint_radix</td>
<td class="description">
This rule warns about using parseInt without a radix. From the MDN
developers reference: <q>Always specify this parameter to eliminate
reader confusion and to guarantee predictable behavior.</q>
<pre>
<code># You would expect this to result in 8, but
# it might result in 0 (parsed as octal).
parseInt '08'
# To be safe, specify the radix argument:
parseInt '08', 10
</code>
</pre>
<p><em>default level: warn</em></p>
</td>
</tr>
<tr>
<td class="rule">newlines_after_classes</td>
<td class="description">
<p>Checks the number of blank lines between classes and other code.</p>
Options:
- <pre><code>value</code></pre> - The number of required blank lines
after class definitions. Defaults to 3.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_backticks</td>
<td class="description">
Backticks allow snippets of JavaScript to be embedded in
CoffeeScript. While some folks consider backticks useful in a few
niche circumstances, they should be avoided because so none of
JavaScript's "bad parts", like <tt>with</tt> and <tt>eval</tt>,
sneak into CoffeeScript.
This rule is enabled by default.
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">no_debugger</td>
<td class="description">
This rule detects `debugger` and optionally `console` calls
This rule is `warn` by default.
<p><em>default level: warn</em></p>
</td>
</tr>
<tr>
<td class="rule">no_empty_functions</td>
<td class="description">
Disallows declaring empty functions. The goal of this rule is that
unintentional empty callbacks can be detected:
<pre>
<code>someFunctionWithCallback ->
doSomethingSignificant()
</code>
</pre>
The problem is that the call to
<tt>doSomethingSignificant</tt> will be made regardless
of <tt>someFunctionWithCallback</tt>'s execution. It can
be because you did not indent the call to
<tt>doSomethingSignificant</tt> properly.
If you really meant that <tt>someFunctionWithCallback</tt>
should call a callback that does nothing, you can write your code
this way:
<pre>
<code>someFunctionWithCallback ->
undefined
doSomethingSignificant()
</code>
</pre>
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_empty_param_list</td>
<td class="description">
This rule prohibits empty parameter lists in function definitions.
<pre>
<code># The empty parameter list in here is unnecessary:
myFunction = () ->
# We might favor this instead:
myFunction = ->
</code>
</pre>
Empty parameter lists are permitted by default.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_implicit_braces</td>
<td class="description">
This rule prohibits implicit braces when declaring object literals.
Implicit braces can make code more difficult to understand,
especially when used in combination with optional parenthesis.
<pre>
<code># Do you find this code ambiguous? Is it a
# function call with three arguments or four?
myFunction a, b, 1:2, 3:4
# While the same code written in a more
# explicit manner has no ambiguity.
myFunction(a, b, {1:2, 3:4})
</code>
</pre>
Implicit braces are permitted by default, since their use is
idiomatic CoffeeScript.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_implicit_parens</td>
<td class="description">
This rule prohibits implicit parens on function calls.
<pre>
<code># Some folks don't like this style of coding.
myFunction a, b, c
# And would rather it always be written like this:
myFunction(a, b, c)
</code>
</pre>
Implicit parens are permitted by default, since their use is
idiomatic CoffeeScript.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_interpolation_in_single_quotes</td>
<td class="description">
This rule prohibits string interpolation in a single quoted string.
<pre>
<code># String interpolation in single quotes is not allowed:
foo = '#{bar}'
# Double quotes is OK of course
foo = "#{bar}"
</code>
</pre>
String interpolation in single quoted strings is permitted by
default.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_nested_string_interpolation</td>
<td class="description">
This rule warns about nested string interpolation,
as it tends to make code harder to read and understand.
<pre>
<code># Good!
str = "Book by #{firstName.toUpperCase()} #{lastName.toUpperCase()}"
# Bad!
str = "Book by #{"#{firstName} #{lastName}".toUpperCase()}"
</code>
</pre>
<p><em>default level: warn</em></p>
</td>
</tr>
<tr>
<td class="rule">no_plusplus</td>
<td class="description">
This rule forbids the increment and decrement arithmetic operators.
Some people believe the <tt>++</tt> and <tt>--</tt> to be cryptic
and the cause of bugs due to misunderstandings of their precedence
rules.
This rule is disabled by default.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_private_function_fat_arrows</td>
<td class="description">
Warns when you use the fat arrow for a private function
inside a class definition scope. It is not necessary and
it does not do anything.
<p><em>default level: warn</em></p>
</td>
</tr>
<tr>
<td class="rule">no_spaces</td>
<td class="description">
This rule forbids spaces in indentation. It is disabled by default.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_stand_alone_at</td>
<td class="description">
This rule checks that no stand alone @ are in use, they are
discouraged. Further information in CoffeeScript issue <a
href="https://github.com/jashkenas/coffee-script/issues/1601">
#1601</a>
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_tabs</td>
<td class="description">
This rule forbids tabs in indentation. Enough said. It is enabled by
default.
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">no_this</td>
<td class="description">
This rule prohibits 'this'.
Use '@' instead.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_throwing_strings</td>
<td class="description">
This rule forbids throwing string literals or interpolations. While
JavaScript (and CoffeeScript by extension) allow any expression to
be thrown, it is best to only throw <a
href="https://developer.mozilla.org
/en/JavaScript/Reference/Global_Objects/Error"> Error</a> objects,
because they contain valuable debugging information like the stack
trace. Because of JavaScript's dynamic nature, CoffeeLint cannot
ensure you are always throwing instances of <tt>Error</tt>. It will
only catch the simple but real case of throwing literal strings.
<pre>
<code># CoffeeLint will catch this:
throw "i made a boo boo"
# ... but not this:
throw getSomeString()
</code>
</pre>
This rule is enabled by default.
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">no_trailing_semicolons</td>
<td class="description">
This rule prohibits trailing semicolons, since they are needless
cruft in CoffeeScript.
<pre>
<code># This semicolon is meaningful.
x = '1234'; console.log(x)
# This semicolon is redundant.
alert('end of line');
</code>
</pre>
Trailing semicolons are forbidden by default.
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">no_trailing_whitespace</td>
<td class="description">
This rule forbids trailing whitespace in your code, since it is
needless cruft. It is enabled by default.
<p><em>default level: error</em></p>
</td>
</tr>
<tr>
<td class="rule">no_unnecessary_double_quotes</td>
<td class="description">
This rule prohibits double quotes unless string interpolation is
used or the string contains single quotes.
<pre>
<code># Double quotes are discouraged:
foo = "bar"
# Unless string interpolation is used:
foo = "#{bar}baz"
# Or they prevent cumbersome escaping:
foo = "I'm just following the 'rules'"
</code>
</pre>
Double quotes are permitted by default.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">no_unnecessary_fat_arrows</td>
<td class="description">
Disallows defining functions with fat arrows when `this`
is not used within the function.
<p><em>default level: warn</em></p>
</td>
</tr>
<tr>
<td class="rule">non_empty_constructor_needs_parens</td>
<td class="description">
Requires constructors with parameters to include the parens
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">object_shorthand</td>
<td class="description">
<p>Use property value shorthand in objects, when explicit braces are used.</p>
<pre><code>test = "value"
# Good
{test}
test: test
# Bad
{test: test}
</code></pre>
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">prefer_english_operator</td>
<td class="description">
This rule prohibits &&, ||, ==, != and !.
Use and, or, is, isnt, and not instead.
!! for converting to a boolean is ignored.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">prefer_fat_arrows_in_methods</td>
<td class="description">
Warns when you do not use a fat arrow for functions defined inside
method bodies. This assures that `this` is always bound to the
method's object inside the code block of a method.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">prefer_logical_operator</td>
<td class="description">
This rule prohibits is, isnt, not, and, or, yes, on, no, off.
Use ==, !=, !, &&, ||, true, false instead.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">space_operators</td>
<td class="description">
This rule enforces that operators have space around them.
Optionally, you can set `default_parameters` to `false` to
require no space around `=` when used to define default paramaters.
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">spacing_after_comma</td>
<td class="description">
This rule checks to make sure you have a space after commas.
Consecutive commas are allowed when skipping array elements
if "ignore_elision" is true.
<pre><code>
# ignore_elision: true
[,, c,, e, f] = [1, 2, 3, 4, 5, 6]
</code></pre>
<p><em>default level: ignore</em></p>
</td>
</tr>
<tr>
<td class="rule">transform_messes_up_line_numbers</td>
<td class="description">
This rule detects when changes are made by transform function,
and warns that line numbers are probably incorrect.
<p><em>default level: warn</em></p>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2 class="section_title" id="api">API</h2>
<div class="paragraph">
If you'd like to run CoffeeScript in the browser or any other
Javascript runtime, include
<a
href="https://coffeescript.org/browser-compiler-legacy/coffeescript.js"
>coffee-script.js</a
>
and
<a href="https://coffeelint.github.io/js/coffeelint.js"
>coffeelint.js</a
>
and you're off to the races. Then you can call CoffeeLint directly
with the following API:
</div>
<h3 class="api_call">coffeelint.lint(source, configuration)</h3>
<div class="paragraph">
Lints the CoffeeScript source with the given configuration and
returns an array of lint errors and warnings. If the array is empty,
all is well. Compile time errors will be thrown. An error is a
Javascript object with the following properties:
</div>
<pre><code>
{
rule : 'Name of the violated rule',
lineNumber: 'Number of the line that caused the violation',
level: 'The severity level of the violated rule',
message: 'Information about the violated rule',
context: 'Optional details about why the rule was violated'
}
</code></pre>
<h3 class="api_call">coffeelint.registerRule(RuleConstructor)</h3>
<div class="paragraph">
Registers a custom rule that may be run by CoffeeLint. If the rule
is ignored by default it will still require overriding it's level
just like the default rules. They have actually all be
re-implemented as pluggable rules that come bundled in CoffeeLint.
</div>
</section>
<section>
<h2 class="section_title" id="loading-custom-rules">
Loading Custom Rules
</h2>
<div class="paragraph">
Not every possible rule will be included in the CoffeeLint project.
Maybe it's very specific to your project, or it's not specific to
CoffeeScript.
</div>
<div class="paragraph">
By convention rule authors add the keyword
<tt>coffeelintrule</tt> to their npm package.json so custom rules
can be found easily. Click
<a href="https://npmjs.org/search?q=coffeelintrule">here</a> to list
all currently available custom rules on npm.
</div>
<div class="paragraph">
For example, maybe you want to get a warning if you don't have a
newline at the end of your files. We'll imagine you globally
installed the package
<a href="https://www.npmjs.com/package/coffeelint-newline-at-eof"
>"coffeelint-newline-eof"</a
>.
</div>
<!-- Found this example at https://github.com/clutchski/coffeelint/pull/79 -->
<pre><code>
{
// This name MUST match the default configuration of the rule being loaded.
"newline_at_eof": {
// NodeJS module to load. It can also be a path to the rule (useful for devleopment)
"module": "coffeelint-newline-at-eof",
// Maybe the rule author set it to error by default and you only want a warning.
"level": "warn"
}
}
</code></pre>
<div class="paragraph">
Now every time you run CoffeeLint it will load that rule and
override it's default level to "warn".
</div>
</section>
<section>
<h2 class="section_title" id="building-custom-rules">
Building Custom Rules
</h2>
<div class="paragraph">
CoffeeLint has three types of linters that run. In no particular
order they are.
<ul>
<li>
LineLinter: processes one line at a time, usually with regular
expressions
</li>
<li>
TokenLinter: processes the token stream generated by
CoffeeScript.
</li>
<li>
ASTLinter: Processes the Abstract Syntax Tree. AST rules are
only called with the root node and it is up to the rule to
recurse the tree.
</li>
</ul>
</div>
<div class="paragraph">
Rules may be loaded using
<code>--rules /path/to/rules/</code>
or
<code>coffeelint.registerRule(RuleConstructor)</code>
when outside of the CLI.
</div>
<div class="paragraph">
Rules do not have to be written in CoffeeScript. A new instance of
each rule is constructed for each file, so the RuleConstructor must
be a constructor function that generates a new clean instance of
your rule when the new operator is used.
</div>
<div class="paragraph">
Your rule instance must have a .rule attribute with it's default
configuration. "name", "level" "message", and "description" are all
required. "level" must be one of 'ignore', 'warn', or 'error'. Once
you have a valid rule configuration CoffeeLint requires you to
implement one function depending on which type of linter your rule
needs.
<pre><code>
lintLine(line, lineApi)
lintToken(token, tokenApi)
lintAST(ast, astApi)
</code></pre>
The second parameter of each is an object with helper functions.
It's best to just check the source or look at how other plugins are
using those.
</div>
<div class="paragraph">
If your function returns true it will generate an error. If you need
to override how the error is generated, maybe providing a context
attribute, you can return an object that will get mixed into the
generated error. The
<a
href="https://github.com/coffeelint/coffeelint/blob/master/src/rules/no_plusplus.coffee"
>No_PlusPlus</a
>
rule is a simple example of this.
</div>
<div class="paragraph">
The core rules have been rewritten as stand alone rules both to
prove the system and provide examples of how to write rules. To get
started
<a
href="https://github.com/coffeelint/coffeelint/blob/master/src/rules/no_plusplus.coffee"
>no_plusplus</a
>
is a Token rule,
<a
href="https://github.com/coffeelint/coffeelint/blob/master/src/rules/no_tabs.coffee"
>no_tabs</a
>
is a Line rule, and
<a
href="https://github.com/coffeelint/coffeelint/blob/master/src/rules/cyclomatic_complexity.coffee"
>cyclomatic_complexity</a
>
is an AST rule.
</div>
<div class="paragraph">
The <tt>--rules</tt> option will load every .js or .coffee file it
finds and assume they export the RuleConstructor. Since the browser
doesn't have a standard export system it's up to you to determine
how you'll load your plugin and register it with
<tt>coffeelint.registerRule</tt>
</div>
</section>
<section>
<h2 class="section_title" id="plugins">Plugins</h2>
<div class="paragraph">
Some nice folks have coded up some cool CoffeeLint plugins for
editors and build systems. Check them out: