Skip to content

Commit

Permalink
Allow excluding files to lint for single runner
Browse files Browse the repository at this point in the history
```
eslint:
  exclude:
    - 'app/assets/**/*'
```
  • Loading branch information
astrauka committed Oct 17, 2016
1 parent 87b77ae commit a23fedc
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 75 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions lib/pronto/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
17 changes: 0 additions & 17 deletions lib/pronto/formatter/github_status_formatter/inflector.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require_relative 'sentence'
require_relative 'inflector'

module Pronto
module Formatter
Expand All @@ -20,7 +19,7 @@ def state
end

def context
Inflector.underscore(@runner.name)
"pronto/#{@runner.title}"
end

private
Expand Down
8 changes: 8 additions & 0 deletions lib/pronto/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 12 additions & 10 deletions lib/pronto/runners.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ 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
end

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)
Expand Down
2 changes: 1 addition & 1 deletion lib/pronto/version.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
27 changes: 0 additions & 27 deletions spec/pronto/formatter/github_status_formatter/inflector_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/pronto/formatter/github_status_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion spec/pronto/runners_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,6 +12,10 @@ module Pronto

context 'fake runner' do
class FakeRunner
def self.title
'fake_runner'
end

def initialize(_, _)
end

Expand Down
4 changes: 4 additions & 0 deletions spec/pronto_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module Pronto

context 'a single runner' do
class Shakespeare
def self.title
'shakespeare'
end

def initialize(patches, _)
@patches = patches
end
Expand Down

0 comments on commit a23fedc

Please sign in to comment.