-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I257b82c0bc5cdaed215579def77074cea8084deb Reviewed-on: http://gerrit.causes.com/47624 Tested-by: jenkins <jenkins@brigade.com> Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module HamlLint | ||
# Checks scripts spread over multiple lines. | ||
class Linter::MultilineScript < Linter | ||
include LinterRegistry | ||
|
||
# List of operators that can split a script into two lines that we want to | ||
# alert on. | ||
SPLIT_OPERATORS = %w[ | ||
|| or && and | ||
||= &&= | ||
^ << >> | & | ||
<<= >>= |= &= | ||
+ - * / ** % | ||
+= -= *= /= **= %= | ||
< <= <=> >= > | ||
= == === != =~ !~ | ||
.. ... | ||
? : | ||
not | ||
if unless while until | ||
begin | ||
].to_set | ||
|
||
def visit_script(node) | ||
check(node) | ||
end | ||
|
||
def visit_silent_script(node) | ||
check(node) | ||
end | ||
|
||
private | ||
|
||
def check(node) | ||
operator = node.script[/\s+(\S+)\z/, 1] | ||
if SPLIT_OPERATORS.include?(operator) | ||
add_lint(node, | ||
"Script with trailing operator `#{operator}` should be " \ | ||
'merged with the script on the following line') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
describe HamlLint::Linter::MultilineScript do | ||
include_context 'linter' | ||
|
||
context 'when silent script is split with a Boolean operator' do | ||
let(:haml) { <<-HAML } | ||
- if condition || | ||
- true | ||
Result | ||
HAML | ||
|
||
it { should report_lint line: 1 } | ||
end | ||
|
||
context 'when silent script is split with an equality operator' do | ||
let(:haml) { <<-HAML } | ||
- if condition == | ||
- something | ||
Result | ||
HAML | ||
|
||
it { should report_lint line: 1 } | ||
end | ||
|
||
context 'when script is split with a binary operator' do | ||
let(:haml) { <<-HAML } | ||
= 1 + | ||
= 2 | ||
HAML | ||
|
||
it { should report_lint line: 1 } | ||
end | ||
end |