Skip to content

Commit

Permalink
add configurable severity for reek smells
Browse files Browse the repository at this point in the history
fixes #15
  • Loading branch information
Drowze committed Jun 1, 2021
1 parent 8834747 commit 8f0e29d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ Pronto runner for [Reek](https://github.com/troessner/reek), code smell detector
## Configuration

Configuring Reek via [config.reek](https://github.com/troessner/reek#configuration-file), or any file ending with .reek, will work just fine with pronto-reek.

You can also specify a custom severity level for the reek smells with the environment variable PRONTO_REEK_SEVERITY_LEVEL.

Or if you prefer provide it on your `.pronto.yml` (environment variable has precedence over file):

```yaml
reek:
severity_level: warning # default is info
```
10 changes: 9 additions & 1 deletion lib/pronto/reek.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pronto'
require 'reek'

Expand Down Expand Up @@ -35,13 +37,19 @@ def new_message(line, error)
path = line.patch.delta.new_file[:path]
message = "#{error.message.capitalize} - [#{error.smell_type}](#{error.explanatory_link})"

Message.new(path, line, :info, message, nil, self.class)
Message.new(path, line, severity_level, message, nil, self.class)
end

def patch_for_error(error)
ruby_patches.find do |patch|
patch.new_file_full_path.relative_path_from(Pathname.pwd).to_s == error.source
end
end

def severity_level
@severity_level ||= begin
ENV['PRONTO_REEK_SEVERITY_LEVEL'] || Pronto::ConfigFile.new.to_h.dig('reek', 'severity_level') || :info
end.to_sym
end
end
end
14 changes: 14 additions & 0 deletions spec/pronto/reek_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

module Pronto
Expand Down Expand Up @@ -32,6 +34,18 @@ module Pronto
should \
match(/Has the variable name '@n' - \[UncommunicativeVariableName\]\(https:\/\/github.com\/troessner\/reek\/blob\/v\d+\.\d+\.\d+\/docs\/Uncommunicative-Variable-Name.md\)/)
end

context 'when severity level configured on environment variable' do
before { stub_const('ENV', 'PRONTO_REEK_SEVERITY_LEVEL' => 'fatal') }

its(:'first.level') { should == :fatal }
end

context 'when severity level configured on file' do
before { Pronto::ConfigFile.stub(:new).and_return('reek' => { 'severity_level' => 'error' }) }

its(:'first.level') { should == :error }
end
end

context 'patches with additions to non-ruby files' do
Expand Down

0 comments on commit 8f0e29d

Please sign in to comment.