Skip to content

Commit

Permalink
Set Hound up to Flog Ruby changes
Browse files Browse the repository at this point in the history
Before, we only checked Ruby files using Rubocop. This only allowed us
to comment on the style of the files. Added a Flog integration which
will comment on Ruby methods that are too complex.
  • Loading branch information
Rob Whittaker committed Jan 26, 2017
1 parent 8728727 commit 4bc8707
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/jobs/flog_review_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class FlogReviewJob
@queue = :flog_review
end
2 changes: 2 additions & 0 deletions app/models/hound_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class HoundConfig
Linter::CoffeeScript,
Linter::Credo,
Linter::Eslint,
Linter::Flog,
Linter::Go,
Linter::Haml,
Linter::Jshint,
Expand All @@ -17,6 +18,7 @@ class HoundConfig
BETA_LINTERS = %w(
credo
eslint
flog
remark
python
tslint
Expand Down
6 changes: 5 additions & 1 deletion app/models/linter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def name
def build_review_job_attributes(commit_file)
{
commit_sha: build.commit_sha,
config: config.serialize,
config: serialized_configuration,
content: commit_file.content,
filename: commit_file.filename,
linter_name: name,
Expand Down Expand Up @@ -73,5 +73,9 @@ def config
owner: owner,
)
end

def serialized_configuration
config.serialize
end
end
end
11 changes: 11 additions & 0 deletions app/models/linter/flog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Linter
class Flog < Base
FILE_REGEXP = /.+\.r(b|ake)\z/

private

def serialized_configuration
"--- {}\n"
end
end
end
85 changes: 85 additions & 0 deletions spec/models/linter/flog_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
require "rails_helper"

module Linter
RSpec.describe Flog do
describe ".can_lint?" do
context "when given a '.rb' file" do
it "is true" do
expect(Flog.can_lint?("foo.rb")).to be(true)
end
end

context "when given a '.rake' file" do
it "is true" do
expect(Flog.can_lint?("foo.rake")).to be(true)
end
end

context "when given a non-Ruby file" do
it "is false" do
expect(Flog.can_lint?("foo.js")).to be(false)
end
end
end

describe "#enabled?" do
context "when Flog linting is enabled" do
it "is true" do
build = instance_double("Build")
hound_config = instance_double("HoundConfig", linter_enabled?: true)
linter = Flog.new(build: build, hound_config: hound_config)

expect(linter).to be_enabled
end
end
end

describe "#file_included?" do
it "is always true" do
build = instance_double("Build")
hound_config = instance_double("HoundConfig", linter_enabled?: true)
linter = Flog.new(build: build, hound_config: hound_config)

expect(linter.file_included?).to be(true)
end
end

describe "#file_review" do
it "is a new file review" do
repo = instance_double("Repo", owner: nil)
build = instance_double(
"Build",
commit_sha: "somesha",
pull_request_number: 123,
repo: repo,
)
commit_file = instance_double(
"CommitFile",
content: "code",
filename: "lib/ruby.rb",
patch: "patch",
)
file_review = instance_double("FileReview")
hound_config = instance_double("HoundConfig")
missing_owner = instance_double("MissingOwner")
allow(FileReview).to receive(:create!).and_return(file_review)
allow(MissingOwner).to receive(:new).and_return(missing_owner)
allow(Resque).to receive(:enqueue)
linter = Flog.new(build: build, hound_config: hound_config)

expect(linter.file_review(commit_file)).to eq file_review
expect(Resque).to have_received(:enqueue)
end
end

describe "#name" do
it "is the class name converted to a config-friendly format" do
build = instance_double("Build")
hound_config = instance_double("HoundConfig")
linter = Flog.new(build: build, hound_config: hound_config)

expect(linter.name).to eq "flog"
end
end
end
end

0 comments on commit 4bc8707

Please sign in to comment.