fast_ignore 0.17.1 → 0.17.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88853f2613fe610772a13666845d500a4b377bbf5606e3fba3bd8842d66c17a2
4
- data.tar.gz: c158117c0234816a067b3e68d7686e247bf18ea81e39b3c339fcf06ecc4026ae
3
+ metadata.gz: 56582bce9b3eae6e761585c77846530bb96b287c2d6938dd7213c31b84567560
4
+ data.tar.gz: c2aabc49876831524acc8f14bc483aa8ec44ec715941a562bf4a6d5c4ac76b5c
5
5
  SHA512:
6
- metadata.gz: a409a69b31021dedca95858ebed16abb4a36efbb758067dcab41bd6cbeb988acf0a62d4324f31cbb68ba4787efca4564cfc51721a50dc710f3357923775cc6e2
7
- data.tar.gz: 4f0e0a8f900d6c0d008850eb8899c1c4446914149697539b9f708620054b614b310305e83df8743a3d5fb558a82ac08f0d48e44450486ad5de966943916a6ac2
6
+ metadata.gz: bc5e6b69f903bf2bb0beed6001bfa01bfa2f8b7e452eca9270884a38a1924649e336866d94085bd59ff72549d495d3857035227a7b3b0cf22859fd939c1e32ac
7
+ data.tar.gz: e286d5802e0a0857552b9c9dbe03999546817478f2960fdbd057709485a862e876e3e9328a12fafc34388ba1aad0893f10ea318e7bdff728fb3ef41facc1568a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.17.2
2
+ - Remove unnecessary backport code that was leftover when support for 2.4 was dropped
3
+ - Tiny performance improvements from rubocop-performance's suggestions
4
+
1
5
  # v0.17.1
2
6
  - fix handling of backward character classes `[z-a]`
3
7
  previously this raised a RegexpError, but git just considered it to be identical to `[z]`, now we match the git behaviour (but why would you ever do this?, i only found it because of the fuzz spec in the `leftovers` gem)
@@ -2,10 +2,6 @@
2
2
 
3
3
  class FastIgnore
4
4
  class FileRoot
5
- # :nocov:
6
- using ::FastIgnore::Backports::DeletePrefixSuffix if defined?(::FastIgnore::Backports::DeletePrefixSuffix)
7
- # :nocov:
8
-
9
5
  def self.build(file_path, project_root)
10
6
  file_root = "#{::File.dirname(file_path)}/".delete_prefix(project_root)
11
7
 
@@ -100,9 +100,8 @@ class FastIgnore
100
100
 
101
101
  def on_branch?(branch_pattern)
102
102
  branch_pattern += '**' if branch_pattern.end_with?('/')
103
- current_branch = ::File.readable?("#{root}/.git/HEAD") && ::File.read("#{root}/.git/HEAD").sub!(
104
- %r{\Aref: refs/heads/}, ''
105
- )
103
+ current_branch = ::File.readable?("#{root}/.git/HEAD") &&
104
+ ::File.read("#{root}/.git/HEAD").delete_prefix('ref: refs/heads/')
106
105
  return unless current_branch
107
106
 
108
107
  # goddamit git what does 'a pattern with standard globbing wildcards' mean
@@ -2,10 +2,6 @@
2
2
 
3
3
  class FastIgnore
4
4
  class GitignoreIncludeRuleBuilder < GitignoreRuleBuilder
5
- # :nocov:
6
- using ::FastIgnore::Backports::DeletePrefixSuffix if defined?(::FastIgnore::Backports::DeletePrefixSuffix)
7
- # :nocov:
8
-
9
5
  def initialize(rule, file_path, expand_path_from = nil)
10
6
  super(rule, file_path)
11
7
 
@@ -15,7 +11,7 @@ class FastIgnore
15
11
  end
16
12
 
17
13
  def expand_rule_path
18
- anchored! unless @s.match?(/\*/)
14
+ anchored! unless @s.match?(/\*/) # rubocop:disable Performance/StringInclude # it's StringScanner#match?
19
15
  return unless @s.match?(%r{(?:[~/]|\.{1,2}/|.*/\.\./)})
20
16
 
21
17
  dir_only! if @s.match?(%r{.*/\s*\z})
@@ -3,10 +3,6 @@
3
3
  class FastIgnore
4
4
  module RuleBuilder
5
5
  class << self
6
- # :nocov:
7
- using ::FastIgnore::Backports::DeletePrefixSuffix if defined?(::FastIgnore::Backports::DeletePrefixSuffix)
8
- # :nocov:
9
-
10
6
  def build(rule, allow, expand_path_with, file_root)
11
7
  if rule.delete_prefix!('#!:')
12
8
  shebang_rules(rule, allow, file_root)
@@ -23,7 +19,7 @@ class FastIgnore
23
19
  rule = ::FastIgnore::ShebangRule.new(pattern, allow, file_root&.shebang_path_pattern)
24
20
  return rule unless allow
25
21
 
26
- rules = gitignore_rules('*/'.dup, allow, file_root)
22
+ rules = gitignore_rules(+'*/', allow, file_root)
27
23
  rules.pop # don't want the include all children one.
28
24
  rules << rule
29
25
  rules
@@ -2,10 +2,6 @@
2
2
 
3
3
  class FastIgnore
4
4
  class RuleSets
5
- # :nocov:
6
- using ::FastIgnore::Backports::DeletePrefixSuffix if defined?(::FastIgnore::Backports::DeletePrefixSuffix)
7
- # :nocov:
8
-
9
5
  def initialize( # rubocop:disable Metrics/ParameterLists
10
6
  root:,
11
7
  ignore_rules: nil,
@@ -63,7 +63,7 @@ class FastIgnore
63
63
  file = ::File.new(path)
64
64
  first_line = file.sysread(64)
65
65
  if first_line.start_with?('#!')
66
- first_line += file.readline unless first_line.match?(/\n/)
66
+ first_line += file.readline unless first_line.include?("\n")
67
67
  else
68
68
  file.close
69
69
  return
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FastIgnore
4
- VERSION = '0.17.1'
4
+ VERSION = '0.17.2'
5
5
  end
data/lib/fast_ignore.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './fast_ignore/backports'
4
-
5
3
  require 'set'
6
4
  require 'strscan'
7
5
 
@@ -24,11 +22,6 @@ class FastIgnore
24
22
 
25
23
  include ::Enumerable
26
24
 
27
- # :nocov:
28
- using ::FastIgnore::Backports::DeletePrefixSuffix if defined?(::FastIgnore::Backports::DeletePrefixSuffix)
29
- using ::FastIgnore::Backports::DirEachChild if defined?(::FastIgnore::Backports::DirEachChild)
30
- # :nocov:
31
-
32
25
  def initialize(relative: false, root: nil, gitignore: :auto, follow_symlinks: false, **rule_set_builder_args)
33
26
  @relative = relative
34
27
  @follow_symlinks_method = ::File.method(follow_symlinks ? :stat : :lstat)
@@ -41,7 +34,7 @@ class FastIgnore
41
34
  end
42
35
 
43
36
  def each(&block)
44
- return enum_for(:each) unless block_given?
37
+ return enum_for(:each) unless block
45
38
 
46
39
  dir_pwd = ::Dir.pwd
47
40
  root_from_pwd = @root.start_with?(dir_pwd) ? ".#{@root.delete_prefix(dir_pwd)}" : @root
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_ignore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.17.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dana Sherson
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - "<"
101
101
  - !ruby/object:Gem::Version
102
102
  version: '1.12'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop-performance
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: rubocop-rake
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -181,7 +195,6 @@ files:
181
195
  - LICENSE.txt
182
196
  - README.md
183
197
  - lib/fast_ignore.rb
184
- - lib/fast_ignore/backports.rb
185
198
  - lib/fast_ignore/file_root.rb
186
199
  - lib/fast_ignore/gitconfig_parser.rb
187
200
  - lib/fast_ignore/gitignore_include_rule_builder.rb
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class FastIgnore
4
- module Backports
5
- ruby_major, ruby_minor = ::RUBY_VERSION.split('.', 2)
6
- unless ruby_major.to_i > 2 || ruby_major.to_i == 2 && ruby_minor.to_i > 5
7
- module DirEachChild
8
- refine ::Dir.singleton_class do
9
- def children(path)
10
- ::Dir.entries(path) - ['.', '..']
11
- end
12
- end
13
- end
14
-
15
- module DeletePrefixSuffix
16
- refine ::String do
17
- # delete_prefix!(prefix) -> self or nil
18
- # Deletes leading prefix from str, returning nil if no change was made.
19
- #
20
- # "hello".delete_prefix!("hel") #=> "lo"
21
- # "hello".delete_prefix!("llo") #=> nil
22
- def delete_prefix!(str)
23
- return unless start_with?(str)
24
-
25
- slice!(0..(str.length - 1))
26
- self
27
- end
28
-
29
- # delete_suffix!(suffix) -> self or nil
30
- # Deletes trailing suffix from str, returning nil if no change was made.
31
- #
32
- # "hello".delete_suffix!("llo") #=> "he"
33
- # "hello".delete_suffix!("hel") #=> nil
34
- def delete_suffix!(str)
35
- return unless end_with?(str)
36
-
37
- slice!(-str.length..-1)
38
- self
39
- end
40
-
41
- # delete_prefix(prefix) -> new_str click to toggle source
42
- # Returns a copy of str with leading prefix deleted.
43
- #
44
- # "hello".delete_prefix("hel") #=> "lo"
45
- # "hello".delete_prefix("llo") #=> "hello"
46
- def delete_prefix(str)
47
- s = dup
48
- s.delete_prefix!(str)
49
- s
50
- end
51
-
52
- # delete_suffix(suffix) -> new_str
53
- # Returns a copy of str with trailing suffix deleted.
54
- #
55
- # "hello".delete_suffix("llo") #=> "he"
56
- # "hello".delete_suffix("hel") #=> "hello"
57
- def delete_suffix(str) # leftovers:allowed
58
- s = dup
59
- s.delete_suffix!(str)
60
- s
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end