From a23fedc0f54739367f0f6225596d7931e95c5b0c Mon Sep 17 00:00:00 2001 From: Karolis Astrauka Date: Mon, 17 Oct 2016 13:38:35 +0300 Subject: [PATCH] Allow excluding files to lint for single runner ``` eslint: exclude: - 'app/assets/**/*' ``` --- README.md | 18 ++++++++----- lib/pronto/config.rb | 17 ++++++------ .../github_status_formatter/inflector.rb | 17 ------------ .../github_status_formatter/status_builder.rb | 3 +-- lib/pronto/runner.rb | 8 ++++++ lib/pronto/runners.rb | 22 ++++++++------- lib/pronto/version.rb | 2 +- .../github_status_formatter/inflector_spec.rb | 27 ------------------- .../formatter/github_status_formatter_spec.rb | 4 +-- spec/pronto/runners_spec.rb | 6 ++++- spec/pronto_spec.rb | 4 +++ 11 files changed, 53 insertions(+), 75 deletions(-) delete mode 100644 lib/pronto/formatter/github_status_formatter/inflector.rb delete mode 100644 spec/pronto/formatter/github_status_formatter/inflector_spec.rb diff --git a/README.md b/README.md index 707ee355..886f8e30 100644 --- a/README.md +++ b/README.md @@ -74,13 +74,13 @@ Just run `pronto` without any arguments to see what Pronto is capable of. Available Options -Command flag | Description ------------------|------------------------------------------------------------ -`--exit-code` | Exits with non-zero code if there were any warnings/errors. -`-c/--commit` | Commit for the diff. -`-i/--index` | Analyze changes in git index (staging area). -`-r/--runner` | Run only the passed runners. -`-f/--formatters`| Pick output formatters. +| Command flag | Description | +|:------------------|:------------------------------------------------------------| +| `--exit-code` | Exits with non-zero code if there were any warnings/errors. | +| `-c/--commit` | Commit for the diff. | +| `-i/--index` | Analyze changes in git index (staging area). | +| `-r/--runner` | Run only the passed runners. | +| `-f/--formatters` | Pick output formatters. | ### GitHub Integration @@ -180,6 +180,10 @@ The file has the following format: all: exclude: - 'spec/**/*' +# exclude files for single runner +eslint: + exclude: + - 'app/assets/**/*' github: slug: mmozuras/pronto access_token: B26354 diff --git a/lib/pronto/config.rb b/lib/pronto/config.rb index 0dad4ca8..94abc6e1 100644 --- a/lib/pronto/config.rb +++ b/lib/pronto/config.rb @@ -16,8 +16,15 @@ def consolidate_comments? !(consolidated).nil? end - def excluded_files - @excluded_files ||= Array(exclude) + def excluded_files(runner) + files = + if runner == 'all' + ENV['PRONTO_EXCLUDE'] || @config_hash['all']['exclude'] + else + @config_hash.fetch(runner, {})['exclude'] + end + + Array(files) .flat_map { |path| Dir[path.to_s] } .map { |path| File.expand_path(path) } end @@ -40,11 +47,5 @@ def logger verbose ? Logger.new($stdout) : Logger.silent end end - - private - - def exclude - ENV['PRONTO_EXCLUDE'] || @config_hash['all']['exclude'] - end end end diff --git a/lib/pronto/formatter/github_status_formatter/inflector.rb b/lib/pronto/formatter/github_status_formatter/inflector.rb deleted file mode 100644 index b141370c..00000000 --- a/lib/pronto/formatter/github_status_formatter/inflector.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Pronto - module Formatter - class GithubStatusFormatter - class Inflector - def self.underscore(camel_cased_word) - return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/ - word = camel_cased_word.to_s.gsub(/::/, '/') - word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') - word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') - word.tr!('-', '_') - word.downcase! - word - end - end - end - end -end diff --git a/lib/pronto/formatter/github_status_formatter/status_builder.rb b/lib/pronto/formatter/github_status_formatter/status_builder.rb index 79d04918..884c4a91 100644 --- a/lib/pronto/formatter/github_status_formatter/status_builder.rb +++ b/lib/pronto/formatter/github_status_formatter/status_builder.rb @@ -1,5 +1,4 @@ require_relative 'sentence' -require_relative 'inflector' module Pronto module Formatter @@ -20,7 +19,7 @@ def state end def context - Inflector.underscore(@runner.name) + "pronto/#{@runner.title}" end private diff --git a/lib/pronto/runner.rb b/lib/pronto/runner.rb index e4e10277..dbfdaec8 100644 --- a/lib/pronto/runner.rb +++ b/lib/pronto/runner.rb @@ -11,6 +11,14 @@ def self.runners repository end + def self.title + @runner_name ||= begin + source_path, _line = instance_method(:run).source_location + file_name, _extension = File.basename(source_path).split('.') + file_name + end + end + def ruby_patches return [] unless @patches diff --git a/lib/pronto/runners.rb b/lib/pronto/runners.rb index eaede29a..920a54d2 100644 --- a/lib/pronto/runners.rb +++ b/lib/pronto/runners.rb @@ -6,14 +6,18 @@ def initialize(runners = Runner.runners, config = Config.new) end def run(patches) - patches = reject_excluded(patches) - return [] unless patches.any? + patches = reject_excluded(@config.excluded_files('all'), patches) + return [] if patches.none? result = [] @runners.each do |runner| next if exceeds_max?(result) @config.logger.log("Running #{runner}") - result += runner.new(patches, patches.commit).run.flatten.compact + runner_patches = reject_excluded( + @config.excluded_files(runner.title), patches + ) + next if runner_patches.none? + result += runner.new(runner_patches, patches.commit).run.flatten.compact end result = result.take(@config.max_warnings) if @config.max_warnings result @@ -21,14 +25,12 @@ def run(patches) private - def reject_excluded(patches) - return patches unless @config.excluded_files.any? - patches.reject! { |patch| excluded?(patch) } - patches - end + def reject_excluded(excluded_files, patches) + return patches unless excluded_files.any? - def excluded?(patch) - @config.excluded_files.include?(patch.new_file_full_path.to_s) + patches.reject do |patch| + excluded_files.include?(patch.new_file_full_path.to_s) + end end def exceeds_max?(warnings) diff --git a/lib/pronto/version.rb b/lib/pronto/version.rb index e700a563..272e0b75 100644 --- a/lib/pronto/version.rb +++ b/lib/pronto/version.rb @@ -1,6 +1,6 @@ module Pronto module Version - STRING = '0.7.1'.freeze + STRING = '0.7.2'.freeze MSG = '%s (running on %s %s %s)'.freeze diff --git a/spec/pronto/formatter/github_status_formatter/inflector_spec.rb b/spec/pronto/formatter/github_status_formatter/inflector_spec.rb deleted file mode 100644 index d7f67db4..00000000 --- a/spec/pronto/formatter/github_status_formatter/inflector_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -module Pronto - module Formatter - RSpec.describe GithubStatusFormatter::Inflector do - describe '#underscore' do - subject { described_class.underscore(class_name) } - - context 'when class is just one word' do - let(:class_name) { 'Pronto::Runner' } - - it { should == 'pronto/runner' } - end - - context 'when class contains camel case' do - let(:class_name) { 'Pronto::FakeRunner' } - - it { should == 'pronto/fake_runner' } - end - - context 'when class contains acronym' do - let(:class_name) { 'Pronto::SUPERFakeRunner' } - - it { should == 'pronto/super_fake_runner' } - end - end - end - end -end diff --git a/spec/pronto/formatter/github_status_formatter_spec.rb b/spec/pronto/formatter/github_status_formatter_spec.rb index 1249481f..c579b26f 100644 --- a/spec/pronto/formatter/github_status_formatter_spec.rb +++ b/spec/pronto/formatter/github_status_formatter_spec.rb @@ -9,8 +9,8 @@ module Formatter let(:repo) { Git::Repository.new('spec/fixtures/test.git') } let(:runner_class) do Class.new do - def self.name - 'Pronto::FakeRunner' + def self.title + 'fake_runner' end end end diff --git a/spec/pronto/runners_spec.rb b/spec/pronto/runners_spec.rb index 3620ae65..c73ef1c4 100644 --- a/spec/pronto/runners_spec.rb +++ b/spec/pronto/runners_spec.rb @@ -2,7 +2,7 @@ module Pronto describe Runners do describe '#run' do subject { described_class.new(runners, config).run(patches) } - let(:patches) { double(commit: nil, any?: true) } + let(:patches) { double(commit: nil, none?: false) } let(:config) { Config.new } context 'no runners' do @@ -12,6 +12,10 @@ module Pronto context 'fake runner' do class FakeRunner + def self.title + 'fake_runner' + end + def initialize(_, _) end diff --git a/spec/pronto_spec.rb b/spec/pronto_spec.rb index e607fd98..17851ddc 100644 --- a/spec/pronto_spec.rb +++ b/spec/pronto_spec.rb @@ -18,6 +18,10 @@ module Pronto context 'a single runner' do class Shakespeare + def self.title + 'shakespeare' + end + def initialize(patches, _) @patches = patches end