Module: XRay::JS::Rule::Helper
- Included in:
- ChecklistRule, FileChecker
- Defined in:
- lib/js/rule/helper.rb
Instance Method Summary collapse
- #app(path) ⇒ Object
- #find_expr_member(expr) ⇒ Object
- #func_file?(path) ⇒ Boolean
- #global_scope?(path) ⇒ Boolean
- #grep_import_js_path(body) ⇒ Object
- #has_doc_comment?(body) ⇒ Boolean
- #lib_scope?(path) ⇒ Boolean
- #merge_file?(path) ⇒ Boolean
- #min_file?(path) ⇒ Boolean
- #page_scope?(path) ⇒ Boolean
- #readfile(path) ⇒ Object
- #relative?(path) ⇒ Boolean
- #results_to_logs(results) ⇒ Object
- #scope(path) ⇒ Object
Instance Method Details
#app(path) ⇒ Object
80 81 82 83 |
# File 'lib/js/rule/helper.rb', line 80 def app( path ) sep = /(?:\\|\/)/ path[/#{sep}app#{sep}(.*?)#{sep}(?:.+#{sep})*(global|page|module)(?:\\|\/)/, 1] end |
#find_expr_member(expr) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/js/rule/helper.rb', line 6 def find_expr_member(expr) while expr.is_a?(Expression) && !yield(expr) expr = expr.left end expr && expr.is_a?(Expression) && yield(expr) ? expr : nil end |
#func_file?(path) ⇒ Boolean
30 31 32 |
# File 'lib/js/rule/helper.rb', line 30 def func_file?(path) !merge_file?(path) and !min_file?(path) end |
#global_scope?(path) ⇒ Boolean
64 65 66 |
# File 'lib/js/rule/helper.rb', line 64 def global_scope?( path ) scope(path) == :global end |
#grep_import_js_path(body) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/js/rule/helper.rb', line 34 def grep_import_js_path(body) lines = body.split /\n/ pattern = /(ImportJavscript\s*\.\s*url\s*\(\s*['"]?([^'"]+)['"]?\s*\)\s*;?)/ pathes = [] lines.each_with_index do |line, index| line.scan(pattern) do |text, url| pathes << { :text => text, :url => url, :row => index + 1, :col => Regexp.last_match.begin(0) + 1 } end end pathes end |
#has_doc_comment?(body) ⇒ Boolean
13 14 15 |
# File 'lib/js/rule/helper.rb', line 13 def has_doc_comment?(body) body =~ /^\s*\/\*\*[^*]*\*+([^\/*][^*]*\*+)*\// end |
#lib_scope?(path) ⇒ Boolean
72 73 74 |
# File 'lib/js/rule/helper.rb', line 72 def lib_scope?( path ) scope(path) == :lib end |
#merge_file?(path) ⇒ Boolean
22 23 24 |
# File 'lib/js/rule/helper.rb', line 22 def merge_file?(path) return path =~ /\w+-merge([-_]?\d+)?\.js$/ end |
#min_file?(path) ⇒ Boolean
26 27 28 |
# File 'lib/js/rule/helper.rb', line 26 def min_file?(path) return path =~ /\w+-min\.js$/ end |
#page_scope?(path) ⇒ Boolean
68 69 70 |
# File 'lib/js/rule/helper.rb', line 68 def page_scope?( path ) scope(path) == :page end |
#readfile(path) ⇒ Object
17 18 19 20 |
# File 'lib/js/rule/helper.rb', line 17 def readfile(path) text, encoding = XRay::Helper::FileReader.readfile path text end |
#relative?(path) ⇒ Boolean
76 77 78 |
# File 'lib/js/rule/helper.rb', line 76 def relative?( path ) path !~ %r(^https?://) end |
#results_to_logs(results) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/js/rule/helper.rb', line 85 def results_to_logs( results ) results.map do |r| msg, level, row, column = *r LogEntry.new(msg, level, row || 0, column || 0) end end |
#scope(path) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/js/rule/helper.rb', line 53 def scope(path) parts = path.split(/\\\//) if parts.include? 'global' :global elsif parts.include? 'page' :page elsif parts.include? 'lib' or parts.include? 'sys' :lib end end |