Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Make base point values language specific #7

Merged
merged 1 commit into from
Oct 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/cc/engine/analyzers/javascript/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Main
"**/*.jsx"
]
DEFAULT_MASS_THRESHOLD = 40
BASE_POINTS = 3000

def initialize(engine_config:, directory:)
@engine_config = engine_config
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cc/engine/analyzers/javascript/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions lib/cc/engine/analyzers/php/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Main
"**/*.module"
]
DEFAULT_MASS_THRESHOLD = 10
BASE_POINTS = 4_000

attr_reader :directory, :engine_config, :io

Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/cc/engine/analyzers/python/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ module Python
class Main
LANGUAGE = "python"
DEFAULT_PATHS = ["**/*.py"]
DEFAULT_MASS_THRESHOLD = 50
DEFAULT_MASS_THRESHOLD = 40
BASE_POINTS = 1000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the base points different for python?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The s-expressions generated from Python's AST is much more verbose than Ruby's which means the points have to be lower.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - makes sense to me!

LANGUAGE = "python"
DEFAULT_PATHS = ["**/*.py"]

def initialize(directory:, engine_config:)
@directory = directory
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cc/engine/analyzers/python/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a related change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this is me trying to trim down the resulting s-expressions since they have a high mass.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make a separate commit for this instead then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll split it into it's own commit, but same PR.


private

Expand Down
2 changes: 1 addition & 1 deletion lib/cc/engine/analyzers/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/cc/engine/analyzers/ruby/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Main

]
DEFAULT_MASS_THRESHOLD = 10
BASE_POINTS = 10_000
TIMEOUT = 10

def initialize(directory:, engine_config:)
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/cc/engine/analyzers/violation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +26,7 @@ def format

private

attr_reader :hashes, :directory
attr_reader :base_points, :hashes, :directory

def current_sexp
@location ||= hashes.first
Expand All @@ -46,7 +45,7 @@ def name
end

def calculate_points
BASE_POINTS * issue.mass
base_points * issue.mass
end

def format_location
Expand Down
2 changes: 1 addition & 1 deletion spec/cc/engine/analyzers/javascript/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/cc/engine/analyzers/php/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/cc/engine/analyzers/python/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down