diff --git a/.rubocop.yml b/.rubocop.yml index 8e36590e..c64ccfd4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -21,8 +21,6 @@ Naming: Layout: Enabled: true - Include: - - 'lib/**/*' Migration: Enabled: true @@ -50,8 +48,9 @@ Gemspec: Performance: Enabled: true - Include: - - 'lib/**/*' + Exclude: + - 'test/**/*.rb' + - '**/*.md' Security/MarshalLoad: Exclude: @@ -786,6 +785,9 @@ Layout/SpaceAroundMethodCallOperator: Layout/LineLength: Enabled: false +Layout/HeredocIndentation: + Enabled: false + Layout/SpaceAroundOperators: Enabled: true EnforcedStyleForExponentOperator: 'space' diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 842e0e3d..8fc1eb6d 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -7,7 +7,7 @@ "soutaro.steep-vscode", "soutaro.rbs-syntax", "dprint.dprint", - "rebornix.ruby", + "pucelle.run-on-save", "jnoortheen.nix-ide" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index c6a9c1f1..2e99e04a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,14 +1,16 @@ { "editor.defaultFormatter": "dprint.dprint", "editor.formatOnSave": true, - "ruby.useBundler": true, - "ruby.useLanguageServer": true, - "ruby.lint": { - "rubocop": { - "useBundler": true + "runOnSave.statusMessageTimeout": 3000, + "runOnSave.commands": [ + { + "match": "(.*\\.rb|Rakefile|Gemfile|.*\\.gemspec)$", + "command": "bundle exec rubocop --autocorrect ${file}", + "runIn": "backend", + "runningStatusMessage": "Formatting with rubocop ${fileBasename}", + "finishStatusMessage": "${fileBasename} formatted" } - }, - "ruby.format": "rubocop", + ], "cSpell.words": [ "kwargs", "Undocumentable", diff --git a/Rakefile b/Rakefile index 66edd002..68989d5e 100644 --- a/Rakefile +++ b/Rakefile @@ -90,7 +90,7 @@ end # This can't be used `bundle exec rake`. Use `rake` instead desc(%q{Compare generating String performance with other gems}) task(:benchmark_with_other_gems) do - [{kachick: 'ruby-ulid(This one)'}, { rafaelsales: 'ulid'}, {abachman: 'ulid-ruby'}].each do |gem_name_by_author| + [{ kachick: 'ruby-ulid(This one)' }, { rafaelsales: 'ulid' }, { abachman: 'ulid-ruby' }].each do |gem_name_by_author| gem_name_by_author.each_pair do |author, gem_name| puts('-' * 72) puts("#### #{author} - #{gem_name}") diff --git a/ruby-ulid.gemspec b/ruby-ulid.gemspec index 2996dfcb..c7a39a87 100644 --- a/ruby-ulid.gemspec +++ b/ruby-ulid.gemspec @@ -18,9 +18,9 @@ Gem::Specification.new do |gem| gem.metadata = { 'documentation_uri' => 'https://kachick.github.io/ruby-ulid/', - 'homepage_uri' => repository_url, - 'source_code_uri' => repository_url, - 'bug_tracker_uri' => "#{repository_url}/issues", + 'homepage_uri' => repository_url, + 'source_code_uri' => repository_url, + 'bug_tracker_uri' => "#{repository_url}/issues", 'rubygems_mfa_required' => 'true' } @@ -32,7 +32,7 @@ Gem::Specification.new do |gem| gem.email = ['kachick1+ruby@gmail.com'] git_managed_files = `git ls-files`.lines.map(&:chomp) might_be_parsing_by_tool_as_dependabot = git_managed_files.empty? - base_files = Dir['README*', '*LICENSE*', 'lib/**/*', 'sig/**/*'].uniq + base_files = Dir['README*', '*LICENSE*', 'lib/**/*', 'sig/**/*'].uniq files = might_be_parsing_by_tool_as_dependabot ? base_files : (base_files & git_managed_files) unless might_be_parsing_by_tool_as_dependabot diff --git a/scripts/generate_many_examples.rb b/scripts/generate_many_examples.rb index 10fe1a5e..d8460979 100644 --- a/scripts/generate_many_examples.rb +++ b/scripts/generate_many_examples.rb @@ -61,7 +61,6 @@ filename = "dumped_fixed_examples_#{Time.now.strftime('%Y-%m-%d_%H-%M')}.bin" output_path = "#{File.expand_path('.')}/test/many_data/fixtures/#{filename}" - File.open(output_path, 'w+b') do |file| Marshal.dump(examples, file) end diff --git a/test/concurrency/test_ulid_monotonic_generator_thread_safety.rb b/test/concurrency/test_ulid_monotonic_generator_thread_safety.rb index 506a08a8..e40446ee 100644 --- a/test/concurrency/test_ulid_monotonic_generator_thread_safety.rb +++ b/test/concurrency/test_ulid_monotonic_generator_thread_safety.rb @@ -102,7 +102,7 @@ def test_thread_safe_generate_with_randomized_time assert(basically_random_but_contain_same_1000_times.none?(initial_and_median.to_time)) # Might be flaky... - later_than_initial_and_median_count = basically_random_but_contain_same_1000_times.count{ |time| time > initial_and_median.to_time } + later_than_initial_and_median_count = basically_random_but_contain_same_1000_times.count { |time| time > initial_and_median.to_time } assert do 1500 < later_than_initial_and_median_count end diff --git a/test/core/test_library_loading.rb b/test/core/test_library_loading.rb index 58124a81..b36334e3 100644 --- a/test/core/test_library_loading.rb +++ b/test/core/test_library_loading.rb @@ -10,6 +10,7 @@ def test_naming_convention_for_bundler compilable_paths = Dir.glob('lib/**/*.rb') raise unless compilable_paths.size >= 5 + compilable_paths.each do |path| data(path, path) end diff --git a/test/core/test_ractor_shareable.rb b/test/core/test_ractor_shareable.rb index 7d1ac52b..e4ad9dbb 100644 --- a/test/core/test_ractor_shareable.rb +++ b/test/core/test_ractor_shareable.rb @@ -44,6 +44,7 @@ def test_instances_are_can_be_shareable const_name_to_value = ULID.constants.to_h { |const_name| [const_name, ULID.const_get(const_name)] } raise unless const_name_to_value.size >= 10 + const_name_to_value.each_pair do |name, value| data(name.to_s, value) end diff --git a/test/core/test_ulid_class.rb b/test/core/test_ulid_class.rb index ac71ff2f..1c7fb8d5 100644 --- a/test/core/test_ulid_class.rb +++ b/test/core/test_ulid_class.rb @@ -434,7 +434,7 @@ def test_range assert_equal(ULID.min..range.end, ULID.range(nil..range.end)) [nil, 42, 1..42, time_has_more_value_than_milliseconds1, ULID.sample.to_s, ULID.sample, - BasicObject.new, Object.new, range.begin.to_s..range.end.to_s].each do |evil| + BasicObject.new, Object.new, range.begin.to_s..range.end.to_s].each do |evil| err = assert_raises(ArgumentError) do ULID.range(evil) end @@ -581,7 +581,7 @@ def test_constant_regexp assert_true(subset_pattern.match?('00000000000000000000000000')) assert_true(subset_pattern.match?('7ZZZZZZZZZZZZZZZZZZZZZZZZZ')) assert_false(subset_pattern.match?('80000000000000000000000000')) - assert_equal({'timestamp' => '01ARZ3NDEK', 'randomness' => 'TSV4RRFFQ69G5FAV'}, subset_pattern.match('01ARZ3NDEKTSV4RRFFQ69G5FAV').named_captures) + assert_equal({ 'timestamp' => '01ARZ3NDEK', 'randomness' => 'TSV4RRFFQ69G5FAV' }, subset_pattern.match('01ARZ3NDEKTSV4RRFFQ69G5FAV').named_captures) assert_true(strict_pattern.casefold?) assert_equal(Encoding::US_ASCII, strict_pattern.encoding) @@ -594,7 +594,7 @@ def test_constant_regexp assert_true(strict_pattern.match?('00000000000000000000000000')) assert_true(strict_pattern.match?('7ZZZZZZZZZZZZZZZZZZZZZZZZZ')) assert_false(strict_pattern.match?('80000000000000000000000000')) - assert_equal({'timestamp' => '01ARZ3NDEK', 'randomness' => 'TSV4RRFFQ69G5FAV'}, strict_pattern.match('01ARZ3NDEKTSV4RRFFQ69G5FAV').named_captures) + assert_equal({ 'timestamp' => '01ARZ3NDEK', 'randomness' => 'TSV4RRFFQ69G5FAV' }, strict_pattern.match('01ARZ3NDEKTSV4RRFFQ69G5FAV').named_captures) assert_true(scanning_pattern.casefold?) assert_equal(Encoding::US_ASCII, scanning_pattern.encoding) diff --git a/test/core/test_ulid_instance.rb b/test/core/test_ulid_instance.rb index 0e8b452f..2b49b0d5 100644 --- a/test/core/test_ulid_instance.rb +++ b/test/core/test_ulid_instance.rb @@ -40,7 +40,7 @@ class TestULIDInstance < Test::Unit::TestCase pred ].freeze - raise 'Incorrect fixture setup' unless (EXPOSED_METHODS & ULID_RETURNING_METHODS).sort == ULID_RETURNING_METHODS.sort + raise 'Incorrect fixture setup' unless (EXPOSED_METHODS & ULID_RETURNING_METHODS).sort == ULID_RETURNING_METHODS.sort def setup @actual_timezone = ENV.fetch('TZ', nil) diff --git a/test/helper.rb b/test/helper.rb index 9bce2962..f696fa0f 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -16,7 +16,7 @@ Warning[:deprecated] = true Warning[:experimental] = true -WARNING_PROCESS = -> _warning_message { +WARNING_PROCESS = ->_warning_message { :raise } @@ -35,8 +35,8 @@ module ULIDAssertions def assert_acceptable_randomized_string(ulids) awesome_randomized_ulids = ulids.select { |ulid| (0..3).cover?(ULID::TIMESTAMP_ENCODED_LENGTH - ulid.timestamp.squeeze.size) || - (0..3).cover?(ULID::RANDOMNESS_ENCODED_LENGTH - ulid.randomness.squeeze.size) || - '000' != ulid.randomness.slice(-3, 3) + (0..3).cover?(ULID::RANDOMNESS_ENCODED_LENGTH - ulid.randomness.squeeze.size) || + '000' != ulid.randomness.slice(-3, 3) } assert_in_epsilon(awesome_randomized_ulids.size, ulids.size, (5/100r).to_f) @@ -44,7 +44,7 @@ def assert_acceptable_randomized_string(ulids) end def assert_warning(pattern, &block) - raise(ArgumentError, 'should pass block as an warning sandbox') unless block_given? + raise(ArgumentError, 'should pass block as an warning sandbox') unless block_given? org_stderr = $stderr $stderr = fake_io = StringIO.new(+'', 'r+')