diff --git a/Dockerfile b/Dockerfile index 90376d4..fbf53b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,17 @@ -FROM ruby:2.6-alpine +FROM ruby:2.7.7-alpine3.16 -MAINTAINER Ryan Davis +LABEL maintainer="Ryan Davis" WORKDIR /usr/src/app -RUN gem install --silent hoe minitest rake && \ - gem install ruby_parser --version 3.13.1 && \ - gem install --silent flog -N -v "~> 4.6" # currently 4.6.4 +COPY Gemfile /usr/src/app/ +COPY Gemfile.lock /usr/src/app/ -RUN adduser -u 9000 -D -h /usr/src/app -s /bin/false app +RUN apk update && \ + apk add git && \ + bundle + +RUN adduser -u 9000 -D -g "app" app COPY . /usr/src/app RUN chown -R app:app /usr/src/app diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..16fed1a --- /dev/null +++ b/Gemfile @@ -0,0 +1,12 @@ +source "https://rubygems.org" + +gem "hoe" +gem "minitest" +gem "rake" +gem "ruby_parser", "3.13.1" +gem "flog", "~> 4.6" + +group :test do + gem "rspec" + gem "simplecov" +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..5b9ad01 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,51 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.5.0) + docile (1.4.0) + flog (4.6.6) + path_expander (~> 1.0) + ruby_parser (~> 3.1, > 3.1.0) + sexp_processor (~> 4.8) + hoe (4.0.1) + rake (>= 0.8, < 15.0) + minitest (5.16.3) + path_expander (1.1.1) + rake (13.0.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + ruby_parser (3.13.1) + sexp_processor (~> 4.9) + sexp_processor (4.16.1) + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + +PLATFORMS + ruby + +DEPENDENCIES + flog (~> 4.6) + hoe + minitest + rake + rspec + ruby_parser (= 3.13.1) + simplecov + +BUNDLED WITH + 2.1.4 diff --git a/lib/cc/engine/flog.rb b/lib/cc/engine/flog.rb index 10c82a9..7bae3e8 100644 --- a/lib/cc/engine/flog.rb +++ b/lib/cc/engine/flog.rb @@ -25,20 +25,17 @@ class Flog } def initialize(root, config = {}, io = STDOUT) - self.dir = root - self.config = config = normalize_conf config - self.io = io + @dir = root + @config = config = normalize_conf(config) + @io = io - options = { - :all => true, - :continue => true, - } + options = { all: true, continue: true } - self.flog = ::Flog.new options + @flog = ::Flog.new(options) paths = config["include_paths"].dup - expander = PathExpander.new paths, "**/*.{rb,rake}" - self.files = expander.process.select { |s| s =~ /\.(?:rb|rake)$/ } + expander = PathExpander.new(paths, "**/*.{rb,rake}") + @files = expander.process.select { |s| s =~ /\.(?:rb|rake)$/ } end ## @@ -49,13 +46,13 @@ def initialize(root, config = {}, io = STDOUT) # https://github.com/codeclimate/codeclimate-yaml/issues/38 # https://github.com/codeclimate/codeclimate-yaml/issues/39 - def normalize_conf top_config + def normalize_conf(top_config) # fix the top, if necessary - top_config = reparse top_config + top_config = reparse(top_config) top_config["config"] ||= {} # normalize contents - config = DEFAULTS.merge top_config["config"] + config = DEFAULTS.merge(top_config["config"]) config["include_paths"] = top_config["include_paths"] if top_config["include_paths"] @@ -68,13 +65,13 @@ def normalize_conf top_config # "false" break a lot of logic. This method reparses the values, # recursively if necessary. - def reparse val + def reparse(val) require "yaml" case val when String then - YAML.load val + YAML.safe_load(val) when Array then - val.map { |v| reparse v } + val.map { |v| reparse(v) } when Hash then Hash[val.map { |k, v| [reparse(k), reparse(v)] }] else @@ -86,7 +83,7 @@ def reparse val # Run flog and print issues as they come up. def run - Dir.chdir dir do + Dir.chdir(dir) do flog.flog(*files) flog.each_by_score do |name, score, call_list| @@ -96,7 +93,7 @@ def run next unless score > config["score_threshold"] datum = "Complex method %s (%.1f)" % [name, score] - issue = self.issue name, datum, location, score + issue = issue(name, datum, location, score) if issue then io.print issue.to_json @@ -119,7 +116,7 @@ def run ## # Create an issue hash from +name+, +datum+, +location+, and +score+. - def issue name, datum, location, score + def issue(name, datum, location, score) file, l_start, l_end = [$1, $2.to_i, $3.to_i] if location =~ /^(.+?):(\d+)-(\d+)$/