diff --git a/lib/cc/engine/analyzers/javascript/main.rb b/lib/cc/engine/analyzers/javascript/main.rb index 20e5c92c..0229e4e2 100644 --- a/lib/cc/engine/analyzers/javascript/main.rb +++ b/lib/cc/engine/analyzers/javascript/main.rb @@ -15,6 +15,7 @@ class Main "**/*.jsx" ] DEFAULT_MASS_THRESHOLD = 40 + BASE_POINTS = 3000 def initialize(engine_config:, directory:) @engine_config = engine_config @@ -31,6 +32,10 @@ def mass_threshold engine_config.fetch("config", {}).fetch("javascript", {}).fetch("mass_threshold", DEFAULT_MASS_THRESHOLD) end + def base_points + BASE_POINTS + end + private attr_reader :engine_config, :directory diff --git a/lib/cc/engine/analyzers/javascript/node.rb b/lib/cc/engine/analyzers/javascript/node.rb index a6ac9a0e..68d88988 100644 --- a/lib/cc/engine/analyzers/javascript/node.rb +++ b/lib/cc/engine/analyzers/javascript/node.rb @@ -5,7 +5,7 @@ module Engine module Analyzers module Javascript class Node < CC::Engine::Analyzers::Node - SCRUB_PROPERTIES = ["type", "start", "end"] + SCRUB_PROPERTIES = %w[type start end] private diff --git a/lib/cc/engine/analyzers/php/main.rb b/lib/cc/engine/analyzers/php/main.rb index 986d2c51..d3133e30 100644 --- a/lib/cc/engine/analyzers/php/main.rb +++ b/lib/cc/engine/analyzers/php/main.rb @@ -14,6 +14,7 @@ class Main "**/*.module" ] DEFAULT_MASS_THRESHOLD = 10 + BASE_POINTS = 4_000 attr_reader :directory, :engine_config, :io @@ -32,6 +33,10 @@ def mass_threshold engine_config.fetch('config', {}).fetch('php', {}).fetch('mass_threshold', DEFAULT_MASS_THRESHOLD) end + def base_points + BASE_POINTS + end + private attr_reader :engine_config, :directory diff --git a/lib/cc/engine/analyzers/python/main.rb b/lib/cc/engine/analyzers/python/main.rb index a75972b5..364f7e3d 100644 --- a/lib/cc/engine/analyzers/python/main.rb +++ b/lib/cc/engine/analyzers/python/main.rb @@ -11,7 +11,10 @@ module Python class Main LANGUAGE = "python" DEFAULT_PATHS = ["**/*.py"] - DEFAULT_MASS_THRESHOLD = 50 + DEFAULT_MASS_THRESHOLD = 40 + BASE_POINTS = 1000 + LANGUAGE = "python" + DEFAULT_PATHS = ["**/*.py"] def initialize(directory:, engine_config:) @directory = directory @@ -28,6 +31,10 @@ def mass_threshold engine_config.fetch("config", {}).fetch("python", {}).fetch("mass_threshold", DEFAULT_MASS_THRESHOLD) end + def base_points + BASE_POINTS + end + private attr_reader :directory, :engine_config diff --git a/lib/cc/engine/analyzers/python/node.rb b/lib/cc/engine/analyzers/python/node.rb index ad56bc5d..b2456969 100644 --- a/lib/cc/engine/analyzers/python/node.rb +++ b/lib/cc/engine/analyzers/python/node.rb @@ -5,7 +5,7 @@ module Engine module Analyzers module Python class Node < CC::Engine::Analyzers::Node - SCRUB_PROPERTIES = ["_type", "attributes"].freeze + SCRUB_PROPERTIES = %w[_type attributes ctx].freeze private diff --git a/lib/cc/engine/analyzers/reporter.rb b/lib/cc/engine/analyzers/reporter.rb index 4489bad5..fa2ad78c 100644 --- a/lib/cc/engine/analyzers/reporter.rb +++ b/lib/cc/engine/analyzers/reporter.rb @@ -46,7 +46,7 @@ def mass_threshold def new_violation(issue) hashes = flay.hashes[issue.structural_hash] - Violation.new(issue, hashes, directory).format + Violation.new(language_strategy.base_points, issue, hashes, directory).format end def flay_options diff --git a/lib/cc/engine/analyzers/ruby/main.rb b/lib/cc/engine/analyzers/ruby/main.rb index 056afb20..050846e1 100644 --- a/lib/cc/engine/analyzers/ruby/main.rb +++ b/lib/cc/engine/analyzers/ruby/main.rb @@ -17,6 +17,7 @@ class Main ] DEFAULT_MASS_THRESHOLD = 10 + BASE_POINTS = 10_000 TIMEOUT = 10 def initialize(directory:, engine_config:) @@ -34,6 +35,10 @@ def mass_threshold engine_config.fetch("config", {}).fetch("ruby", {}).fetch("mass_threshold", DEFAULT_MASS_THRESHOLD) end + def base_points + BASE_POINTS + end + private attr_reader :directory, :engine_config diff --git a/lib/cc/engine/analyzers/violation.rb b/lib/cc/engine/analyzers/violation.rb index 243a45e5..e6d8b92b 100644 --- a/lib/cc/engine/analyzers/violation.rb +++ b/lib/cc/engine/analyzers/violation.rb @@ -2,11 +2,10 @@ module CC module Engine module Analyzers class Violation - BASE_POINTS = 10_000 - attr_reader :issue - def initialize(issue, hashes, directory) + def initialize(base_points, issue, hashes, directory) + @base_points = base_points @issue = issue @hashes = hashes @directory = directory @@ -27,7 +26,7 @@ def format private - attr_reader :hashes, :directory + attr_reader :base_points, :hashes, :directory def current_sexp @location ||= hashes.first @@ -46,7 +45,7 @@ def name end def calculate_points - BASE_POINTS * issue.mass + base_points * issue.mass end def format_location diff --git a/spec/cc/engine/analyzers/javascript/main_spec.rb b/spec/cc/engine/analyzers/javascript/main_spec.rb index c3cfc4c2..61e5b212 100644 --- a/spec/cc/engine/analyzers/javascript/main_spec.rb +++ b/spec/cc/engine/analyzers/javascript/main_spec.rb @@ -36,7 +36,7 @@ def run_engine(config = nil) end def printed_issue - issue = {"type":"issue","check_name":"Identical code","description":"Duplication found in ExpressionStatement","categories":["Duplication"],"location":{"path":"foo.js","lines":{"begin":1,"end":1}},"remediation_points":1260000, "other_locations":[{"path":"foo.js","lines":{"begin":2,"end":2}},{"path":"foo.js","lines":{"begin":3,"end":3}}], "content":{"body": read_up}} + issue = {"type":"issue","check_name":"Identical code","description":"Duplication found in ExpressionStatement","categories":["Duplication"],"location":{"path":"foo.js","lines":{"begin":1,"end":1}},"remediation_points":378000, "other_locations":[{"path":"foo.js","lines":{"begin":2,"end":2}},{"path":"foo.js","lines":{"begin":3,"end":3}}], "content":{"body": read_up}} issue.to_json + "\0\n" end diff --git a/spec/cc/engine/analyzers/php/main_spec.rb b/spec/cc/engine/analyzers/php/main_spec.rb index d09ce17d..575864e1 100644 --- a/spec/cc/engine/analyzers/php/main_spec.rb +++ b/spec/cc/engine/analyzers/php/main_spec.rb @@ -49,7 +49,7 @@ def run_engine(config = nil) end def printed_issue - issue = {"type":"issue","check_name":"Identical code","description":"Duplication found in function","categories":["Duplication"],"location":{"path":"foo.php","lines":{"begin":2,"end":6}},"remediation_points":440000,"other_locations":[{"path":"foo.php","lines":{"begin":10,"end":14}}],"content":{"body": read_up}} + issue = {"type":"issue","check_name":"Identical code","description":"Duplication found in function","categories":["Duplication"],"location":{"path":"foo.php","lines":{"begin":2,"end":6}},"remediation_points":176000,"other_locations":[{"path":"foo.php","lines":{"begin":10,"end":14}}],"content":{"body": read_up}} issue.to_json + "\0\n" end diff --git a/spec/cc/engine/analyzers/python/main_spec.rb b/spec/cc/engine/analyzers/python/main_spec.rb index ed6c0162..1ba0c1bf 100644 --- a/spec/cc/engine/analyzers/python/main_spec.rb +++ b/spec/cc/engine/analyzers/python/main_spec.rb @@ -35,7 +35,7 @@ def run_engine(config = nil) end def printed_issue - issue = {"type":"issue","check_name":"Identical code","description":"Duplication found in Print","categories":["Duplication"],"location":{"path":"foo.py","lines":{"begin":1,"end":1}},"remediation_points":990000, "other_locations":[{"path":"foo.py","lines":{"begin":2,"end":2}},{"path":"foo.py","lines":{"begin":3,"end":3}}], "content":{"body": read_up}} + issue = {"type":"issue","check_name":"Identical code","description":"Duplication found in Print","categories":["Duplication"],"location":{"path":"foo.py","lines":{"begin":1,"end":1}},"remediation_points":81000, "other_locations":[{"path":"foo.py","lines":{"begin":2,"end":2}},{"path":"foo.py","lines":{"begin":3,"end":3}}], "content":{"body": read_up}} issue.to_json + "\0\n" end