-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from codeclimate/jp/upgrade-rubocop
Bump rubocop to 0.37.2
- Loading branch information
Showing
15 changed files
with
410 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem "activesupport", require: false | ||
gem "rubocop", require: false | ||
gem "rubocop", "~> 0.37.2", require: false | ||
gem "rubocop-rspec", require: false | ||
gem "safe_yaml" | ||
gem "pry", require: false | ||
|
||
group :test do | ||
gem "mocha" | ||
gem "rake" | ||
gem "minitest" | ||
gem "minitest-reporters" | ||
gem "rspec" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,67 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activesupport (4.2.4) | ||
activesupport (4.2.5.1) | ||
i18n (~> 0.7) | ||
json (~> 1.7, >= 1.7.7) | ||
minitest (~> 5.1) | ||
thread_safe (~> 0.3, >= 0.3.4) | ||
tzinfo (~> 1.1) | ||
ansi (1.5.0) | ||
ast (2.2.0) | ||
astrolabe (1.3.1) | ||
parser (~> 2.2) | ||
builder (3.2.2) | ||
coderay (1.1.0) | ||
diff-lcs (1.2.5) | ||
i18n (0.7.0) | ||
json (1.8.3) | ||
metaclass (0.0.4) | ||
method_source (0.8.2) | ||
minitest (5.8.0) | ||
minitest-reporters (1.0.20) | ||
ansi | ||
builder | ||
minitest (>= 5.0) | ||
ruby-progressbar | ||
mocha (1.1.0) | ||
metaclass (~> 0.0.1) | ||
parser (2.2.3.0) | ||
ast (>= 1.1, < 3.0) | ||
minitest (5.8.4) | ||
parser (2.3.0.4) | ||
ast (~> 2.2) | ||
powerpack (0.1.1) | ||
pry (0.10.1) | ||
pry (0.10.3) | ||
coderay (~> 1.1.0) | ||
method_source (~> 0.8.1) | ||
slop (~> 3.4) | ||
rainbow (2.0.0) | ||
rake (10.4.2) | ||
rubocop (0.35.1) | ||
astrolabe (~> 1.3) | ||
parser (>= 2.2.3.0, < 3.0) | ||
rainbow (2.1.0) | ||
rake (10.5.0) | ||
rspec (3.3.0) | ||
rspec-core (~> 3.3.0) | ||
rspec-expectations (~> 3.3.0) | ||
rspec-mocks (~> 3.3.0) | ||
rspec-core (3.3.1) | ||
rspec-support (~> 3.3.0) | ||
rspec-expectations (3.3.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.3.0) | ||
rspec-mocks (3.3.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.3.0) | ||
rspec-support (3.3.0) | ||
rubocop (0.37.2) | ||
parser (>= 2.3.0.4, < 3.0) | ||
powerpack (~> 0.1) | ||
rainbow (>= 1.99.1, < 3.0) | ||
ruby-progressbar (~> 1.7) | ||
tins (<= 1.6.0) | ||
rubocop-rspec (1.3.0) | ||
unicode-display_width (~> 0.3) | ||
rubocop-rspec (1.3.1) | ||
ruby-progressbar (1.7.5) | ||
safe_yaml (1.0.4) | ||
slop (3.6.0) | ||
thread_safe (0.3.5) | ||
tins (1.6.0) | ||
tzinfo (1.2.2) | ||
thread_safe (~> 0.1) | ||
unicode-display_width (0.3.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
activesupport | ||
minitest | ||
minitest-reporters | ||
mocha | ||
pry | ||
rake | ||
rubocop | ||
rspec | ||
rubocop (~> 0.37.2) | ||
rubocop-rspec | ||
safe_yaml | ||
|
||
BUNDLED WITH | ||
1.11.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
require 'rake/testtask' | ||
require "rspec/core/rake_task" | ||
|
||
Rake.add_rakelib 'lib/tasks' | ||
|
||
Rake::TestTask.new do |t| | ||
t.test_files = Dir.glob('spec/**/*_spec.rb') | ||
t.libs = %w[lib spec] | ||
end | ||
|
||
task(default: :test) | ||
Rake.add_rakelib "lib/tasks" | ||
RSpec::Core::RakeTask.new(:spec) | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
Metrics/AbcSize: | ||
base_points: 1_000_000 | ||
violation_points: 70_000 | ||
overage_points: 70_000 | ||
Metrics/BlockNesting: | ||
base_points: 100_000 | ||
overage_points: 50_000 | ||
Metrics/ClassLength: | ||
base_points: 5_000_000 | ||
violation_points: 35_000 | ||
Metrics/CyclomaticComplexity: # This check is per method | ||
overage_points: 35_000 | ||
Metrics/CyclomaticComplexity: | ||
base_points: 1_000_000 | ||
violation_points: 70_000 | ||
overage_points: 70_000 | ||
Metrics/LineLength: | ||
base_points: 50_000 | ||
overage_points: 0 | ||
Metrics/MethodLength: | ||
base_points: 1_000_000 | ||
violation_points: 70_000 | ||
overage_points: 70_000 | ||
Metrics/ModuleLength: | ||
base_points: 5_000_000 | ||
violation_points: 35_000 | ||
overage_points: 35_000 | ||
Metrics/ParameterList: | ||
base_points: 500_000 | ||
violation_points: 100_000 | ||
overage_points: 100_000 | ||
Metrics/PerceivedComplexity: | ||
base_points: 1_000_000 | ||
violation_points: 70_000 | ||
overage_points: 70_000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
require 'safe_yaml' | ||
SafeYAML::OPTIONS[:default_mode] = :safe | ||
|
||
module CC | ||
module Engine | ||
class Issue < SimpleDelegator | ||
MULTIPLIER_REGEX = %r{\[([\d\.]+)\/([\d\.]+)\]} | ||
DEFAULT_REMEDIATION_POINTS = 50_000 | ||
DEFAULT_BASE_POINTS = 200_000 | ||
DEFAULT_OVERAGE_POINTS = 50_000 | ||
|
||
def initialize(issue, path, cop_list: nil) | ||
@path = path | ||
@cop_list = cop_list | ||
|
||
super(issue) | ||
end | ||
|
||
# rubocop:disable Metrics/MethodLength | ||
def to_json | ||
hash = { | ||
type: "Issue", | ||
check_name: "Rubocop/#{cop_name}", | ||
description: message, | ||
categories: [category], | ||
remediation_points: remediation_points, | ||
location: { | ||
path: path, | ||
positions: positions, | ||
}, | ||
} | ||
hash[:content] = { body: content_body } if content_body.present? | ||
hash.to_json | ||
end | ||
|
||
def remediation_points | ||
if multiplier? | ||
base_points + overage_points | ||
else | ||
cop_definition.fetch("remediation_points", DEFAULT_REMEDIATION_POINTS) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :path | ||
|
||
def multiplier? | ||
message.match(MULTIPLIER_REGEX) | ||
end | ||
|
||
def base_points | ||
cop_definition.fetch("base_points", DEFAULT_BASE_POINTS) | ||
end | ||
|
||
def cop_definition | ||
@cop_definition ||= cop_list.fetch(cop_name, {}) | ||
end | ||
|
||
def cop_list | ||
@cop_list ||= YAML.load_file(expand_config_path("cops.yml")) | ||
end | ||
|
||
def expand_config_path(path) | ||
File.expand_path("../../../../config/#{path}", __FILE__) | ||
end | ||
|
||
def overage_points | ||
overage_points = cop_definition. | ||
fetch("overage_points", DEFAULT_OVERAGE_POINTS) | ||
|
||
overage_points * multiplier | ||
end | ||
|
||
def multiplier | ||
result = message.scan(MULTIPLIER_REGEX) | ||
score, threshold = result[0] | ||
score.to_i - threshold.to_i | ||
end | ||
|
||
def category | ||
CategoryParser.new(cop_name).category | ||
end | ||
|
||
def positions | ||
{ | ||
begin: { | ||
column: columns.first, | ||
line: lines.first, | ||
}, | ||
end: { | ||
column: columns.last, | ||
line: lines.last, | ||
} | ||
} | ||
end | ||
|
||
# Increments column values as columns are 0-based in parser | ||
def columns | ||
return @columns if defined?(@columns) | ||
|
||
end_column = location.try(:last_column) || location.column | ||
@columns = [location.column + 1, end_column + 1] | ||
end | ||
|
||
def lines | ||
return @lines if defined?(@lines) | ||
|
||
begin_line = location.try(:first_line) || location.line | ||
end_line = location.try(:last_line) || location.line | ||
@lines = [begin_line, end_line] | ||
end | ||
|
||
def content_body | ||
return @content_body if defined?(@content_body) | ||
|
||
content_path = expand_config_path("contents/#{cop_name.underscore}.md") | ||
@content_body = File.exist?(content_path) && File.read(content_path) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.