roku_builder 4.14.1 → 4.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28e303ec07cdadeab357258626a2dc7ac99022d9
4
- data.tar.gz: fd728532cabed6972d049228335d8d81d805a022
3
+ metadata.gz: 62fc3eeb8342b7b051b3fb0c96ca465328da1132
4
+ data.tar.gz: '0739f417d2fdd6cfc2d3ab4755e6cef51bfd70a1'
5
5
  SHA512:
6
- metadata.gz: 556c367b93d5d1d5ad51b50597eabee9529923f7c168614a0be6e61010a28f8b50d150dd02d79120cb64d27dcabe2aa8d7135fa093baa3a107786d7e86acbc84
7
- data.tar.gz: 102ce72c84846d63b8971817a326e5393b4f3a746012a3df701d229855f51d74b2022200dd09ff5dfecf8424c8566b92faabaddc924fcc3241ffa563aa25d1d4
6
+ metadata.gz: 2a8822179c1be73aa66fa86a16006e9b9085e311834c721aabe454552e7e8e610439c89566f626d6ec54f678198769d48f3d6422c8a1e88a2f2864fe062685f8
7
+ data.tar.gz: 74bcb13af4721aa3bb22312b37c6820249a79f03fdbb5445a25d78630766516c19e4e69e7eaeff976506191c8c13ead65d5637ecac6e89813b2fa9f1de8c09f6
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = 4.15.0 =
2
+
3
+ - Add indentation checking to analyze command
4
+
1
5
  = 4.14.1 =
2
6
 
3
7
  - Rebuild of gem
@@ -33,6 +33,7 @@ module RokuBuilder
33
33
  analyzer_config = get_config("inspector_config.json")
34
34
  performance_config = get_config("performance_config.json")
35
35
  linter_config = get_config(".roku_builder_linter.json", true)
36
+ linter_config ||= {}
36
37
  @inspector_config = analyzer_config[:inspectors]
37
38
  loader = Loader.new(config: @config)
38
39
  Dir.mktmpdir do |dir|
@@ -49,8 +50,8 @@ module RokuBuilder
49
50
  if File.file?(file_path) and file_path.end_with?(".brs", ".xml")
50
51
  line_inspector_config = analyzer_config[:lineInspectors]
51
52
  line_inspector_config += performance_config
52
- line_inspector_config += linter_config if linter_config
53
- line_inspector = LineInspector.new(config: @config, raf: raf_inspector, inspector_config: line_inspector_config)
53
+ line_inspector_config += linter_config[:rules] if linter_config[:rules]
54
+ line_inspector = LineInspector.new(config: @config, raf: raf_inspector, inspector_config: line_inspector_config, indent_config: linter_config[:indentation])
54
55
  @warnings.concat(line_inspector.run(file_path))
55
56
  end
56
57
  if file_path.end_with?("__MACOSX")
@@ -0,0 +1,83 @@
1
+ # ********** Copyright Viacom, Inc. Apache 2.0 **********
2
+
3
+ module RokuBuilder
4
+ class IndentationInspector
5
+ attr_reader :warnings
6
+ def initialize(rules:, path:)
7
+ @character = get_character(rules[:character])
8
+ @count = rules[:count].to_i
9
+ @path = path
10
+ @type = File.extname(path)[1..-1].to_sym
11
+ @warnings = []
12
+ @prev_line = nil
13
+ @ind = 0
14
+ end
15
+
16
+ def check_line(line:, number:)
17
+ #byebug if number == 191 and @path.ends_with?("EpisodeGuide.animation.brs")
18
+ set_indentation(line: line)
19
+ regexp = /^#{@character}{#{@ind}}[^#{@character}]/
20
+ unless line =~ regexp or line == "\n"
21
+ add_warning(line: number)
22
+ end
23
+ @prev_line = line
24
+ end
25
+
26
+ def set_indentation(line:)
27
+ case @type
28
+ when :xml
29
+ if @prev_line and @prev_line =~ /<[^?!\/][^>]*[^\/]>/
30
+ unless @prev_line =~ /<([^>\/]*)>.*<\/\1*>/
31
+ @ind += @count
32
+ end
33
+ end
34
+ if line =~ /<\/[^>]*>/
35
+ unless line =~ /<([^>\/]*)>.*<\/\1*>/
36
+ @ind -= @count
37
+ end
38
+ end
39
+ when :brs
40
+ if @prev_line
41
+ if @prev_line =~ /[\{\[\(:]$/
42
+ @ind += @count
43
+ elsif @prev_line =~ /^\s*\bfunction\b|^\s*\bsub\b/i
44
+ @ind += @count
45
+ elsif @prev_line =~ /^\s*#?if\b|^\s*#?else\b/i
46
+ unless @prev_line =~ /\bthen\b[ \t ]*[^' \r\n']+.*$/i or @prev_line =~ /\breturn\b/i
47
+ @ind += @count
48
+ end
49
+ elsif @prev_line =~ /^\s*\bfor\b|^\s*\bwhile\b/i
50
+ @ind += @count
51
+ end
52
+ end
53
+ if line =~ /^\s*[\}\]\)]/
54
+ @ind -= @count
55
+ elsif line =~ /^\s*\bfunction\b|^\s*\bsub\b/i
56
+ @ind -= 0
57
+ elsif line =~ /^\s*#?end\b|^\s*#?endif\b|^\s*endfor\b|^\s*\bnext\b/i
58
+ @ind -= @count
59
+ elsif line =~ /^\s*#?else\b|^\s*elseif\b/i
60
+ @ind -= @count
61
+ end
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def get_character(character)
68
+ case character
69
+ when "tab"
70
+ "\t"
71
+ when "space"
72
+ " "
73
+ end
74
+ end
75
+
76
+ def add_warning(line:)
77
+ @warnings.push({severity: "warning", message: 'Incorrect indentation'})
78
+ @warnings.last[:path] = @path
79
+ @warnings.last[:line] = line
80
+ end
81
+ end
82
+ end
83
+
@@ -3,18 +3,20 @@
3
3
  module RokuBuilder
4
4
 
5
5
  class LineInspector
6
- def initialize(config:, raf:, inspector_config:)
6
+ def initialize(config:, raf:, inspector_config:, indent_config:)
7
7
  @config = config
8
8
  @raf_inspector = raf
9
9
  @inspector_config = inspector_config
10
+ @indent_config = indent_config
10
11
  end
11
12
 
12
13
  def run(file_path)
13
14
  @warnings = []
14
15
  File.open(file_path) do |file|
15
- line_number = 0
16
16
  in_xml_comment = false
17
- file.readlines.each do |line|
17
+ indent_inspector = IndentationInspector.new(rules: @indent_config, path: file_path) if @indent_config
18
+ file.readlines.each_with_index do |line, line_number|
19
+ indent_inspector.check_line(line: line, number: line_number) if indent_inspector
18
20
  full_line = line.dup
19
21
  line = line.partition("'").first if file_path.end_with?(".brs")
20
22
  if file_path.end_with?(".xml")
@@ -42,8 +44,8 @@ module RokuBuilder
42
44
  end
43
45
  end
44
46
  @raf_inspector.inspect_line(line: line, file: file_path, line_number: line_number)
45
- line_number += 1
46
47
  end
48
+ @warnings += indent_inspector.warnings if indent_inspector
47
49
  end
48
50
  @warnings
49
51
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module RokuBuilder
4
4
  # Version of the RokuBuilder Gem
5
- VERSION = "4.14.1"
5
+ VERSION = "4.15.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roku_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.14.1
4
+ version: 4.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - greeneca
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-21 00:00:00.000000000 Z
11
+ date: 2019-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -486,6 +486,7 @@ files:
486
486
  - lib/roku_builder/plugin.rb
487
487
  - lib/roku_builder/plugins/analyzer.rb
488
488
  - lib/roku_builder/plugins/core.rb
489
+ - lib/roku_builder/plugins/indentation_inspector.rb
489
490
  - lib/roku_builder/plugins/inspector.rb
490
491
  - lib/roku_builder/plugins/inspector_config.json
491
492
  - lib/roku_builder/plugins/line_inspector.rb