coffeelint 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjgyMzIyZWJlMmU1MjEwZjBhZWRlZDA5M2MyYmEwZWQ4MzU5ZTc0ZQ==
4
+ NWNhOWRlOGVkMDhkMTQwMjFkMTRhYjMwZTQxMTE2MGQxOTkxZjFlMA==
5
5
  data.tar.gz: !binary |-
6
- ZDFiMmUzMzAwOGIzMzZjMDkyNjkzNTRkMzZkYTc1MzZjZDg4NzJkOA==
6
+ NTVlMzA1ZTk2OGU5NDNiY2U2YTU3OTc0MTEyMzcyYTAwZDRhZTMxMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDQxODdhZmMzYTYxNGQyMDUwMzNmYmNhMDc2Y2Y2YmY2NzY0NTA4MWI2Mjg2
10
- ZjZhY2UxMTQxYmJlYjEyMGQyY2Q5NTBlYTE4NGM5MzA4NjMyMWM0OTFkNWVi
11
- NTJlOGYwM2Y3MmJjYTBhMWZiY2FmMWVkYmRhNTRkMGZlYTNlMjE=
9
+ YjBmNzVkZjRmMGJlOTRhOWRjMzJjNTJjZWU4MTE4MWQ2ZWUxOGJiNTRkOGUw
10
+ MDdhODRmYjg3OGU0OTdmMWViYTg5ODEyOWExYTI3ZWUyMjY1YTBiMjk3N2Q0
11
+ MmViOWQzOTc5MTlkOTJhYzE2M2RmZTE1OGFmMGMzY2YwMWM1NWU=
12
12
  data.tar.gz: !binary |-
13
- YThmMTNhMjUzZThhNDZkODk2YzA3NzRlZTg0YmI2OGUzODkzY2JiYWQ2NjA0
14
- ZGRkNjYzOWUyZmU1YThjYmEyNDE2OGY1ODMzZmY0NzJiODNhOTBmN2I4MDE2
15
- Y2I2ZjY2ZTRmM2NlYjZlNzFhYTg1ZDI2YmVkNmMxMWMzYjA0ZDU=
13
+ YmViOTViODYyOWMxNDg0YTVhZDAyNmRjMTkzZGI0NDY0ZDk5OGU1NDE4NTQ4
14
+ ZmExMWUyYTVkZDVjYmRiZGQ5OGM5MzFmOTkyODY5YzExYzA4NTMzMTcwZjNl
15
+ YTU3YjdhMjMxN2ExZThkNTY4NzhkMDc3MTRhYmUzNjE1NmY4OGY=
data/README.md CHANGED
@@ -45,8 +45,8 @@ Which will run the test on any *.coffee file in your `app` or `spec` directories
45
45
 
46
46
  Finally, there is a command line utility that allows you to run standalone tests:
47
47
 
48
- coffeelint <filename>
49
- coffeelint -r <directory>
48
+ coffeelint.rb <filename>
49
+ coffeelint.rb -r <directory>
50
50
 
51
51
  ## Contributing
52
52
 
File without changes
@@ -96,6 +96,10 @@ coffeelint.RULES = RULES =
96
96
  level : IGNORE
97
97
  message : 'Invoking a constructor without parens and without arguments'
98
98
 
99
+ non_empty_constructor_needs_parens :
100
+ level : IGNORE
101
+ message : 'Invoking a constructor without parens and with arguments'
102
+
99
103
  no_empty_param_list :
100
104
  level : IGNORE
101
105
  message : 'Empty parameter list is forbidden'
@@ -121,6 +125,10 @@ coffeelint.RULES = RULES =
121
125
  level : IGNORE
122
126
  message : '@ must not be used stand alone'
123
127
 
128
+ arrow_spacing :
129
+ level : IGNORE
130
+ message : 'Function arrow (->) must be spaced properly'
131
+
124
132
  coffeescript_error :
125
133
  level : ERROR
126
134
  message : '' # The default coffeescript error is fine.
@@ -402,15 +410,19 @@ class LexicalLinter
402
410
  lintToken : (token) ->
403
411
  [type, value, lineNumber] = token
404
412
 
405
- lineNumber = lineNumber.first_line if lineNumber?.first_line?
413
+ if typeof lineNumber == "object"
414
+ if type == 'OUTDENT' or type == 'INDENT'
415
+ lineNumber = lineNumber.last_line
416
+ else
417
+ lineNumber = lineNumber.first_line
406
418
  @tokensByLine[lineNumber] ?= []
407
419
  @tokensByLine[lineNumber].push(token)
408
420
  # CoffeeScript loses line numbers of interpolations and multi-line
409
421
  # regexes, so fake it by using the last line number we know.
410
422
  @lineNumber = lineNumber or @lineNumber or 0
411
-
412
423
  # Now lint it.
413
424
  switch type
425
+ when "->" then @lintArrowSpacing(token)
414
426
  when "INDENT" then @lintIndentation(token)
415
427
  when "CLASS" then @lintClass(token)
416
428
  when "UNARY" then @lintUnary(token)
@@ -430,14 +442,18 @@ class LexicalLinter
430
442
  else null
431
443
 
432
444
  lintUnary: (token) ->
433
- if token[1] is 'new'
434
- expectedIdentifier = @peek(1)
435
- # The callStart is generated if your parameters are on the next line
436
- # but is missing if there are no params and no parens.
437
- expectedCallStart = @peek(2)
438
- if expectedIdentifier?[0] is 'IDENTIFIER' and
439
- expectedCallStart?[0] isnt 'CALL_START'
440
- @createLexError('empty_constructor_needs_parens')
445
+ if token[1] is 'new'
446
+ expectedIdentifier = @peek(1)
447
+ # The callStart is generated if your parameters are all on the same
448
+ # line with implicit parens, and if your parameters start on the
449
+ # next line, but is missing if there are no params and no parens.
450
+ expectedCallStart = @peek(2)
451
+ if expectedIdentifier?[0] is 'IDENTIFIER' and expectedCallStart?
452
+ if expectedCallStart[0] is 'CALL_START'
453
+ if expectedCallStart.generated
454
+ @createLexError('non_empty_constructor_needs_parens')
455
+ else
456
+ @createLexError('empty_constructor_needs_parens')
441
457
 
442
458
  # Lint the given array token.
443
459
  lintArray : (token) ->
@@ -673,6 +689,27 @@ class LexicalLinter
673
689
  else
674
690
  null
675
691
 
692
+ lintArrowSpacing : (token) ->
693
+ # Throw error unless the following happens.
694
+
695
+ # We will take a look at the previous token to see
696
+ # 1. That the token is properly spaced
697
+ # 2. Wasn't generated by the CoffeeScript compiler
698
+ # 3. That it is just indentation
699
+ # 4. If the function declaration has no parameters
700
+ # e.g. x(-> 3)
701
+ # x( -> 3)
702
+ # we will accept either having a space or not having a space there.
703
+ unless (token.spaced? or token.newLine?) and
704
+ # Throw error unless the previous token...
705
+ (@peek(-1).spaced? or #1
706
+ @peek(-1).generated? or #2
707
+ @peek(-1)[0] is "INDENT" or #3
708
+ (@peek(-1)[0] is "CALL_START" and not @peek(-1).generated?)) #4
709
+ @createLexError('arrow_spacing')
710
+ else
711
+ null
712
+
676
713
  createLexError : (rule, attrs = {}) ->
677
714
  attrs.lineNumber = @lineNumber + 1
678
715
  attrs.level = @config[rule].level
@@ -768,8 +805,11 @@ class ASTLinter
768
805
 
769
806
  # Parse the line number
770
807
  lineNumber = -1
771
- match = /line (\d+)/.exec message
772
- lineNumber = parseInt match[1], 10 if match?.length > 1
808
+ if coffeeError.location?
809
+ lineNumber = coffeeError.location.first_line + 1
810
+ else
811
+ match = /line (\d+)/.exec message
812
+ lineNumber = parseInt match[1], 10 if match?.length > 1
773
813
  attrs = {
774
814
  message: message
775
815
  level: rule.level
@@ -1,3 +1,3 @@
1
1
  module Coffeelint
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffeelint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Bush
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-07 00:00:00.000000000 Z
11
+ date: 2013-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-script
@@ -56,7 +56,7 @@ description: Ruby bindings for coffeelint
56
56
  email:
57
57
  - zach@zmbush.com
58
58
  executables:
59
- - coffeelint
59
+ - coffeelint.rb
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
@@ -66,7 +66,7 @@ files:
66
66
  - LICENSE.txt
67
67
  - README.md
68
68
  - Rakefile
69
- - bin/coffeelint
69
+ - bin/coffeelint.rb
70
70
  - coffeelint.gemspec
71
71
  - lib/coffeelint.rb
72
72
  - lib/coffeelint/railtie.rb