Module: SpacingChecker
- Defined in:
- lib/jscop/spacing_checker.rb
Class Method Summary collapse
- .check_spaces(file) ⇒ Object
- .check_spaces_res(error_bin, path) ⇒ Object
- .found_spaces(cont) ⇒ Object
Class Method Details
.check_spaces(file) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jscop/spacing_checker.rb', line 32 def self.check_spaces(file) lines_with_spaces = [] check_line = lambda { |line| lines_with_spaces << line.number if found_spaces(line.content) && !lines_with_spaces.nil? } err_type = 'SPACING_ERR' file.lines.each(&check_line) lines_with_spaces.each { |line| raise_err(line, err_type, file.filename) if !lines_with_spaces.empty? } end |
.check_spaces_res(error_bin, path) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/jscop/spacing_checker.rb', line 4 def self.check_spaces_res(error_bin, path) bad_spaced_lines = check_spaces(path) bad_spaced_lines.each { |line| error_bin << line if !bad_spaced_lines.empty? } error_bin end |
.found_spaces(cont) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jscop/spacing_checker.rb', line 17 def self.found_spaces(cont) spaces_before = /[\s]+(const|let|var|function|class|[\}$])[\s]+[\w]*/ spaces_after = /(const|let|var|function|class)[\s]{2,}[\w]+[\s]*[\=]/ spaced_console = /[\s]+(function|(console.log)[\(][\w]*[\)])[\s]*/ closing_line = /[\s]+[\}][\s]*/ commented_line = cont.match?(%r{^\W+[\/\/]}) a = spaces_before.match?(cont) b = spaces_after.match?(cont) c = spaced_console.match?(cont) !commented_line && (a || b || c || closing_line.match?(cont)) end |