This repository has been archived by the owner on Oct 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathtest_no_implicit_parens.coffee
149 lines (121 loc) · 4.24 KB
/
test_no_implicit_parens.coffee
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
path = require 'path'
vows = require 'vows'
assert = require 'assert'
coffeelint = require path.join('..', 'lib', 'coffeelint')
RULE = 'no_implicit_parens'
vows.describe(RULE).addBatch({
'Implicit parens':
topic:
'''
console.log 'implict parens'
blah = (a, b) ->
blah 'a', 'b'
class A
@configure(1, 2, 3)
constructor: ->
class B
_defaultC = 5
constructor: (a) ->
@c = a ? _defaultC
'''
'are allowed by default': (source) ->
errors = coffeelint.lint(source)
assert.isArray(errors)
assert.isEmpty(errors)
'can be forbidden': (source) ->
config = no_implicit_parens: { level: 'error' }
errors = coffeelint.lint(source, config)
assert.isArray(errors)
assert.lengthOf(errors, 2)
error = errors[0]
assert.equal(error.lineNumber, 1)
assert.equal(error.message, 'Implicit parens are forbidden')
assert.equal(error.rule, RULE)
'No implicit parens strict':
topic:
'''
blah = (a) ->
blah
foo: 'bar'
blah = (a, b) ->
blah 'a'
, 'b'
'''
'blocks all implicit parens by default': (source) ->
config = no_implicit_parens: { level: 'error' }
errors = coffeelint.lint(source, config)
assert.isArray(errors)
assert.lengthOf(errors, 2)
assert.equal(rule, RULE) for { rule } in errors
'allows parens at the end of lines when strict is false': (source) ->
config =
no_implicit_parens:
level: 'error'
strict: false
errors = coffeelint.lint(source, config)
assert.isArray(errors)
assert.isEmpty(errors)
'Nested no implicit parens strict':
topic:
'''
blah = (a) ->
blah
foo: blah('a')
blah = (a, b) ->
blah 'a'
, blah('c', 'd')
blah 'a'
, (blah 'c'
, 'd')
'''
'blocks all implicit parens by default': (source) ->
config = no_implicit_parens: { level: 'error' }
errors = coffeelint.lint(source, config)
assert.isArray(errors)
assert.lengthOf(errors, 4)
assert.equal(rule, RULE) for { rule } in errors
'allows parens at the end of lines when strict is false': (source) ->
config =
no_implicit_parens:
level: 'error'
strict: false
errors = coffeelint.lint(source, config)
assert.isArray(errors)
assert.isEmpty(errors)
'Test for when implicit parens are on the last line':
topic:
'''
class Something
constructor: ->
return $ '#something'
yo: ->
class AnotherSomething
constructor: ->
return $ '#something'
blah 'a'
, blah('c', 'd')
'''
'throws three errors when strict is true': (source) ->
config =
no_implicit_parens:
level: 'error'
strict: true
errors = coffeelint.lint(source, config)
assert.isArray(errors)
assert.lengthOf(errors, 3)
assert.equal(errors[0].rule, RULE)
assert.equal(errors[1].rule, RULE)
assert.equal(errors[2].rule, RULE)
# When implicit parens are separated out on multiple lines
# and strict is set to false, do not return an error.
'throws two errors when strict is false': (source) ->
config =
no_implicit_parens:
level: 'error'
strict: false
errors = coffeelint.lint(source, config)
assert.isArray(errors)
assert.lengthOf(errors, 2)
assert.equal(errors[0].rule, RULE)
assert.equal(errors[1].rule, RULE)
}).export(module)