Skip to content

Commit 21f132c

Browse files
authored
Merge pull request #3 from aktsk/rubocop
Add RuboCop for linting
2 parents 7144547 + c380ae2 commit 21f132c

8 files changed

Lines changed: 267 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
rubocop:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v6
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: "3.4"
15+
bundler-cache: true
16+
- name: Run RuboCop
17+
run: bundle exec rubocop

.rubocop.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
AllCops:
2+
DisplayCopNames: true
3+
NewCops: enable
4+
5+
plugins:
6+
7+
### Lint ###
8+
Lint/AmbiguousOperatorPrecedence:
9+
Enabled: false
10+
11+
Lint/MissingSuper:
12+
Enabled: false
13+
14+
### Style ###
15+
Style/AccessorGrouping:
16+
Enabled: true
17+
EnforcedStyle: separated
18+
19+
Style/BlockDelimiters:
20+
Enabled: true
21+
EnforcedStyle: semantic
22+
AllowBracesOnProceduralOneLiners: true
23+
24+
Style/ClassAndModuleChildren:
25+
Enabled: false
26+
27+
Style/Documentation:
28+
Enabled: false
29+
30+
Style/DocumentDynamicEvalDefinition:
31+
Enabled: false
32+
33+
Style/DoubleNegation:
34+
Enabled: false
35+
36+
Style/FormatString:
37+
Enabled: false
38+
39+
Style/GlobalVars:
40+
AllowedVariables: [$current_dataset]
41+
42+
Style/GuardClause:
43+
Enabled: false
44+
45+
Style/IfInsideElse:
46+
Enabled: false
47+
48+
Style/IfUnlessModifier:
49+
Enabled: false
50+
51+
Style/Lambda:
52+
Enabled: false
53+
54+
Style/MultilineBlockChain:
55+
Enabled: false
56+
57+
Style/StringLiterals:
58+
Enabled: false
59+
60+
Style/NumericLiterals:
61+
MinDigits: 9
62+
63+
Style/NumericPredicate:
64+
Enabled: false
65+
66+
Style/TrailingCommaInArguments:
67+
EnforcedStyleForMultiline: comma
68+
69+
Style/TrailingCommaInArrayLiteral:
70+
EnforcedStyleForMultiline: comma
71+
72+
Style/TrailingCommaInHashLiteral:
73+
EnforcedStyleForMultiline: comma
74+
75+
Style/OptionalBooleanParameter:
76+
Enabled: false
77+
78+
Style/SignalException:
79+
EnforcedStyle: semantic
80+
81+
Style/PercentLiteralDelimiters:
82+
PreferredDelimiters:
83+
'%': '()'
84+
'%i': '()'
85+
'%q': '()'
86+
'%Q': '()'
87+
'%r': '{}'
88+
'%s': '()'
89+
'%w': '()'
90+
'%W': '()'
91+
'%x': '()'
92+
93+
Style/RescueStandardError:
94+
Enabled: false
95+
96+
Style/EmptyMethod:
97+
EnforcedStyle: expanded
98+
99+
Style/SymbolArray:
100+
Enabled: false
101+
102+
### Layout ###
103+
Layout/EmptyLineAfterGuardClause:
104+
Enabled: false
105+
106+
Layout/LeadingCommentSpace:
107+
Enabled: false
108+
109+
### Naming ###
110+
Naming/PredicatePrefix:
111+
Enabled: false
112+
113+
Naming/MethodParameterName:
114+
Enabled: false
115+
116+
Naming/PredicateMethod:
117+
Enabled: false
118+
119+
### Metrics ###
120+
Metrics/AbcSize:
121+
Enabled: false
122+
123+
Metrics/BlockLength:
124+
Enabled: false
125+
126+
Metrics/BlockNesting:
127+
Enabled: false
128+
129+
Metrics/ClassLength:
130+
Enabled: false
131+
132+
Metrics/CyclomaticComplexity:
133+
Enabled: false
134+
135+
Layout/LineLength:
136+
Enabled: false
137+
138+
Metrics/MethodLength:
139+
Enabled: false
140+
141+
Metrics/ModuleLength:
142+
Enabled: false
143+
144+
Metrics/PerceivedComplexity:
145+
Enabled: false

Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gemspec
6+
7+
gem "rubocop", group: :development

Gemfile.lock

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
PATH
2+
remote: .
3+
specs:
4+
simple_master (0.1.0)
5+
activerecord (>= 7.0)
6+
activesupport (>= 7.0)
7+
request_store (>= 1.0)
8+
9+
GEM
10+
remote: https://rubygems.org/
11+
specs:
12+
activemodel (8.1.1)
13+
activesupport (= 8.1.1)
14+
activerecord (8.1.1)
15+
activemodel (= 8.1.1)
16+
activesupport (= 8.1.1)
17+
timeout (>= 0.4.0)
18+
activesupport (8.1.1)
19+
base64
20+
bigdecimal
21+
concurrent-ruby (~> 1.0, >= 1.3.1)
22+
connection_pool (>= 2.2.5)
23+
drb
24+
i18n (>= 1.6, < 2)
25+
json
26+
logger (>= 1.4.2)
27+
minitest (>= 5.1)
28+
securerandom (>= 0.3)
29+
tzinfo (~> 2.0, >= 2.0.5)
30+
uri (>= 0.13.1)
31+
ast (2.4.3)
32+
base64 (0.3.0)
33+
bigdecimal (4.0.1)
34+
concurrent-ruby (1.3.6)
35+
connection_pool (3.0.2)
36+
drb (2.2.3)
37+
i18n (1.14.8)
38+
concurrent-ruby (~> 1.0)
39+
json (2.18.0)
40+
language_server-protocol (3.17.0.5)
41+
lint_roller (1.1.0)
42+
logger (1.7.0)
43+
minitest (6.0.0)
44+
prism (~> 1.5)
45+
parallel (1.27.0)
46+
parser (3.3.10.0)
47+
ast (~> 2.4.1)
48+
racc
49+
prism (1.7.0)
50+
racc (1.8.1)
51+
rack (3.2.4)
52+
rainbow (3.1.1)
53+
regexp_parser (2.11.3)
54+
request_store (1.7.0)
55+
rack (>= 1.4)
56+
rubocop (1.82.0)
57+
json (~> 2.3)
58+
language_server-protocol (~> 3.17.0.2)
59+
lint_roller (~> 1.1.0)
60+
parallel (~> 1.10)
61+
parser (>= 3.3.0.2)
62+
rainbow (>= 2.2.2, < 4.0)
63+
regexp_parser (>= 2.9.3, < 3.0)
64+
rubocop-ast (>= 1.48.0, < 2.0)
65+
ruby-progressbar (~> 1.7)
66+
unicode-display_width (>= 2.4.0, < 4.0)
67+
rubocop-ast (1.48.0)
68+
parser (>= 3.3.7.2)
69+
prism (~> 1.4)
70+
ruby-progressbar (1.13.0)
71+
securerandom (0.4.1)
72+
timeout (0.6.0)
73+
tzinfo (2.0.6)
74+
concurrent-ruby (~> 1.0)
75+
unicode-display_width (3.2.0)
76+
unicode-emoji (~> 4.1)
77+
unicode-emoji (4.2.0)
78+
uri (1.1.1)
79+
80+
PLATFORMS
81+
arm64-darwin-24
82+
x86_64-linux
83+
84+
DEPENDENCIES
85+
rubocop
86+
simple_master!
87+
88+
BUNDLED WITH
89+
2.7.1

lib/simple_master/active_record/extension.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def belongs_to(name, scope = nil, **options)
2828
unless options[:polymorphic]
2929
class_name = options[:class_name] || ActiveSupport::Inflector.classify(name)
3030

31-
klass = compute_type("#{class_name}")
31+
klass = compute_type(class_name.to_s)
3232
if klass < SimpleMaster::Master
3333
return belongs_to_master(name, options)
3434
else
@@ -91,7 +91,7 @@ def has_one(name, scope = nil, **options)
9191

9292
class_name = options[:class_name] || ActiveSupport::Inflector.classify(name)
9393

94-
klass = compute_type("#{class_name}")
94+
klass = compute_type(class_name.to_s)
9595
if klass < SimpleMaster::Master
9696
has_one_master(name, options)
9797
else
@@ -122,7 +122,7 @@ def has_many(name, scope = nil, **options)
122122

123123
class_name = options[:class_name] || ActiveSupport::Inflector.classify(name)
124124

125-
klass = compute_type("#{class_name}")
125+
klass = compute_type(class_name.to_s)
126126
if klass < SimpleMaster::Master
127127
has_many_master(name, options)
128128
else

lib/simple_master/master/column/enum_column.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ def #{name}_before_type_cast
6464

6565
enum.each_key do |enum_name|
6666
# Skip generating helpers for names that start with a digit
67-
unless enum_name.match?(/\A\d/)
68-
master_class.simple_master_module.class_eval <<-RUBY, __FILE__, __LINE__ + 1
67+
next if enum_name.match?(/\A\d/)
68+
master_class.simple_master_module.class_eval <<-RUBY, __FILE__, __LINE__ + 1
6969
def #{prefix}#{enum_name}#{suffix}?
7070
#{name} == :#{enum_name}
7171
end
72-
RUBY
73-
end
72+
RUBY
7473
end
7574
end
7675

lib/simple_master/master/queryable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def insert_queries(records, on_duplicate_key_update = false, batch_size: 10000)
3535
values_sql =
3636
sliced_records.map { |record|
3737
sql_column_methods
38-
.zip(column_names)
39-
.map { |method_name, column_name|
38+
.zip(column_names)
39+
.map { |method_name, column_name|
4040
if [:updated_at, :created_at].include?(column_name)
4141
current_time
4242
else

lib/simple_master/storage/dataset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def unload
9090
tables.clear
9191
end
9292

93-
# Note: Pass a empty hash to duplicate with empty diff.
93+
# NOTE: Pass a empty hash to duplicate with empty diff.
9494
def duplicate(diff: nil)
9595
diff ||= @diff
9696
new_dataset = self.class.new(table_class: table_class, loader: loader)

0 commit comments

Comments
 (0)