Giter Site home page Giter Site logo

danger-reek's Introduction

Hi there 👋

Ruby TypeScript Docker Terraform CLI

danger-reek's People

Contributors

blooper05 avatar dependabot-preview[bot] avatar dependabot-support avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

danger-reek's Issues

Handling `exclude_paths` in reek configuration

Acknowledgement

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. 👏👏👏

Current Behavior

Danger::DangerReek

def lint
  files_to_lint = fetch_files_to_lint
  code_smells   = run_linter(files_to_lint)
  warn_each_line(code_smells)
end

Step Analysis

  1. Builds a file list to examine, basically all changed files
fetch_files_to_lint = git.modified_files + git.added_files
  1. Builds an 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.

Issue

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

Proposed Enhancement

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)
  • It basically modifies fetch_files_to_lint method to discard files in excluded_paths path

It would be great to have some community feedback on this.

I can create a PR if my proposed solution is agreeable.

Show smell name as well as description

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?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.