Module: NamingChecker

Defined in:
lib/jscop/naming_checker.rb

Class Method Summary collapse

Class Method Details

.bad_var_case(bad_case) ⇒ Object



17
18
19
20
21
22
# File 'lib/jscop/naming_checker.rb', line 17

def self.bad_var_case(bad_case)
  bad_var_start = /(var|let|const|[\s])[\s]*([[:upper:]]{1,}|\d)+(([\w]+[\s][\w]+)|[\w]+)[\s]*[\=][\s]*[\w]*/
  commented_line = bad_case.match?(%r{^\W+[\/\/]})

  bad_var_start.match?(bad_case) && !commented_line
end

.check_naming(fpath) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jscop/naming_checker.rb', line 24

def self.check_naming(fpath)
  bad_lines = []
  check_line = lambda { |line|
    line_with_bad_naming = line if bad_var_case(line.content)
    bad_lines << line_with_bad_naming.number if line_with_bad_naming
  }
  err_type = 'VAR_NAMING_ERR'
  fpath.lines.each(&check_line)

  bad_lines.each { |line| raise_err(line, err_type, fpath.filename) if !bad_lines.empty? }
end

.check_naming_res(error_bin, path) ⇒ Object



4
5
6
7
8
9
# File 'lib/jscop/naming_checker.rb', line 4

def self.check_naming_res(error_bin, path)
  bad_named_lines = check_naming(path)
  bad_named_lines.each { |line| error_bin << line if bad_named_lines }

  error_bin
end