blooper05 / danger-reek Goto Github PK
View Code? Open in Web Editor NEWA Danger plugin to lint Ruby files through Reek.
Home Page: https://rubygems.org/gems/danger-reek
License: MIT License
A Danger plugin to lint Ruby files through Reek.
Home Page: https://rubygems.org/gems/danger-reek
License: MIT License
e.g. Gemfile.lock, README.md and YAML files
I love danger
& its plugin gems. They are always a part of my CI suite. I would like to express my gratitude to the maintainers of this project. 👏👏👏
def lint
files_to_lint = fetch_files_to_lint
code_smells = run_linter(files_to_lint)
warn_each_line(code_smells)
end
fetch_files_to_lint = git.modified_files + git.added_files
examiner
object for each files & evaluates it's smells.run_linter(files_to_lint)
def run_linter(files_to_lint)
configuration = ::Reek::Configuration::AppConfiguration.from_path(nil)
files_to_lint.flat_map do |file|
examiner = ::Reek::Examiner.new(file, configuration: configuration)
examiner.smells
end
end
examiner = ::Reek::Examiner.new(file, configuration: configuration)
This examiner does not check if the file path is in exclude_paths
on Reek configuration. And as such, posts warning messages on PR.
exclude_paths
is .reek.yml
has no effect.
exclude_paths:
- db/migrate
It gets particularly annoying if you add migration files. It posts FeatureEnvy
message on each files.
Refers to 't' more than self
I made it work with the following change:
module MyDanger
module ReekDecorator
private
def fetch_files_to_lint
files = git.modified_files + git.added_files
excluded_files = files.to_a.select { |file| file_excluded?(file) }
files_to_lint = files - excluded_files
::Reek::Source::SourceLocator.new(files_to_lint).sources
end
def file_excluded?(filename)
configuration = ::Reek::Configuration::AppConfiguration.from_path(nil)
configuration.send(:excluded_paths).map(&:expand_path).map do |excluded_path|
Pathname(filename).expand_path.fnmatch?(File.join(excluded_path, '**'))
end.any?
end
end
end
Danger::DangerReek.prepend(MyDanger::ReekDecorator)
fetch_files_to_lint
method to discard files in excluded_paths
pathIt would be great to have some community feedback on this.
I can create a PR if my proposed solution is agreeable.
Currently, a comment left by danger-reek looks like this:
spec/rails_helper.rb#L49Doesn’t depend on instance state (maybe move it to another class?)
To find out which smell this is, you need to grep the reek source for the comment text. (It's also quite difficult to read with no space between the line number and the text…)
It's also not even particularly obvious that the comment was injected by danger-reek, and not something else in the Dangerfile.
Would it be possible for the comment to look like this instead?
spec/rails_helper.rb#L49 [Reek:UtilityFunction] Doesn’t depend on instance state (maybe move it to another class?)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.