Skip to content

Commit

Permalink
Merge pull request #6 from polishgeeks/final_blank_excluded
Browse files Browse the repository at this point in the history
Final blank excluded
  • Loading branch information
mensfeld committed Aug 31, 2015
2 parents 072ebbf + 907ffff commit 4105893
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 61 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# PolishGeeks Dev Tools Changelog

## 1.1.2

- Ignore .DS_Store files in FinalBlankLine validator.
- Changed FinalBlankLine excluded mechanism. You can define directories and files (ex. lib/command or lib/file.rb). Please don't use path with stars convention (ex. lib/**/*).

## 1.1.1

- Ignore doc directory in FinalBlankLine validator
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
polishgeeks-dev-tools (1.1.1)
polishgeeks-dev-tools (1.1.2)
brakeman
faker
haml-lint
Expand Down Expand Up @@ -148,7 +148,7 @@ GEM
reek (= 1.6.3)
ruby2ruby (>= 2.1.1, < 3.0)
virtus (~> 1.0)
sass (3.4.17)
sass (3.4.18)
sexp_processor (4.6.0)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ determine, which you can use in your project:

Some validators might accept additional config settings - please refer to this table for a description on how to use them:

| Option | Validator | Description |
|-------------------------------|-----------------------|-----------------------------------------------------------------------------------------------------|
| rspec_files_structure_ignored | rspec_files_structure | You can provide an array of files that should be ignored |
| final_blank_line_ignored | final_blank_line | You can provide an array of files (ex. lib/file.rb) or paths (ex. lib/\*\*/\*) that should be ignored |
| Option | Validator | Description |
|-------------------------------|-----------------------|-------------------------------------------------------------------------------------------------------------|
| rspec_files_structure_ignored | rspec_files_structure | You can provide an array of files that should be ignored |
| final_blank_line_ignored | final_blank_line | You can provide an array of files (ex. lib/file.rb) or directories (ex. lib/command) that should be ignored |

## Usage in any Rails/Ruby application

Expand Down
44 changes: 19 additions & 25 deletions lib/polishgeeks/dev-tools/command/final_blank_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FinalBlankLine < Base
public
app/assets/images
app/assets/fonts
.DS_Store
)

# Executes this command and set output and counter variables
Expand Down Expand Up @@ -49,40 +50,33 @@ def error_message
private

# @return [Array<String>] array with files to analyze
# @note method take all not excluded files, also with hidden files
def files_to_analyze
# expression {*,.*} is needed because glob method don't take unix-like hidden files
files_from_path('**/{*,.*}') - excludes
files = files_from_path('**/{*,.*}')
remove_excludes files
end

# @return [Array<String>] list of files that
# should be excluded from checking
def excludes
(default_excludes + config_excludes).flatten
end

# @return [Array<String>] list of default excluded files
# defined in DEFAULT_PATHS_TO_EXCLUDE
def default_excludes
excluded_files = []

DEFAULT_PATHS_TO_EXCLUDE.each do |path|
excluded_files << files_from_path("#{path}/**/{*,.*}")
# @param [Array<String>] files list which we want analyse
# @return [Array<String>] array without excluded files
def remove_excludes(files)
excluded_paths = excludes
files.delete_if do |file|
excluded_paths.any? { |exclude| file =~ /#{exclude}/ }
end
end

excluded_files
# @return [Array<String>] list of files/directories that
# should be excluded from checking
# @note excluded files/directories are defined in DEFAULT_PATHS_TO_EXCLUDE
# and in configuration file
def excludes
config_excludes + DEFAULT_PATHS_TO_EXCLUDE
end

# @return [Array<String>] list of excluded files from config file
# @return [Array<String>] list of excluded files/directories from config file
def config_excludes
excluded_files = []
config_paths = DevTools.config.final_blank_line_ignored
return [] unless config_paths

config_paths.each do |path|
excluded_files << files_from_path(path)
end

excluded_files
DevTools.config.final_blank_line_ignored || []
end

# @param [String] path from which we want take files
Expand Down
2 changes: 1 addition & 1 deletion lib/polishgeeks/dev-tools/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module PolishGeeks
# Dev Tools for PolishGeeks developers
module DevTools
# Current version of dev tools
VERSION = '1.1.1'
VERSION = '1.1.2'
end
end
45 changes: 16 additions & 29 deletions spec/lib/polishgeeks/dev-tools/command/final_blank_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,40 @@

describe '#files_to_analyze' do
let(:files) { [rand.to_s, rand.to_s] }
let(:excludes) { [files[0]] }
let(:expected) { [files[1]] }

before do
expect(subject)
.to receive(:files_from_path)
.with('**/{*,.*}')
.and_return(files)

expect(subject)
.to receive(:remove_excludes)
.with(files)
.and_return(files)
end

it { expect(subject.send(:files_to_analyze)).to eq files }
end

describe '#remove_excludes' do
let(:files) { %w(lib/file.txt exclude.txt file.rb) }
let(:excludes) { %w(lib exclude.txt) }

before do
expect(subject)
.to receive(:excludes)
.and_return(excludes)
end

it { expect(subject.send(:files_to_analyze)).to eq expected }
it { expect(subject.send(:remove_excludes, files)).to eq ['file.rb'] }
end

describe '#excludes' do
let(:defaults) { [rand.to_s, rand.to_s] }
let(:configs) { [rand.to_s] }
let(:expected) { (defaults + configs).flatten }
let(:expected) { configs + described_class::DEFAULT_PATHS_TO_EXCLUDE }

before do
expect(subject)
.to receive(:default_excludes)
.and_return(defaults)

expect(subject)
.to receive(:config_excludes)
.and_return(configs)
Expand All @@ -125,19 +132,6 @@
it { expect(subject.send(:excludes)).to eq expected }
end

describe '#default_excludes' do
before do
described_class::DEFAULT_PATHS_TO_EXCLUDE.each do |path|
expect(subject)
.to receive(:files_from_path)
.with("#{path}/**/{*,.*}")
.and_return(path)
end
end

it { expect(subject.send(:default_excludes)).to eq described_class::DEFAULT_PATHS_TO_EXCLUDE }
end

describe '#config_excludes' do
context 'final_blank_line_ignored is set' do
let(:paths) { [rand.to_s, rand.to_s] }
Expand All @@ -147,13 +141,6 @@
expect(PolishGeeks::DevTools)
.to receive(:config)
.and_return config

paths.each do |path|
expect(subject)
.to receive(:files_from_path)
.with("#{path}")
.and_return(path)
end
end

it { expect(subject.send(:config_excludes)).to eq paths }
Expand Down

0 comments on commit 4105893

Please sign in to comment.