Skip to content

Commit b0489ce

Browse files
authored
fix: Respect exclude_paths in reek config (#538)
Add ability to exclude files from Reek analysis using the `exclude_paths` option in `.reek.yml`. Updated the analyser to skip excluded files and added tests to verify excluded files are ignored. Also added a sample excluded file for testing. Fixes: #537
1 parent e441ce6 commit b0489ce

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

.reek.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
exclude_paths:
3+
- test/samples/reek/excluded.rb
24
detectors:
35
InstanceVariableAssumption:
46
exclude:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [FEATURE] ...
77

88
* [CHORE] Uses prism instead of parser for Ruby 3.4 and above (by [@torresga][] and [@julioalucero][])
9+
* [BUGFIX] Respect excluded paths from .reek configuration file during reek analysis (by [@fbuys][])
910

1011
# v4.11.0 / 2025-10-15 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.10.0...v4.11.0)
1112

lib/rubycritic/analysers/smells/reek.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ReekSmells
1010
include Colorize
1111

1212
def initialize(analysed_modules)
13-
@analysed_modules = analysed_modules
13+
@analysed_modules = analysed_modules.reject { Reek.configuration.path_excluded?(_1.pathname) }
1414
end
1515

1616
def run

test/lib/rubycritic/analysers/smells/reek_test.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
describe RubyCritic::Analyser::ReekSmells do
77
context 'when analysing a smelly file' do
88
before do
9-
pathname = Pathname.new('test/samples/reek/smelly.rb')
10-
@analysed_module = AnalysedModuleDouble.new(pathname: pathname, smells: [])
11-
analysed_modules = [@analysed_module]
9+
# Reset Reek configuration between tests
10+
# Config is cached and can leak between tests
11+
RubyCritic::Reek.instance_variable_set(:@configuration, nil)
12+
13+
analysed_path = Pathname.new('test/samples/reek/smelly.rb')
14+
@analysed_module = AnalysedModuleDouble.new(pathname: analysed_path, smells: [])
15+
16+
excluded_path = Pathname.new('test/samples/reek/excluded.rb')
17+
@excluded_module = AnalysedModuleDouble.new(pathname: excluded_path, smells: [])
18+
19+
analysed_modules = [@analysed_module, @excluded_module]
1220
RubyCritic::Analyser::ReekSmells.new(analysed_modules).run
1321
end
1422

@@ -22,6 +30,10 @@
2230
_(messages).wont_include "has the parameter name 'a'"
2331
end
2432

33+
it 'ignores excluded files' do
34+
_(@excluded_module.smells).must_be :empty?
35+
end
36+
2537
it 'creates smells with messages' do
2638
first_smell = @analysed_module.smells.first
2739

test/lib/rubycritic/generators/lint_report_test.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
require 'test_helper'
44
require 'rubycritic/analysers_runner'
55
require 'rubycritic/generators/lint_report'
6-
require 'fakefs/safe'
76

87
describe RubyCritic::Generator::LintReport do
98
describe '#generate_report' do
10-
around do |example|
11-
capture_output_streams do
12-
with_cloned_fs(&example)
13-
end
9+
before do
10+
# Reset Reek configuration between tests
11+
# Config is cached and can leak between tests
12+
RubyCritic::Reek.instance_variable_set(:@configuration, nil)
1413
end
1514

1615
it 'report file has data inside' do
17-
sample_files = Dir['test/samples/**/*.rb'].reject { |f| File.empty?(f) }
16+
sample_files = Dir['test/samples/**/*.rb'].reject { |f| File.empty?(f) || f.include?('excluded') }
1817
create_analysed_modules_collection
1918
generate_report
2019
lines = File.readlines('test/samples/lint.txt').map(&:strip).reject(&:empty?)

test/samples/reek/excluded.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Tyrion
2+
def reeks?(reek = true)
3+
reek
4+
end
5+
6+
def flayed?(a)
7+
a
8+
end
9+
end
10+
11+
# Reek should exclude this file entirely based on the .reek.yml configuration

0 commit comments

Comments
 (0)