Skip to content

Commit 2e51fde

Browse files
committed
Less RuboCop, fix use on projects with rubocop config
1 parent 3722a24 commit 2e51fde

File tree

5 files changed

+23
-33
lines changed

5 files changed

+23
-33
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LABEL maintainer="Jacob Frautschi <[email protected]>"
44

55
WORKDIR /usr/src/app
66

7-
RUN adduser -u 9000 -D app
7+
RUN adduser -u 9000 -g 9000 -D app
88

99
COPY Gemfile Gemfile.lock /usr/src/app/
1010

engine.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "Standard",
2+
"name": "codeclimate-standard",
33
"description": "Standard is an opinionated wrapper around RuboCop with no configuration necessary.",
44
"maintainer": {
55
"name": "Jacob Frautschi",
66
"email": "[email protected]"
77
},
88
"languages" : ["Ruby"],
9-
"version": "0.6.0a",
9+
"version": "0.6.0b",
1010
"spec_version": "0.3.1"
1111
}

lib/cc/engine/file_list_resolver.rb

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
module CC
22
module Engine
33
class FileListResolver
4-
def initialize(root:, config_store:, engine_config: {})
4+
def initialize(root:, builds_config:, engine_config: {})
55
@root = root
66
@include_paths = engine_config["include_paths"] || ["./"]
7-
@config_store = config_store
7+
@builds_config = builds_config
88
end
99

1010
def expanded_list
1111
absolute_include_paths.flat_map { |path|
12-
if Dir.exist?(path)
13-
rubocop_runner.send(:find_target_files, [path])
14-
elsif rubocop_file_to_include?(path)
15-
path
16-
end
12+
find_target_files(path)
1713
}.compact
1814
end
1915

2016
private
2117

22-
attr_reader :config_store
23-
2418
def absolute_include_paths
2519
@include_paths.map { |path| to_absolute_path(path) }.compact
2620
end
@@ -31,17 +25,13 @@ def to_absolute_path(path)
3125
nil
3226
end
3327

34-
def rubocop_file_to_include?(file)
35-
root, basename = File.split(file)
36-
store = config_store.for(root)
37-
38-
return false if store.file_to_exclude?(basename)
39-
40-
file =~ /\.rb$/ || store.file_to_include?(basename)
28+
def find_target_files(path)
29+
target_files = target_finder.find([path], :all_file_types)
30+
target_files.each(&:freeze).freeze
4131
end
4232

43-
def rubocop_runner
44-
@rubocop_runner ||= RuboCop::Runner.new({}, @config_store)
33+
def target_finder
34+
@target_finder ||= RuboCop::TargetFinder.new(@builds_config.rubocop_config_store)
4535
end
4636
end
4737
end

lib/cc/engine/source_file.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module CC
22
module Engine
33
class SourceFile
4-
def initialize(config_store:, io:, path:, root:)
5-
@config_store = config_store
4+
def initialize(builds_config:, io:, path:, root:)
5+
@builds_config = builds_config
66
@io = io
77
@path = path
88
@root = root
@@ -19,23 +19,23 @@ def inspect
1919

2020
private
2121

22-
attr_reader :config_store, :io, :path, :root
22+
attr_reader :builds_config, :io, :path, :root
2323

2424
def processed_source
2525
RuboCop::ProcessedSource.from_file(path, target_ruby_version)
2626
end
2727

28+
def config_store
29+
builds_config.rubocop_config_store.for_file(path)
30+
end
31+
2832
def target_ruby_version
2933
config_store.target_ruby_version
3034
end
3135

3236
def rubocop_team
33-
config = ::Standard::BuildsConfig.new.call([])
34-
3537
cop_classes = RuboCop::Cop::Registry.all
36-
registry = RuboCop::Cop::Registry.new(cop_classes, config.rubocop_options)
37-
38-
config_store = config.rubocop_config_store.for_file(path)
38+
registry = RuboCop::Cop::Registry.new(cop_classes, builds_config.rubocop_options)
3939

4040
RuboCop::Cop::Team.new(registry, config_store, display_cop_names: false)
4141
end

lib/cc/engine/standard.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def run
2424
Dir.chdir(root) do
2525
files_to_inspect.each do |path|
2626
SourceFile.new(
27-
config_store: config_store.for(path),
27+
builds_config: builds_config,
2828
io: io,
2929
path: path,
3030
root: root
@@ -39,14 +39,14 @@ def run
3939

4040
def files_to_inspect
4141
@files_to_inspect ||= FileListResolver.new(
42-
config_store: config_store,
42+
builds_config: builds_config,
4343
engine_config: engine_config,
4444
root: root
4545
).expanded_list
4646
end
4747

48-
def config_store
49-
@config_store ||= RuboCop::ConfigStore.new
48+
def builds_config
49+
@builds_config ||= ::Standard::BuildsConfig.new.call([])
5050
end
5151
end
5252
end

0 commit comments

Comments
 (0)