Skip to content

Commit 5fa639c

Browse files
author
Tod Beardsley
committed
Land rapid7#3528, add Rubocop from @jhart-r7
This adds the gem to the :development group in the Gemfile, as well as wires up msftidy to use it.
2 parents f8e47a5 + fa472c7 commit 5fa639c

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

.rubocop.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
LineLength:
2+
Enabled: true
3+
Max: 180
4+
5+
MethodLength:
6+
Enabled: true
7+
Max: 100
8+
9+
Style/ClassLength:
10+
Exclude:
11+
# Most modules are quite large and all contained in one class. This is OK.
12+
- 'modules/**/*'
13+
14+
Style/NumericLiterals:
15+
Enabled: false
16+
17+
Documentation:
18+
Exclude:
19+
- 'modules/**/*'

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and Metasploit's [Common Coding Mistakes](https://github.com/rapid7/metasploit-f
3333
## Code Contributions
3434

3535
* **Do** stick to the [Ruby style guide](https://github.com/bbatsov/ruby-style-guide).
36+
* Similarly, **try** to get Rubocop passing or at least relatively quiet against the files added/modified as part of your contribution
3637
* **Do** follow the [50/72 rule](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) for Git commit messages.
3738
* **Do** create a [topic branch](http://git-scm.com/book/en/Git-Branching-Branching-Workflows#Topic-Branches) to work on instead of working directly on `master`.
3839

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ group :pcap do
3737
end
3838

3939
group :development do
40+
# Style/sanity checking Ruby code
41+
gem 'rubocop'
4042
# Markdown formatting for yard
4143
gem 'redcarpet'
4244
# generating documentation

Gemfile.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ GEM
1313
i18n (~> 0.6, >= 0.6.4)
1414
multi_json (~> 1.0)
1515
arel (3.0.2)
16+
ast (2.0.0)
1617
bcrypt (3.1.7)
1718
builder (3.0.4)
1819
database_cleaner (1.1.1)
@@ -34,8 +35,13 @@ GEM
3435
nokogiri (1.6.0)
3536
mini_portile (~> 0.5.0)
3637
packetfu (1.1.9)
38+
parser (2.1.9)
39+
ast (>= 1.1, < 3.0)
40+
slop (~> 3.4, >= 3.4.5)
3741
pcaprub (0.11.3)
3842
pg (0.16.0)
43+
powerpack (0.0.9)
44+
rainbow (2.0.0)
3945
rake (10.1.0)
4046
redcarpet (3.0.0)
4147
rkelly-remix (0.0.6)
@@ -48,12 +54,20 @@ GEM
4854
rspec-expectations (2.14.2)
4955
diff-lcs (>= 1.1.3, < 2.0)
5056
rspec-mocks (2.14.3)
57+
rubocop (0.23.0)
58+
json (>= 1.7.7, < 2)
59+
parser (~> 2.1.9)
60+
powerpack (~> 0.0.6)
61+
rainbow (>= 1.99.1, < 3.0)
62+
ruby-progressbar (~> 1.4)
63+
ruby-progressbar (1.5.1)
5164
shoulda-matchers (2.3.0)
5265
activesupport (>= 3.0.0)
5366
simplecov (0.5.4)
5467
multi_json (~> 1.0.3)
5568
simplecov-html (~> 0.5.3)
5669
simplecov-html (0.5.3)
70+
slop (3.5.0)
5771
sqlite3 (1.3.9)
5872
timecop (0.6.3)
5973
tzinfo (0.3.37)
@@ -83,6 +97,7 @@ DEPENDENCIES
8397
rkelly-remix (= 0.0.6)
8498
robots
8599
rspec (>= 2.12)
100+
rubocop
86101
shoulda-matchers
87102
simplecov (= 0.5.4)
88103
sqlite3

tools/msftidy.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ def check_extname
320320
end
321321
end
322322

323+
# Explicitly skip this check if we're suppressing info messages
324+
# anyway, since it takes a fair amount of time per module to perform.
325+
def check_rubocop
326+
return true if SUPPRESS_INFO_MESSAGES
327+
out = %x{rubocop -n #{@full_filepath}}
328+
ret = $?
329+
info("Fails to pass Rubocop Ruby style guidelines (run 'rubocop #{@full_filepath}' to see violations)") unless ret.exitstatus == 0
330+
end
331+
323332
def check_old_rubies
324333
return true unless CHECK_OLD_RUBIES
325334
return true unless Object.const_defined? :RVM
@@ -574,6 +583,7 @@ def run_checks(full_filepath)
574583
tidy.check_vuln_codes
575584
tidy.check_vars_get
576585
tidy.check_newline_eof
586+
tidy.check_rubocop
577587
return tidy
578588
end
579589

0 commit comments

Comments
 (0)