Skip to content

Commit

Permalink
Add frozen string literal + small update (#50)
Browse files Browse the repository at this point in the history
* Update fakefs and rubocop to latest version
Remove `spec` from files (spec are included when gem installed)
Remove `test_files` (not required anymore)

* Regenerate rubocop
Fix frozen_string_literal

* Update ruby/setup-ruby to v1
  • Loading branch information
ericproulx authored Apr 10, 2024
1 parent 7b67ad9 commit 23737d2
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gem-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Ruby 3.1
uses: ruby/setup-ruby@d4526a55538b775af234ba4af27118ed6f8f6677
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
Expand Down
19 changes: 3 additions & 16 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.1', '3.2', '3.3']

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@d4526a55538b775af234ba4af27118ed6f8f6677
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
Expand All @@ -37,23 +32,15 @@ jobs:
run: gem install ./pathspec*.gem

test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.1', '3.2', '3.3']
# TODO: Fix rubocop issues
# raketasks: ['rubocop', 'spec', 'docs']
raketasks: ['spec', 'docs']


raketasks: ['rubocop', 'spec', 'docs']
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@d4526a55538b775af234ba4af27118ed6f8f6677
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 3.1
NewCops: enable

Style/NumericPredicate:
Expand Down
100 changes: 41 additions & 59 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-01-11 16:42:16 -0800 using RuboCop version 0.52.1.
# on 2024-04-08 19:36:04 UTC using RuboCop version 1.63.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 7
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'pathspec.gemspec'

# Offense count: 2
# Cop supports --auto-correct.
# This cop supports safe autocorrection (--autocorrect).
Layout/BlockEndNewline:
Exclude:
- 'spec/unit/pathspec_spec.rb'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
# This cop supports safe autocorrection (--autocorrect).
Layout/HeredocIndentation:
Exclude:
- 'spec/unit/pathspec_spec.rb'

# Offense count: 8
# Cop supports --auto-correct.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Expand All @@ -30,102 +36,78 @@ Layout/SpaceInsideBlockBraces:
- 'lib/pathspec.rb'
- 'spec/unit/pathspec_spec.rb'

# Offense count: 2
Lint/ImplicitStringConcatenation:
Exclude:
- 'lib/pathspec/gitignorespec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/pathspec/spec.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AutoCorrect.
Lint/UselessAssignment:
Exclude:
- 'spec/unit/pathspec_spec.rb'

# Offense count: 2
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'lib/pathspec.rb'
- 'lib/pathspec/gitignorespec.rb'

# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Enabled: false
Max: 62
Max: 63

# Offense count: 7
# Configuration parameters: CountComments, ExcludedMethods.
# Offense count: 8
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Enabled: false
Max: 270
Max: 300

# Offense count: 2
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 4

# Offense count: 1
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 146
Max: 123

# Offense count: 2
# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 26
Max: 18

# Offense count: 3
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 77
Max: 69

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 32
Max: 31

# Offense count: 25
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
# AllowedMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'spec/unit/pathspec_spec.rb'

# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: when_needed, always, never
Style/FrozenStringLiteralComment:
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'lib/pathspec.rb'
- 'lib/pathspec/gitignorespec.rb'
- 'lib/pathspec/regexspec.rb'
- 'lib/pathspec/spec.rb'
- 'pathspec.gemspec'
- 'spec/spec_helper.rb'
- 'spec/unit/pathspec/gitignorespec_spec.rb'
- 'spec/unit/pathspec/spec_spec.rb'
- 'spec/unit/pathspec_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
# AllowedMethods: define_method
Style/SymbolProc:
Exclude:
- 'lib/pathspec.rb'

# Offense count: 7
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 108
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
Expand Down
2 changes: 2 additions & 0 deletions lib/pathspec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pathspec/gitignorespec'
require 'pathspec/regexspec'
require 'find'
Expand Down
6 changes: 4 additions & 2 deletions lib/pathspec/gitignorespec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pathspec/regexspec'

class PathSpec
Expand Down Expand Up @@ -87,7 +89,7 @@ def initialize(original_pattern) # rubocop:disable Metrics/CyclomaticComplexity
end

# Build regular expression from pattern.
regex = '^'
regex = +'^'
need_slash = false
regex_end = pattern_segs.size - 1
pattern_segs.each_index do |i|
Expand Down Expand Up @@ -165,7 +167,7 @@ def translate_segment_glob(pattern)
# the POSIX function `fnmatch()` with the `FNM_PATHNAME` flag set.

escape = false
regex = ''
regex = +''
i = 0

while i < pattern.size
Expand Down
2 changes: 2 additions & 0 deletions lib/pathspec/regexspec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pathspec/spec'

class PathSpec
Expand Down
2 changes: 2 additions & 0 deletions lib/pathspec/spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class PathSpec
# Abstract spec
class Spec
Expand Down
9 changes: 5 additions & 4 deletions pathspec.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand All @@ -8,21 +10,20 @@ Gem::Specification.new do |s|
s.description = 'Use to match path patterns such as gitignore'
s.authors = ['Brandon High']
s.email = '[email protected]'
s.files = Dir.glob('{lib,spec,docs}/**/*') + %w[LICENSE README.md CHANGELOG.md]
s.files = Dir.glob('{lib,docs}/**/*') + %w[LICENSE README.md CHANGELOG.md]
s.bindir = 'bin'
s.executables << 'pathspec-rb'
s.test_files = s.files.grep(%r{^spec/})
s.require_paths = ['lib']
s.metadata['allowed_push_host'] = 'https://rubygems.org'
s.metadata['rubygems_mfa_required'] = 'true'
s.homepage = 'https://github.com/highb/pathspec-ruby'
s.license = 'Apache-2.0'
s.required_ruby_version = '>= 3.1.0'
s.add_development_dependency 'bundler', '~> 2.2'
s.add_development_dependency 'fakefs', '~> 1.3'
s.add_development_dependency 'fakefs', '~> 2.5'
s.add_development_dependency 'kramdown', '~> 2.3'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rspec', '~> 3.10'
s.add_development_dependency 'rubocop', '~> 1.7'
s.add_development_dependency 'rubocop', '~> 1.63.0'
s.add_development_dependency 'simplecov', '~> 0.21'
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require 'simplecov'
SimpleCov.start
Expand Down
2 changes: 2 additions & 0 deletions spec/unit/pathspec/gitignorespec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'pathspec/gitignorespec'

Expand Down
2 changes: 2 additions & 0 deletions spec/unit/pathspec/spec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'pathspec/spec'

Expand Down
2 changes: 2 additions & 0 deletions spec/unit/pathspec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'fakefs/safe'
require 'pathspec'
Expand Down

0 comments on commit 23737d2

Please sign in to comment.