Make sure the indentation is consistent with the previous level.

This prevents mixing spaces and tabs in the same ‘block’ of code.

Mixing is still allowed if each line uses the same mix and if the indentation level returns to 0.

This breaks the literate coffeescript test that mixes spaces and tabs.
This commit is contained in:
Eelco Lempsink
2016-09-20 23:06:44 +02:00
parent a8b77fb4e7
commit 98068611b1
3 changed files with 41 additions and 1 deletions

View File

@@ -76,7 +76,7 @@ test "#2516: Unicode spaces should not be part of identifiers", ->
eq 5, {c: 5}[ 'c' ]
# A line where every space in non-breaking
  eq 1 + 1, 2  
eq 1 + 1, 2  
test "don't accidentally stringify keywords", ->
ok (-> this == 'this')() is false

View File

@@ -254,3 +254,33 @@ test "#1275: allow indentation before closing brackets", ->
a = 1
)
eq 1, a
test "dont allow mixing of spaces and tabs for indentation", ->
try
CoffeeScript.compile '''
new Layer
x: 0
y: 1
'''
ok no
catch e
eq 'indentation mismatch', e.message
test "indentation can be a mix of spaces and tabs, if each line is the same", ->
doesNotThrow ->
CoffeeScript.compile '''
new Layer
x: 0
y: 1
'''
test "each code block that starts at indentation 0 can use a different style", ->
doesNotThrow ->
CoffeeScript.compile '''
new Layer
x: 0
y: 1
new Layer
x: 0
y: 1
'''