-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Using Rubocop
Rubocop is a great tool for beginning and experienced Ruby coders if you treat the output for what it is: suggestions. While msftidy remains our barrier to entry, there are many things it will not catch. As msftidy is not strict enough to catch everything, Rubocop sometimes goes too far in its suggestions.
Installing Rubocop is really easy. Simply go to your metasploit-framework directory and run:
gem install rubocop
Run rubocop <ruby file>
Don't worry about it. Metasploit Project uses msftidy as the minimum barrier to submitting code, but we strongly encourage contributors to run their ruby code through Rubocop. Where Msftidy does the bare minimum, Rubocop sometimes goes too far. Treat the output of Rubocop as a suggestion, not really as a black and white rule. Part of that reason is because at best, the Metasploit team probably only agrees on 50% of the suggestions from Rubocop. Other suggestions can bleed into snide comments, coding holy wars, and Nerf battles that last until we forget why we were fighting.
White space affects code readability, and we'd like to try and maintain (or establish) an continual look and feel. If Rubocop complains about whitespace, please take it to heart.
Rubocop likes aligned parentheses, spaces around brackets, and is picky about spacing around most encapsulating syntax elements. As a big fan of Python, I agree wholeheartedly with these alignment and spacing suggestions, as it makes me feel like I'm home. Others will disagree about importance, but no one will complain if you do it right, only varying volumes of complaining when doing it wrong.
As stated above, Rubocops's code complexity warnings are less useful than we'd like. Please keep functions below 100 lines (50 is better). Otherwise, just be clear. If two lines will be readable, use two lines. Someone will be coming along behind you. Please do not make that person hate you.
Rubocop encourages single-line incomprehensible conditional statements that reek of blatant, painful, Ruby exhibitionism. Again, as a non-native Ruby coder that has to go back and figure out what old modules do, I humbly request that you please ignore those warnings. Make your conditional statements easy to read and understand, make them stand out as conditional, and please, never, ever use unless
. I've watched unless
screw up very good, talented, experienced coders. I've also watched senior members of our team snap and git grep
through the codebase ripping out unless
statements and muttering unpleasant things the entire time.
If your conditional statement takes up two whole lines, so be it. If two nested conditional statements can be replaced with a single, unreadable and impossible to debug multi-line complex statement, please leave the two statements in place.
This is likely never to come up, but if it does, please don't use ternary operators.
Consistency is a virtue only when it is correct. (In all seriousness, use your best judgement here, and don't be afraid to ask.)
- Home Welcome to Metasploit!
- Using Metasploit A collection of useful links for penetration testers.
-
Setting Up a Metasploit Development Environment From
apt-get install
togit push
. - CONTRIBUTING.md What should your contributions look like?
- Landing Pull Requests Working with other people's contributions.
- Using Git All about Git and GitHub.
- Contributing to Metasploit Be a part of our open source community.
- Meterpreter All about the Meterpreter payload.