Skip to content

Commit

Permalink
Add indent updates
Browse files Browse the repository at this point in the history
  • Loading branch information
greeneca committed Sep 19, 2019
1 parent 1a09ea1 commit 05cc087
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
= 4.20.1 =

-Add indent-ignore and indent-reset comment processing to analyzer

= 4.20.0 =

- Add file size warning
Expand Down
56 changes: 30 additions & 26 deletions lib/roku_builder/plugins/indentation_inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def initialize(rules:, path:)
end

def check_line(line:, number:)
#byebug if number == 191 and @path.ends_with?("EpisodeGuide.animation.brs")
#byebug if number == 43 and @path.ends_with?("keyEvents.brs")
set_indentation(line: line)
regexp = /^#{@character}{#{@ind}}[^#{@character}]/
unless line =~ regexp or line == "\n"
unless line =~ regexp or line == "\n" or line =~ /\'indent-ignore/
add_warning(line: number)
end
@prev_line = line
Expand All @@ -37,33 +37,37 @@ def set_indentation(line:)
end
end
when :brs
if @prev_line
if @prev_line =~ /^\'/
# Don't change indentation
elsif @prev_line =~ /[\{\[\(:]$/
@ind += @count
elsif @prev_line =~ /:\s*\bfunction\b|:\s*\bsub\b/i
@ind += @count
elsif @prev_line =~ /^\s*\bfunction\b|^\s*\bsub\b/i
@ind += @count
elsif @prev_line =~ /^\s*#?if\b|^\s*#?else\b/i
unless @prev_line =~ /\bthen\b[ \t ]*[^' \r\n']+.*$/i or @prev_line =~ /\breturn\b/i
if line =~ /'indent-reset/
@ind = line.index(/[^#{@character}]/)
else
if @prev_line
if @prev_line =~ /^\'/ or @prev_line =~ /\'indent-ignore/
# Don't change indentation
elsif @prev_line =~ /[\{\[\(:]$/
@ind += @count
elsif @prev_line =~ /:\s*\bfunction\b|:\s*\bsub\b/i
@ind += @count
elsif @prev_line =~ /^\s*\bfunction\b|^\s*\bsub\b/i
@ind += @count
elsif @prev_line =~ /^\s*#?if\b|^\s*#?else\b/i
unless @prev_line =~ /\bthen\b[ \t ]*[^' \r\n']+.*$/i or @prev_line =~ /\breturn\b/i
@ind += @count
end
elsif @prev_line =~ /^\s*\bfor\b|^\s*\bwhile\b/i
@ind += @count
end
elsif @prev_line =~ /^\s*\bfor\b|^\s*\bwhile\b/i
@ind += @count
end
end
if line =~ /^\'/
# Don't change indentation
elsif line =~ /^\s*[\}\]\)]/
@ind -= @count
elsif line =~ /^\s*\bfunction\b|^\s*\bsub\b/i
@ind -= 0
elsif line =~ /^\s*:?\s*#?end\b|^\s*#?endif\b|^\s*endfor\b|^\s*\bnext\b/i
@ind -= @count
elsif line =~ /^\s*#?else\b|^\s*elseif\b/i
@ind -= @count
if line =~ /^\'/ or line =~ /\'indent-ignore/
# Don't change indentation
elsif line =~ /^\s*[\}\]\)]/
@ind -= @count
elsif line =~ /^\s*\bfunction\b|^\s*\bsub\b/i
@ind -= 0
elsif line =~ /^\s*:?\s*#?end\b|^\s*#?endif\b|^\s*endfor\b|^\s*\bnext\b/i
@ind -= @count
elsif line =~ /^\s*#?else\b|^\s*elseif\b/i
@ind -= @count
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/roku_builder/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module RokuBuilder
# Version of the RokuBuilder Gem
VERSION = "4.21.0"
VERSION = "4.21.1"
end

0 comments on commit 05cc087

Please sign in to comment.