Skip to content

Commit 78a9e2b

Browse files
authored
Merge pull request #1826 from troessner/issue-853-improve-reek-task-env-var-handling
Fix handling of env vars overriding reek task definitions
2 parents e2e3d5e + 88d46ad commit 78a9e2b

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

features/rake_task/rake_task.feature

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,48 @@ Feature: Reek can be driven through its Task
136136
[4]:UncommunicativeMethodName: Smelly#x has the name 'x'
137137
[5]:UncommunicativeVariableName: Smelly#x has the variable name 'y'
138138
"""
139+
140+
Scenario: REEK_CFG overrides the configuration file to use
141+
Given the smelly file 'smelly.rb'
142+
And a configuration file 'empty.reek'
143+
And a configuration file 'full_mask.reek'
144+
And a file "Rakefile" with:
145+
"""
146+
require 'reek/rake/task'
147+
148+
Reek::Rake::Task.new do |t|
149+
t.config_file = 'full_mask.reek'
150+
t.source_files = 'smelly.rb'
151+
t.reek_opts = '--no-color --no-documentation'
152+
end
153+
"""
154+
When I set the environment variable "REEK_CFG" to "empty.reek"
155+
And I run `rake reek`
156+
Then the exit status indicates an error
157+
And it reports:
158+
"""
159+
smelly.rb -- 2 warnings:
160+
[4]:UncommunicativeMethodName: Smelly#x has the name 'x'
161+
[5]:UncommunicativeVariableName: Smelly#x has the variable name 'y'
162+
"""
163+
164+
Scenario: REEK_OPTS overrides options to use
165+
Given the smelly file 'smelly.rb'
166+
And a file "Rakefile" with:
167+
"""
168+
require 'reek/rake/task'
169+
170+
Reek::Rake::Task.new do |t|
171+
t.source_files = 'smelly.rb'
172+
t.reek_opts = '--no-color --no-documentation'
173+
end
174+
"""
175+
When I set the environment variable "REEK_OPTS" to "--single-line --no-documentation"
176+
And I run `rake reek`
177+
Then the exit status indicates an error
178+
And it reports:
179+
"""
180+
smelly.rb -- 2 warnings:
181+
smelly.rb:4: UncommunicativeMethodName: Smelly#x has the name 'x'
182+
smelly.rb:5: UncommunicativeVariableName: Smelly#x has the variable name 'y'
183+
"""

lib/reek/rake/task.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ class Task < ::Rake::TaskLib
6969

7070
# @public
7171
def initialize(name = :reek)
72-
@config_file = ENV.fetch('REEK_CFG', nil)
7372
@name = name
74-
@reek_opts = ENV.fetch('REEK_OPTS', '')
73+
@reek_opts = ''
7574
@fail_on_error = true
7675
@verbose = false
7776

7877
yield self if block_given?
7978

79+
if (reek_cfg = ENV.fetch('REEK_CFG', nil))
80+
@config_file = reek_cfg
81+
end
82+
if (reek_opts = ENV.fetch('REEK_OPTS', nil))
83+
@reek_opts = reek_opts
84+
end
8085
if (reek_src = ENV.fetch('REEK_SRC', nil))
8186
@source_files = FileList[reek_src]
8287
end

0 commit comments

Comments
 (0)