Skip to content

Commit

Permalink
Resolve RuboCop offenses (#534)
Browse files Browse the repository at this point in the history
* Simple RuboCop fixes

* Add `max_line_length` into EditorConfig

Duplicate value from RuboCop config.

* Remove RuboCop config file from `.gitignore`

* Breaking changes with optional arguments

There were RuboCop offenses, and I think keyword approaches is better.

* Add Changelog entries

* Fix error with `Image.file`

* Resolve RuboCop offense about global variable

I don't know a way better, the whole approach is not the best.

* Replace manual `autoload` list with dynamic one

* Resolve RuboCop offense about block length in `scripts/reference`

* Add `.rubocop_todo` file

Resolve these issues later.

* Add `rubocop-performance` and `rubocop-rake` gems

Resolve new offenses.

* Add `inherit_mode` for RuboCop config

* Resolve Ruby warning about `-` char in Regex

* Add RuboCop GitHub Action

* Add `bundle exec` for GitHub Actions

* Rename `autoload_abbreviations` into `autoload_acronyms`

* Resolve a new RuboCop offense

* Add file exclusions for `Style/AsciiComments` RuboCop cop

Also turn them into mask by locale.

* Revert breaking changes, return positional arguments

Leave keyword arguments, add deprecation warning for positional.

---------

Co-authored-by: marocchino <marocchino@users.noreply.github.com>
  • Loading branch information
AlexWayfer and marocchino committed Sep 13, 2023
1 parent 9b93e54 commit 14eed86
Show file tree
Hide file tree
Showing 62 changed files with 478 additions and 353 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120
17 changes: 17 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: RuboCop
on:
pull_request:
push:
branches:
- "main"
jobs:
test:
runs-on: ubuntu-latest
name: RuboCop lint
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 'ruby'
bundler-cache: true # 'bundle install' and cache
- run: bundle exec rake rubocop
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # 'bundle install' and cache
- run: rake test
- run: bundle exec rake test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ Gemfile.lock
.ruby-gemset
.ruby-version
.rvmrc
.rubocop.yml
28 changes: 25 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
require:
- rubocop-performance
- rubocop-rake

inherit_mode:
merge:
- Include
- Exclude

inherit_from:
- ./.rubocop_todo.yml

AllCops:
TargetRubyVersion: 3.0
NewCops: enable
Expand All @@ -24,13 +36,23 @@ Style/Documentation:
Style/AsciiComments:
Enabled: true
Exclude:
- 'lib/ffaker/address_ja.rb'
- 'lib/ffaker/address_se.rb'
- '**/*_cs.rb'
- '**/*_ja.rb'
- '**/*_mx.rb'
- '**/*_se.rb'
Style/OptionalBooleanParameter:
Enabled: false
Metrics/ModuleLength:
Enabled: true
Max: 200
Metrics/ClassLength:
Exclude:
- 'lib/ffaker/bank.rb'
- 'test/**/*.rb'
Metrics/MethodLength:
AllowedPatterns:
- 'test_'
Metrics/AbcSize:
AllowedPatterns:
- 'test_'
Style/RedundantArgument:
Enabled: false
6 changes: 6 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Metrics/MethodLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## development

- Add your change HERE
- Resolve a lot of RuboCop offenses [@AlexWayfer]
- Change `Image.url`, `Image.file`, `Book.cover` and `Avatar.image` arguments to keywords [@AlexWayfer]
- Adds FFaker::Date.birthday [@professor]
- Adds FFaker::Crypto.sha256 [@professor]
- Update README [@professor]
Expand Down
15 changes: 15 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

group :development do
gem 'rake', '~> 13.0'
end

group :development, :lint do
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rake'
end

group :development, :test do
gem 'test-unit'
end
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
* [FFaker::IdentificationESCO](#ffakeridentificationesco)
* [FFaker::IdentificationIN](#ffakeridentificationin)
* [FFaker::IdentificationIT](#ffakeridentificationit)
* [FFaker::IdentificationKr](#ffakeridentificationkr)
* [FFaker::IdentificationKR](#ffakeridentificationkr)
* [FFaker::IdentificationMX](#ffakeridentificationmx)
* [FFaker::IdentificationPL](#ffakeridentificationpl)
* [FFaker::IdentificationTW](#ffakeridentificationtw)
Expand Down Expand Up @@ -1385,7 +1385,7 @@
| `gender` | ‼️ FFaker::UniqueUtils::RetryLimitExceeded: Retry limit exceeded for gender |
| `ssn` | 11830877014613103430, 45436375172610549922, 29278264986997805738 |

## FFaker::IdentificationKr
## FFaker::IdentificationKR

| Method | Example |
| ------ | ------- |
Expand Down
14 changes: 7 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ module Test
end
end

require 'rubocop/rake_task'

RuboCop::RakeTask.new

#############################################################################
#
# Helper functions
Expand Down Expand Up @@ -80,14 +84,9 @@ rescue LoadError
end
end

#############################################################################
#
# Packaging tasks
#
#############################################################################

desc 'Packaging tasks'
task release: :build do
unless `git branch` =~ /^\* main$/
unless `git branch`.match?(/^\* main$/)
puts 'You must be on the main branch to release!'
exit!
end
Expand All @@ -103,6 +102,7 @@ task build: %i[validate reference] do
sh "gem build #{gemspec_file} --output=pkg/#{gem_file}"
end

desc 'Validate library files'
task :validate do
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
unless libfiles.empty?
Expand Down
8 changes: 2 additions & 6 deletions ffaker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ Gem::Specification.new do |s|
s.files = `git ls-files`
.split("\n")
.sort
.reject { |file| file =~ /^\./ }
.reject { |file| file =~ /^(rdoc|pkg)/ }
.grep_v(/^\./)
.grep_v(/^(rdoc|pkg)/)

s.metadata = {
'changelog_uri' => 'https://github.com/ffaker/ffaker/blob/main/Changelog.md',
'documentation_uri' => 'https://github.com/ffaker/ffaker/blob/main/REFERENCE.md',
'rubygems_mfa_required' => 'true'
}

s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'test-unit'
end
Loading

0 comments on commit 14eed86

Please sign in to comment.