Skip to content

Commit 4f60cd8

Browse files
authored
Add rubocop with a few basic styling rules (#849)
* Use rubocop to enforce a few styling rules * Add a CI job for linting
1 parent 4afc98c commit 4f60cd8

File tree

7 files changed

+48
-5
lines changed

7 files changed

+48
-5
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ jobs:
1212
with:
1313
engine: cruby-truffleruby
1414
min_version: 2.7
15-
15+
lint:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Ruby
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: "3.3"
23+
bundler-cache: true
24+
- name: Run rubocop
25+
run: bundle exec rubocop
1626
irb:
1727
needs: ruby-versions
1828
name: rake test ${{ matrix.ruby }} ${{ matrix.with_latest_reline && '(latest reline)' || '' }}

.rubocop.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
AllCops:
2+
TargetRubyVersion: 3.0
3+
DisabledByDefault: true
4+
SuggestExtensions: false
5+
6+
Layout/TrailingWhitespace:
7+
Enabled: true
8+
9+
Layout/TrailingEmptyLines:
10+
Enabled: true
11+
12+
Layout/IndentationConsistency:
13+
Enabled: true
14+
15+
Layout/CaseIndentation:
16+
Enabled: true
17+
EnforcedStyle: end
18+
19+
Layout/CommentIndentation:
20+
Enabled: true
21+
22+
Layout/IndentationStyle:
23+
Enabled: true
24+
25+
Layout/SpaceAroundKeyword:
26+
Enabled: true
27+
28+
Layout/SpaceBeforeComma:
29+
Enabled: true
30+
31+
Layout/SpaceAfterComma:
32+
Enabled: true

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ gem "rake"
1717
gem "test-unit"
1818
gem "test-unit-ruby-core"
1919

20+
gem "rubocop"
21+
2022
gem "debug", github: "ruby/debug", platforms: [:mri, :mswin]
2123

2224
if RUBY_VERSION >= "3.0.0" && !is_truffleruby

lib/irb/inspector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Inspector
4646
# Determines the inspector to use where +inspector+ is one of the keys passed
4747
# during inspector definition.
4848
def self.keys_with_inspector(inspector)
49-
INSPECTORS.select{|k,v| v == inspector}.collect{|k, v| k}
49+
INSPECTORS.select{|k, v| v == inspector}.collect{|k, v| k}
5050
end
5151

5252
# Example

lib/irb/locale.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def load(file)
9494
end
9595
end
9696

97-
def find(file , paths = $:)
97+
def find(file, paths = $:)
9898
dir = File.dirname(file)
9999
dir = "" if dir == "."
100100
base = File.basename(file)

test/irb/test_input_method.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,3 @@ def has_rdoc_content?
170170
end
171171
end
172172
end
173-

test/irb/test_workspace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_toplevel_binding_local_variables
9191
irb_path = "#{top_srcdir}/#{dir}/irb"
9292
File.exist?(irb_path)
9393
end or omit 'irb command not found'
94-
assert_in_out_err(bundle_exec + ['-W0', "-C#{top_srcdir}", '-e', <<~RUBY , '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
94+
assert_in_out_err(bundle_exec + ['-W0', "-C#{top_srcdir}", '-e', <<~RUBY, '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
9595
version = 'xyz' # typical rubygems loading file
9696
load('#{irb_path}')
9797
RUBY

0 commit comments

Comments
 (0)