Skip to content

Commit 794dc7b

Browse files
RUBY-3665 - Enable Rubocop (#349)
Co-authored-by: Dmitry Rybakov <[email protected]>
1 parent 46d2ccd commit 794dc7b

File tree

8 files changed

+31
-18
lines changed

8 files changed

+31
-18
lines changed

.github/workflows/bson-ruby.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ name: CI
33
on: [push, pull_request]
44

55
jobs:
6+
rubocop:
7+
runs-on: ubuntu-latest
8+
env:
9+
CI: true
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Ruby 3.4
13+
uses: ruby/setup-ruby@v1
14+
with:
15+
ruby-version: 3.4
16+
bundler-cache: true
17+
- name: Run RuboCop
18+
run: bundle exec rubocop --parallel
19+
620
build:
721
name: >-
822
${{ matrix.os }} ${{ matrix.ruby }}
@@ -20,7 +34,7 @@ jobs:
2034
fail-fast: false
2135
matrix:
2236
os: [ ubuntu, macos, windows ]
23-
ruby: [ 2.7, 3.0, 3.1, 3.2, 3.3, head ]
37+
ruby: [ 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, head ]
2438
include:
2539
- { os: windows , ruby: mingw }
2640
exclude:

.rubocop.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
require:
1+
plugins:
22
- rubocop-performance
33
- rubocop-rake
44
- rubocop-rspec
55

66
AllCops:
7-
TargetRubyVersion: 2.5
7+
TargetRubyVersion: 2.6
88
NewCops: enable
99
Exclude:
1010
- 'spec/shared/**/*'
1111
- 'tmp/**/*'
12+
- 'vendor/**/*'
1213

1314
Bundler:
1415
Enabled: true

Gemfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ group :development, :test do
2424
# https://github.com/jruby/jruby/wiki/UsingTheJRubyDebugger
2525
gem 'ruby-debug', platforms: :jruby
2626

27-
# Ruby 2.5 wants an older version of rubocop. Rather than try to
28-
# please everybody, we'll just not install rubocop for Ruby 2.5.
29-
if RUBY_VERSION > "2.5.99"
30-
gem 'rubocop', '~> 1.45.1'
31-
gem 'rubocop-performance', '~> 1.16.0'
32-
gem 'rubocop-rake', '~> 0.6.0'
33-
gem 'rubocop-rspec', '~> 2.18.1'
27+
# JRuby 9.3 reports RUBY_VERSION as 2.6, and the latest versions of Rubocop
28+
# wants 2.7 or higher. It enough to use rubocop only on MRI, so we can skip
29+
# it on JRuby.
30+
unless RUBY_PLATFORM =~ /java/
31+
gem 'rubocop', '~> 1.75.5'
32+
gem 'rubocop-performance', '~> 1.25.0'
33+
gem 'rubocop-rake', '~> 0.7.1'
34+
gem 'rubocop-rspec', '~> 3.6.0'
3435
end
3536
end
3637

lib/bson/binary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
2-
2+
# rubocop:todo all
33
# Copyright (C) 2009-2020 MongoDB Inc.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");

lib/bson/object_id.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def repair(object)
360360
# NUM2UINT. Further, the spec dictates that the time component of an
361361
# ObjectID must be no more than 4 bytes long, so the spec itself is
362362
# constrained in this regard.
363-
MAX_INTEGER = 2 ** 32
363+
MAX_INTEGER = 2**32
364364

365365
# Returns an integer timestamp (seconds since the Epoch). Primarily used
366366
# by the generator to produce object ids.

lib/bson/regexp.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ def bson_options
9999
end
100100

101101
def bson_extended
102-
(options & ::Regexp::EXTENDED).zero? ? NO_VALUE : EXTENDED_VALUE
102+
options.nobits?(::Regexp::EXTENDED) ? NO_VALUE : EXTENDED_VALUE
103103
end
104104

105105
def bson_ignorecase
106-
(options & ::Regexp::IGNORECASE).zero? ? NO_VALUE : IGNORECASE_VALUE
106+
options.nobits?(::Regexp::IGNORECASE) ? NO_VALUE : IGNORECASE_VALUE
107107
end
108108

109109
def bson_dotall
110110
# Ruby Regexp's MULTILINE is equivalent to BSON's dotall value
111-
(options & ::Regexp::MULTILINE).zero? ? NO_VALUE : NEWLINE_VALUE
111+
options.nobits?(::Regexp::MULTILINE) ? NO_VALUE : NEWLINE_VALUE
112112
end
113113

114114
# Represents the raw values for the regular expression.

lib/bson/vector.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
module BSON
1818
# Vector of numbers along with metadata for binary interoperability.
1919
class Vector < ::Array
20-
2120
# @return [ Integer ] The data type stored in the vector.
2221
attr_reader :dtype
2322

spec/runners/binary_vector.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def invalid_tests
2626
end
2727

2828
class Test
29-
3029
attr_reader :canonical_bson, :description, :dtype, :padding, :vector
3130

3231
def initialize(spec, test)
@@ -49,7 +48,6 @@ def document_from_canonical_bson
4948
bson_bytes = decode_hex(@canonical_bson)
5049
buffer = BSON::ByteBuffer.new(bson_bytes)
5150
BSON::Document.from_bson(buffer)
52-
5351
end
5452

5553
def canonical_bson_from_document(use_vector_type: false, validate_vector_data: false)

0 commit comments

Comments
 (0)