Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump rubocop to 0.37.2 #48

Merged
merged 8 commits into from
Feb 11, 2016
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
6 changes: 2 additions & 4 deletions Gemfile
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
60 changes: 31 additions & 29 deletions Gemfile.lock
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
13 changes: 4 additions & 9 deletions Rakefile
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
18 changes: 10 additions & 8 deletions config/cops.yml
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
14 changes: 7 additions & 7 deletions lib/cc/engine/file_list_resolver.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module CC
module Engine
class FileListResolver
def initialize(code:, engine_config: {}, rubocop_config_store:)
@code = code
def initialize(root:, engine_config: {}, config_store:)
@root = root
@exclude_paths = engine_config["exclude_paths"] || []
@include_paths = engine_config["include_paths"]
@rubocop_config_store = rubocop_config_store
@config_store = config_store
end

def expanded_list
Expand Down Expand Up @@ -39,21 +39,21 @@ def include_based_files_to_inspect
end

def local_path(path)
realpath = Pathname.new(@code).realpath.to_s
realpath = Pathname.new(@root).realpath.to_s
path.gsub(%r{^#{realpath}/}, '')
end

def rubocop_file_to_include?(file)
if file =~ /\.rb$/
true
else
dir, basename = File.split(file)
@rubocop_config_store.for(dir).file_to_include?(basename)
root, basename = File.split(file)
@config_store.for(root).file_to_include?(basename)
end
end

def rubocop_runner
@rubocop_runner ||= RuboCop::Runner.new({}, @rubocop_config_store)
@rubocop_runner ||= RuboCop::Runner.new({}, @config_store)
end
end
end
Expand Down
122 changes: 122 additions & 0 deletions lib/cc/engine/issue.rb
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
Loading