From b3cdb8b72ae1a0fcb58d73b52bd4a167b0b09903 Mon Sep 17 00:00:00 2001 From: wata727 Date: Sun, 7 Aug 2016 17:23:10 +0900 Subject: [PATCH 1/2] add first_line value in ParseDef and ParseClass --- lib/saikuro/html_stylesheet.rb | 4 ++-- lib/saikuro/parse_class.rb | 3 ++- lib/saikuro/parse_def.rb | 3 ++- lib/saikuro/parse_state_formatter.rb | 8 ++++---- lib/saikuro/state_html_complexity_formatter.rb | 9 +++++---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/saikuro/html_stylesheet.rb b/lib/saikuro/html_stylesheet.rb index aab41c3..79a00cc 100644 --- a/lib/saikuro/html_stylesheet.rb +++ b/lib/saikuro/html_stylesheet.rb @@ -51,12 +51,12 @@ def HTMLStyleSheet.style_sheet out.puts ' margin: 0;' out.puts '}' out.puts '' - out.puts '.class_total_complexity, .class_total_lines, .start_token_count, .file_count {' + out.puts '.class_total_complexity, .class_total_lines, .start_token_count, .file_count, .class_first_line {' out.puts ' font-size: 13px;' out.puts ' font-weight: bold;' out.puts '}' out.puts '' - out.puts '.class_total_complexity, .class_total_lines {' + out.puts '.class_total_complexity, .class_total_lines, .class_first_line {' out.puts ' color: #c00;' out.puts '}' out.puts '' diff --git a/lib/saikuro/parse_class.rb b/lib/saikuro/parse_class.rb index 2b72ae6..0d53c86 100644 --- a/lib/saikuro/parse_class.rb +++ b/lib/saikuro/parse_class.rb @@ -1,6 +1,7 @@ class ParseClass < EndableParseState def initialize(lexer,parent=nil) super(lexer,parent) + @first_line = lexer.line_no @type_name = "Class" end @@ -15,7 +16,7 @@ def compute_state(formater) child.kind_of?(ParseClass) end - formater.start_class_compute_state(@type_name,@name,self.calc_complexity,self.calc_lines) + formater.start_class_compute_state(@type_name,@name,self.calc_complexity,@first_line,self.calc_lines) super(formater) formater.end_class_compute_state(@name) diff --git a/lib/saikuro/parse_def.rb b/lib/saikuro/parse_def.rb index 08e739e..de5e259 100644 --- a/lib/saikuro/parse_def.rb +++ b/lib/saikuro/parse_def.rb @@ -2,6 +2,7 @@ class ParseDef < EndableParseState def initialize(lexer,parent=nil) super(lexer,parent) + @first_line = lexer.line_no @complexity = 1 @looking_for_name = true @first_space = true @@ -53,7 +54,7 @@ def parse_token(token) end def compute_state(formater) - formater.def_compute_state(@name, self.calc_complexity, self.calc_lines) + formater.def_compute_state(@name, self.calc_complexity, @first_line, self.calc_lines) super(formater) end end diff --git a/lib/saikuro/parse_state_formatter.rb b/lib/saikuro/parse_state_formatter.rb index 6d326b4..3dacd4c 100644 --- a/lib/saikuro/parse_state_formatter.rb +++ b/lib/saikuro/parse_state_formatter.rb @@ -8,20 +8,20 @@ def start(new_out=nil) def end end - def start_class_compute_state(type_name,name,complexity,lines) + def start_class_compute_state(type_name,name,complexity,first_line,lines) @current = name @out.puts "-- START #{name} --" - @out.puts "Type:#{type_name} Name:#{name} Complexity:#{complexity} Lines:#{lines}" + @out.puts "Type:#{type_name} Name:#{name} Complexity:#{complexity} FirstLine:#{first_line} Lines:#{lines}" end def end_class_compute_state(name) @out.puts "-- END #{name} --" end - def def_compute_state(name,complexity,lines) + def def_compute_state(name,complexity,first_line,lines) return if @filter.ignore?(complexity) warn_error?(complexity, name) - @out.puts "Type:Def Name:#{name} Complexity:#{complexity} Lines:#{lines}" + @out.puts "Type:Def Name:#{name} Complexity:#{complexity} FirstLine:#{first_line} Lines:#{lines}" end end diff --git a/lib/saikuro/state_html_complexity_formatter.rb b/lib/saikuro/state_html_complexity_formatter.rb index 2b3d25f..c405a86 100644 --- a/lib/saikuro/state_html_complexity_formatter.rb +++ b/lib/saikuro/state_html_complexity_formatter.rb @@ -14,14 +14,15 @@ def end @out.puts "" end - def start_class_compute_state(type_name,name,complexity,lines) + def start_class_compute_state(type_name,name,complexity,first_line,lines) @current = name @out.puts "
" @out.puts "

#{type_name} : #{name}

" + @out.puts "
First Line: #{first_line}
" @out.puts "
Total Complexity: #{complexity}
" @out.puts "
Total Lines: #{lines}
" @out.puts "" - @out.puts "" + @out.puts "" end def end_class_compute_state(name) @@ -29,10 +30,10 @@ def end_class_compute_state(name) @out.puts "" end - def def_compute_state(name, complexity, lines) + def def_compute_state(name, complexity, first_line, lines) return if @filter.ignore?(complexity) klass = warn_error?(complexity, name) - @out.puts "#{complexity}" + @out.puts "#{complexity}" end end From 3fc4deca1cced7329b8aa7d30c92b7490d139a9c Mon Sep 17 00:00:00 2001 From: wata727 Date: Sun, 7 Aug 2016 17:50:29 +0900 Subject: [PATCH 2/2] fix arguments in global class compute state --- lib/saikuro/parse_state.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/saikuro/parse_state.rb b/lib/saikuro/parse_state.rb index 90d207e..bb8a81f 100644 --- a/lib/saikuro/parse_state.rb +++ b/lib/saikuro/parse_state.rb @@ -79,7 +79,7 @@ def compute_state_for_global(formater) return if global_def.empty? gx = global_def.inject(0) { |c,s| s.calc_complexity } gl = global_def.inject(0) { |c,s| s.calc_lines } - formater.start_class_compute_state("Global", "", gx, gl) + formater.start_class_compute_state("Global", "", gx, 0, gl) global_def.each do |s| s.compute_state(formater) end
MethodComplexity# Lines
MethodComplexityFirst Line# Lines
#{name}#{lines}
#{name}#{first_line}#{lines}