Skip to content

Commit bca6576

Browse files
Fix Rubocop workflow (#41)
* Fix Rubocop workflow * Bump rubocop * Update files * Fix supers * Bump mocha * Bump simplecov * Downgrade rubocop * Another attempt * Revert * Exclude simplecov * Exclude all vendor
1 parent de8f448 commit bca6576

File tree

9 files changed

+63
-49
lines changed

9 files changed

+63
-49
lines changed

.github/workflows/rubocop.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,25 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- name: Checkout code
15+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
1516

1617
- name: Set up Ruby
17-
uses: ruby/setup-ruby@a699edbce608a2c128dedad88e3b6a0e28687b3c
18+
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
1819
with:
19-
ruby-version: 2.6.6
20+
ruby-version: .ruby-version
2021
bundler-cache: true
2122

2223
- name: Install gems
2324
run: |
24-
gem install rubocop
25-
gem install rubocop-minitest
26-
gem install rubocop-performance
25+
# Extract the exact versions of the rubocop gems from Gemfile.lock
26+
rubocop_version=$(sed -n -E 's/^ rubocop \((.+)\)/\1/p' Gemfile.lock)
27+
rubocop_minitest_version=$(sed -n -E 's/^ rubocop-minitest \((.+)\)/\1/p' Gemfile.lock)
28+
rubocop_performance_version=$(sed -n -E 's/^ rubocop-performance \((.+)\)/\1/p' Gemfile.lock)
29+
30+
gem install rubocop -v $rubocop_version
31+
gem install rubocop-minitest -v $rubocop_minitest_version
32+
gem install rubocop-performance -v $rubocop_performance_version
2733
2834
- name: Run Rubocop
2935
run: rubocop --except Metrics

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ AllCops:
66
NewCops: disable
77
Exclude:
88
- "bin/**/*"
9+
- "tests/**/*"
10+
- "vendor/**/*"
911
- "Gemfile"
1012
- "Gemfile.lock"
1113

@@ -27,6 +29,7 @@ Layout/EmptyLinesAroundAccessModifier:
2729
Layout/LineLength:
2830
Exclude:
2931
- "scripts/generate_fixture.rb"
32+
- "test/**/*"
3033

3134
Lint/SuppressedException:
3235
Exclude:

Gemfile.lock

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
ast (2.4.1)
4+
ast (2.4.2)
55
coderay (1.1.3)
6-
docile (1.3.2)
7-
json (2.3.1)
6+
docile (1.4.0)
7+
json (2.6.3)
88
mandate (0.3.0)
99
method_source (1.0.0)
1010
minitest (5.14.2)
1111
minitest-stub-const (0.6)
12-
mocha (1.11.2)
13-
parallel (1.20.0)
14-
parser (2.7.2.0)
12+
mocha (2.1.0)
13+
ruby2_keywords (>= 0.0.5)
14+
parallel (1.23.0)
15+
parser (3.2.2.3)
1516
ast (~> 2.4.1)
17+
racc
1618
pry (0.13.1)
1719
coderay (~> 1.1)
1820
method_source (~> 1.0)
19-
rainbow (3.0.0)
21+
racc (1.7.1)
22+
rainbow (3.1.1)
2023
rake (13.0.1)
21-
regexp_parser (1.8.2)
22-
rexml (3.2.4)
23-
rubocop (1.3.1)
24+
regexp_parser (2.8.1)
25+
rexml (3.2.6)
26+
rubocop (1.50.2)
27+
json (~> 2.3)
2428
parallel (~> 1.10)
25-
parser (>= 2.7.1.5)
29+
parser (>= 3.2.0.0)
2630
rainbow (>= 2.2.2, < 4.0)
27-
regexp_parser (>= 1.8)
28-
rexml
29-
rubocop-ast (>= 1.1.1)
31+
regexp_parser (>= 1.8, < 3.0)
32+
rexml (>= 3.2.5, < 4.0)
33+
rubocop-ast (>= 1.28.0, < 2.0)
3034
ruby-progressbar (~> 1.7)
31-
unicode-display_width (>= 1.4.0, < 2.0)
32-
rubocop-ast (1.1.1)
33-
parser (>= 2.7.1.5)
35+
unicode-display_width (>= 2.4.0, < 3.0)
36+
rubocop-ast (1.29.0)
37+
parser (>= 3.2.1.0)
3438
rubocop-minitest (0.10.1)
3539
rubocop (>= 0.87)
3640
rubocop-performance (1.9.0)
3741
rubocop (>= 0.90.0, < 2.0)
3842
rubocop-ast (>= 0.4.0)
39-
ruby-progressbar (1.10.1)
43+
ruby-progressbar (1.13.0)
44+
ruby2_keywords (0.0.5)
4045
simplecov (0.17.1)
4146
docile (~> 1.1)
4247
json (>= 1.8, < 3)
4348
simplecov-html (~> 0.10.0)
4449
simplecov-html (0.10.2)
45-
unicode-display_width (1.7.0)
50+
unicode-display_width (2.4.2)
4651

4752
PLATFORMS
4853
ruby
@@ -62,4 +67,4 @@ DEPENDENCIES
6267
simplecov (~> 0.17.0)
6368

6469
BUNDLED WITH
65-
2.1.4
70+
2.3.6

bin/rubocop-quick

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

3-
git diff --name-status --staged | grep '^[MA]' | grep -o '\s\+.*rb' | xargs bundle exec rubocop --except Metrics --auto-correct --format quiet --force-exclusion Gemfile && \
3+
git diff --name-status --staged | grep '^[MA]' | grep -o '\s\+.*rb' | xargs bundle exec rubocop --except Metrics --autocorrect --format quiet --force-exclusion Gemfile && \
44
git diff --name-status --staged | grep '^[MA]' | grep -o '\s\+.*rb' | xargs git add

lib/generate_mapping.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class GenerateMapping < Parser::AST::Processor
66
def initialize(code)
77
@code = code
88
@mapping = {}
9+
super()
910
end
1011

1112
def call
@@ -90,7 +91,7 @@ def process(node)
9091
node.arguments.each do |arg|
9192
case arg.type
9293
when :sym
93-
add_entry(arg.loc.expression.source[1..-1])
94+
add_entry(arg.loc.expression.source[1..])
9495
when :str
9596
add_entry(arg.value)
9697
end
@@ -128,14 +129,15 @@ def add_entry(token)
128129
return if mapping.key?(token)
129130

130131
# The placeholder case should match the token type and case
131-
if token[0] == "@"
132-
mapping[token] = "@placeholder_#{mapping.size}"
133-
elsif token[0] == "$"
134-
mapping[token] = "$placeholder_#{mapping.size}"
135-
elsif token[0] == token[0].capitalize
136-
mapping[token] = "PLACEHOLDER_#{mapping.size}"
137-
else
138-
mapping[token] = "placeholder_#{mapping.size}"
139-
end
132+
mapping[token] = case token[0]
133+
when "@"
134+
"@placeholder_#{mapping.size}"
135+
when "$"
136+
"$placeholder_#{mapping.size}"
137+
when token[0].capitalize
138+
"PLACEHOLDER_#{mapping.size}"
139+
else
140+
"placeholder_#{mapping.size}"
141+
end
140142
end
141143
end

lib/normalizers/naming_normalizer.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class NamingNormalizer < Parser::TreeRewriter
77
def initialize(code, mapping)
88
@original_code = code
99
@mapping = mapping
10+
super()
1011
end
1112

1213
def call
@@ -39,31 +40,31 @@ def on_send(node)
3940
super
4041
end
4142

42-
def process_regular_node
43-
super
44-
end
43+
# def process_regular_node
44+
# super
45+
# end
4546

4647
def on_op_asgn(node)
4748
p "opasgn"
48-
#node.pry
49+
# node.pry
4950
super
5051
end
5152

5253
def on_casgn(node)
5354
p "casgn"
54-
#node.pry
55+
# node.pry
5556
super
5657
end
5758

5859
def on_defs(node)
5960
p "defs"
60-
#node.pry
61+
# node.pry
6162
super
6263
end
6364

6465
def on_numblock(node)
6566
p "numblock"
66-
#node.pry
67+
# node.pry
6768
super
6869
end
6970

@@ -74,7 +75,7 @@ def handler_missing(node)
7475
super
7576
else
7677
p "handler_missing"
77-
#node.pry
78+
# node.pry
7879
end
7980
end
8081

lib/representer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
require_relative 'representation'
1212
require_relative 'represent_solution'
1313

14-
#require 'pry'
14+
# require 'pry'
1515

1616
module Representer
1717
def self.generate(exercise_slug, solution_path, output_path)

test/normalizers/naming_normalisation_test.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,4 @@ def placeholder_0(placeholder_1, placeholder_2)
130130
"
131131
assert_representation code, representation
132132
end
133-
134-
135133
end

test/representer_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ def total_time_in_minutes(number_of_layers:, actual_minutes_in_oven:)
4545
assert_equal ast, File.read("#{dir}/representation.txt")
4646
end
4747
end
48-
4948
end

0 commit comments

Comments
 (0)