fast_ignore 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -7
- data/.rubocop.yml +1 -0
- data/.spellr.yml +5 -0
- data/.spellr_wordlists/english.txt +41 -0
- data/.spellr_wordlists/ruby.txt +1 -0
- data/.spellr_wordlists/shell.txt +3 -0
- data/CHANGELOG.md +5 -2
- data/README.md +1 -0
- data/Rakefile +3 -1
- data/fast_ignore.gemspec +1 -0
- data/lib/fast_ignore.rb +29 -18
- data/lib/fast_ignore/rule_set.rb +4 -10
- data/lib/fast_ignore/rule_set_builder.rb +10 -14
- data/lib/fast_ignore/version.rb +1 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03c81966a545152071086c49d90057bc1950731affd0abdaabfe622c1b357d78
|
4
|
+
data.tar.gz: 312e624e3a542e3ee179d02f11070fe2a78d43cf7304b92a8420071ffdde75aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98af14403dd1ba3dd9ac4800077324ed21d00a0a57e9761e3e720fe81e723de589e016ae78696c8ce173ab60e027361a37181c61492fbd8240a85657612b13ad
|
7
|
+
data.tar.gz: df3f1d628a6f42b8630ee6c8aacc23722720e88e782001809bb4106da68853e365f573b4796b3e0fa828fc640428ac7e820ab6b0eade1a8eee1affbea605118d
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.spellr.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
argv
|
2
|
+
backports
|
3
|
+
baz
|
4
|
+
changelog
|
5
|
+
codebase
|
6
|
+
config
|
7
|
+
cov
|
8
|
+
cyclomatic
|
9
|
+
enoent
|
10
|
+
enumerables
|
11
|
+
errno
|
12
|
+
extensionless
|
13
|
+
fancyignore
|
14
|
+
gemfile
|
15
|
+
github
|
16
|
+
gitignore
|
17
|
+
gitkeep
|
18
|
+
hashbang
|
19
|
+
klass
|
20
|
+
nocov
|
21
|
+
noninfringement
|
22
|
+
params
|
23
|
+
pathspec
|
24
|
+
pwd
|
25
|
+
rdoc
|
26
|
+
regexp
|
27
|
+
rspec
|
28
|
+
rubo
|
29
|
+
rubocop
|
30
|
+
rubygems
|
31
|
+
rulesets
|
32
|
+
rvm
|
33
|
+
sherson
|
34
|
+
simplecov
|
35
|
+
stdin
|
36
|
+
sudo
|
37
|
+
tmp
|
38
|
+
toplevel
|
39
|
+
txt
|
40
|
+
unrecursive
|
41
|
+
zsh
|
@@ -0,0 +1 @@
|
|
1
|
+
rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# v0.8.2
|
2
|
+
- fix `include_rules` not matching filenames with no extension when using `include_shebangs:`
|
3
|
+
|
1
4
|
# v0.8.1
|
2
|
-
- `
|
5
|
+
- `include_shebangs:` can be given non array value
|
3
6
|
|
4
7
|
# v0.8.0
|
5
8
|
- drop support for ruby 2.3. My plan is to only support supported ruby versions
|
@@ -7,7 +10,7 @@
|
|
7
10
|
- deprecate using `gitignore: '/path/to/gitignore'`. please use `gitignore: false, ignore_files: '/path/to/gitignore'` instead.
|
8
11
|
|
9
12
|
# v0.7.0
|
10
|
-
- add `
|
13
|
+
- add `include_shebangs:` which filters by shebangs
|
11
14
|
|
12
15
|
# v0.6.0
|
13
16
|
- nicer argv handling
|
data/README.md
CHANGED
@@ -77,6 +77,7 @@ FastIgnore.new(gitignore: true).to_a
|
|
77
77
|
To filter by extensionless files shebang/hashbang/etc:
|
78
78
|
```ruby
|
79
79
|
FastIgnore.new(include_rules: '*.rb', include_shebangs: 'ruby').to_a
|
80
|
+
FastIgnore.new(include_rules: '*.sh', include_shebangs: ['sh', 'bash', 'zsh']).to_a
|
80
81
|
```
|
81
82
|
|
82
83
|
To check if a single file is allowed, use
|
data/Rakefile
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
require 'rubocop/rake_task'
|
6
|
+
require 'spellr/rake_task'
|
6
7
|
|
7
8
|
RuboCop::RakeTask.new
|
8
9
|
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
Spellr::RakeTask.generate_task
|
9
11
|
|
10
|
-
task default: [:spec, :rubocop]
|
12
|
+
task default: [:spec, :rubocop, :spellr]
|
data/fast_ignore.gemspec
CHANGED
@@ -36,4 +36,5 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency 'rubocop', '>= 0.74.0'
|
37
37
|
spec.add_development_dependency 'rubocop-rspec', '~> 1'
|
38
38
|
spec.add_development_dependency 'simplecov', '~> 0.18.5'
|
39
|
+
spec.add_development_dependency 'spellr', '>= 0.8.1'
|
39
40
|
end
|
data/lib/fast_ignore.rb
CHANGED
@@ -42,10 +42,11 @@ class FastIgnore
|
|
42
42
|
gitignore: gitignore,
|
43
43
|
include_rules: include_rules,
|
44
44
|
include_files: include_files,
|
45
|
-
argv_rules: argv_rules
|
46
|
-
and_no_ext: @shebang_pattern
|
45
|
+
argv_rules: argv_rules
|
47
46
|
)
|
48
47
|
|
48
|
+
@include_rule_sets, @ignore_rule_sets = @rule_sets.partition(&:allow?)
|
49
|
+
@has_include_rule_sets = !@include_rule_sets.empty?
|
49
50
|
@relative = relative
|
50
51
|
end
|
51
52
|
|
@@ -59,13 +60,15 @@ class FastIgnore
|
|
59
60
|
|
60
61
|
def allowed?(path)
|
61
62
|
path = ::File.expand_path(path)
|
62
|
-
|
63
|
-
dir = stat.directory?
|
64
|
-
return false if dir
|
63
|
+
dir = ::File.stat(path).directory? # equivalent to directory? and exist?
|
65
64
|
|
66
|
-
|
65
|
+
return false if dir
|
66
|
+
return false unless @ignore_rule_sets.all? { |r| r.allowed_recursive?(path, dir) }
|
67
|
+
return @include_rule_sets.all? { |r| r.allowed_recursive?(path, dir) } unless @shebang_pattern
|
67
68
|
|
68
|
-
@
|
69
|
+
(@has_include_rule_sets &&
|
70
|
+
@include_rule_sets.all? { |r| r.allowed_unrecursive?(path, false) }) ||
|
71
|
+
match_shebang?(path, ::File.basename(path))
|
69
72
|
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
|
70
73
|
false
|
71
74
|
end
|
@@ -76,21 +79,27 @@ class FastIgnore
|
|
76
79
|
@relative ? path.delete_prefix(@root_trailing_slash) : path
|
77
80
|
end
|
78
81
|
|
79
|
-
def each_allowed(path = @root_trailing_slash, &block) # rubocop:disable Metrics/MethodLength
|
82
|
+
def each_allowed(path = @root_trailing_slash, &block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
80
83
|
Dir.each_child(path) do |basename|
|
81
84
|
begin
|
82
85
|
child = path + basename
|
83
|
-
|
84
|
-
|
85
|
-
dir = stat.directory?
|
86
|
+
dir = ::File.stat(child).directory? # equivalent to directory? and exist?
|
86
87
|
|
87
88
|
if dir
|
88
|
-
next unless @rule_sets.all? { |r| r.allowed_unrecursive?(child, dir
|
89
|
+
next unless @shebang_pattern || @rule_sets.all? { |r| r.allowed_unrecursive?(child, dir) }
|
89
90
|
|
90
91
|
each_allowed("#{child}/", &block)
|
91
92
|
else
|
92
|
-
unless @
|
93
|
-
|
93
|
+
next unless @ignore_rule_sets.all? { |r| r.allowed_unrecursive?(child, dir) }
|
94
|
+
|
95
|
+
if @shebang_pattern
|
96
|
+
unless (@has_include_rule_sets &&
|
97
|
+
@include_rule_sets.all? { |r| r.allowed_unrecursive?(child, dir) }) ||
|
98
|
+
match_shebang?(child, basename)
|
99
|
+
next
|
100
|
+
end
|
101
|
+
else
|
102
|
+
next unless @include_rule_sets.all? { |r| r.allowed_unrecursive?(child, dir) }
|
94
103
|
end
|
95
104
|
|
96
105
|
yield prepare_path(child)
|
@@ -102,8 +111,7 @@ class FastIgnore
|
|
102
111
|
end
|
103
112
|
|
104
113
|
def match_shebang?(path, basename)
|
105
|
-
return
|
106
|
-
return true if basename.include?('.')
|
114
|
+
return false if basename.include?('.')
|
107
115
|
|
108
116
|
begin
|
109
117
|
f = ::File.new(path)
|
@@ -111,7 +119,7 @@ class FastIgnore
|
|
111
119
|
fragment = f.sysread(256)
|
112
120
|
f.close
|
113
121
|
rescue SystemCallError, EOFError
|
114
|
-
return
|
122
|
+
return false
|
115
123
|
end
|
116
124
|
|
117
125
|
@shebang_pattern.match?(fragment)
|
@@ -120,6 +128,9 @@ class FastIgnore
|
|
120
128
|
def prepare_shebang_pattern(rules)
|
121
129
|
return if !rules || (rules = Array(rules)).empty?
|
122
130
|
|
123
|
-
|
131
|
+
rules = rules.flat_map { |s| s.to_s.split("\n") }
|
132
|
+
rules_re = rules.map { |s| Regexp.escape(s.to_s) }.join('|')
|
133
|
+
|
134
|
+
/\A#!.*\b(?:#{rules_re})\b/.freeze
|
124
135
|
end
|
125
136
|
end
|
data/lib/fast_ignore/rule_set.rb
CHANGED
@@ -6,31 +6,25 @@ class FastIgnore
|
|
6
6
|
attr_reader :allow
|
7
7
|
alias_method :allow?, :allow
|
8
8
|
|
9
|
-
def initialize(project_root: Dir.pwd, allow: false
|
9
|
+
def initialize(project_root: Dir.pwd, allow: false)
|
10
10
|
@dir_rules = []
|
11
11
|
@file_rules = []
|
12
12
|
@project_root = project_root
|
13
|
-
@and_no_ext = and_no_ext
|
14
13
|
|
15
14
|
@any_not_anchored = false
|
16
15
|
@allow = allow
|
17
16
|
@default = true unless allow
|
18
17
|
end
|
19
18
|
|
20
|
-
def allowed_recursive?(path, dir
|
19
|
+
def allowed_recursive?(path, dir)
|
21
20
|
@allowed_recursive ||= { @project_root => true }
|
22
21
|
@allowed_recursive.fetch(path) do
|
23
22
|
@allowed_recursive[path] =
|
24
|
-
allowed_recursive?(::File.dirname(path), true
|
23
|
+
allowed_recursive?(::File.dirname(path), true) && allowed_unrecursive?(path, dir)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
def allowed_unrecursive?(path, dir
|
29
|
-
if @and_no_ext
|
30
|
-
return true if dir
|
31
|
-
return true unless basename&.include?('.')
|
32
|
-
end
|
33
|
-
|
27
|
+
def allowed_unrecursive?(path, dir)
|
34
28
|
(dir ? @dir_rules : @file_rules).reverse_each do |rule|
|
35
29
|
# 14 = Rule::FNMATCH_OPTIONS
|
36
30
|
return rule.negation? if ::File.fnmatch?(rule.rule, path, 14)
|
@@ -9,32 +9,28 @@ class FastIgnore
|
|
9
9
|
gitignore: :auto,
|
10
10
|
include_rules: nil,
|
11
11
|
include_files: nil,
|
12
|
-
argv_rules: nil
|
13
|
-
and_no_ext: false
|
12
|
+
argv_rules: nil
|
14
13
|
)
|
15
14
|
rule_sets = [
|
16
15
|
from_array(ignore_rules, root: root),
|
17
16
|
*from_files(ignore_files, project_root: root),
|
18
17
|
from_array('.git', root: root),
|
19
18
|
from_gitignore_arg(gitignore, root: root),
|
20
|
-
from_array(include_rules, root: root, allow: true
|
21
|
-
*from_files(include_files, allow: true, project_root: root
|
22
|
-
from_array(argv_rules, root: root, allow: true, expand_path: true
|
19
|
+
from_array(include_rules, root: root, allow: true),
|
20
|
+
*from_files(include_files, allow: true, project_root: root),
|
21
|
+
from_array(argv_rules, root: root, allow: true, expand_path: true)
|
23
22
|
]
|
24
23
|
|
25
24
|
rule_sets.compact!
|
26
25
|
rule_sets.reject!(&:empty?)
|
27
|
-
if and_no_ext && rule_sets.none?(&:allow?)
|
28
|
-
rule_sets << ::FastIgnore::RuleSet.new(project_root: root, allow: true, and_no_ext: and_no_ext)
|
29
|
-
end
|
30
26
|
rule_sets.sort_by!(&:length)
|
31
27
|
rule_sets
|
32
28
|
end
|
33
29
|
|
34
|
-
def self.from_file(filename, allow: false, project_root: Dir.pwd
|
30
|
+
def self.from_file(filename, allow: false, project_root: Dir.pwd)
|
35
31
|
filename = ::File.expand_path(filename)
|
36
32
|
root = ::File.dirname(filename)
|
37
|
-
rule_set = ::FastIgnore::RuleSet.new(project_root: project_root, allow: allow
|
33
|
+
rule_set = ::FastIgnore::RuleSet.new(project_root: project_root, allow: allow)
|
38
34
|
|
39
35
|
::IO.foreach(filename) do |rule_string|
|
40
36
|
parse_rules(rule_string, allow: allow, rule_set: rule_set, root: root)
|
@@ -43,9 +39,9 @@ class FastIgnore
|
|
43
39
|
rule_set
|
44
40
|
end
|
45
41
|
|
46
|
-
def self.from_files(files, allow: false, project_root: Dir.pwd
|
42
|
+
def self.from_files(files, allow: false, project_root: Dir.pwd)
|
47
43
|
Array(files).map do |file|
|
48
|
-
from_file(file, allow: allow, project_root: project_root
|
44
|
+
from_file(file, allow: allow, project_root: project_root)
|
49
45
|
end
|
50
46
|
end
|
51
47
|
|
@@ -65,11 +61,11 @@ class FastIgnore
|
|
65
61
|
end
|
66
62
|
end
|
67
63
|
|
68
|
-
def self.from_array(rules, allow: false, expand_path: false, root: Dir.pwd
|
64
|
+
def self.from_array(rules, allow: false, expand_path: false, root: Dir.pwd)
|
69
65
|
rules = Array(rules)
|
70
66
|
return if rules.empty?
|
71
67
|
|
72
|
-
rule_set = ::FastIgnore::RuleSet.new(project_root: root, allow: allow
|
68
|
+
rule_set = ::FastIgnore::RuleSet.new(project_root: root, allow: allow)
|
73
69
|
|
74
70
|
rules.each do |rule_string|
|
75
71
|
rule_string.to_s.each_line do |rule_line|
|
data/lib/fast_ignore/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_ignore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Sherson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.18.5
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: spellr
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.8.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.8.1
|
111
125
|
description:
|
112
126
|
email:
|
113
127
|
- robot@dana.sh
|
@@ -119,6 +133,10 @@ files:
|
|
119
133
|
- ".rspec"
|
120
134
|
- ".rubocop.yml"
|
121
135
|
- ".simplecov"
|
136
|
+
- ".spellr.yml"
|
137
|
+
- ".spellr_wordlists/english.txt"
|
138
|
+
- ".spellr_wordlists/ruby.txt"
|
139
|
+
- ".spellr_wordlists/shell.txt"
|
122
140
|
- ".travis.yml"
|
123
141
|
- CHANGELOG.md
|
124
142
|
- Gemfile
|