Land #2932, msftidy for Travis
commit
9658a4d863
|
@ -1,9 +1,11 @@
|
||||||
language: ruby
|
language: ruby
|
||||||
|
env: MSF_SPOTCHECK_RECENT=1
|
||||||
before_install:
|
before_install:
|
||||||
- rake --version
|
- rake --version
|
||||||
- sudo apt-get update -qq
|
- sudo apt-get update -qq
|
||||||
- sudo apt-get install -qq libpcap-dev
|
- sudo apt-get install -qq libpcap-dev
|
||||||
before_script:
|
before_script:
|
||||||
|
- ./tools/msftidy.rb
|
||||||
- cp config/database.yml.travis config/database.yml
|
- cp config/database.yml.travis config/database.yml
|
||||||
- bundle exec rake --version
|
- bundle exec rake --version
|
||||||
- bundle exec rake db:create
|
- bundle exec rake db:create
|
||||||
|
|
|
@ -8,8 +8,10 @@
|
||||||
#
|
#
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'find'
|
require 'find'
|
||||||
|
require 'time'
|
||||||
|
|
||||||
CHECK_OLD_RUBIES = !!ENV['MSF_CHECK_OLD_RUBIES']
|
CHECK_OLD_RUBIES = !!ENV['MSF_CHECK_OLD_RUBIES']
|
||||||
|
SPOTCHECK_RECENT = !!ENV['MSF_SPOTCHECK_RECENT']
|
||||||
|
|
||||||
if CHECK_OLD_RUBIES
|
if CHECK_OLD_RUBIES
|
||||||
require 'rvm'
|
require 'rvm'
|
||||||
|
@ -38,34 +40,47 @@ class Msftidy
|
||||||
|
|
||||||
LONG_LINE_LENGTH = 200 # From 100 to 200 which is stupidly long
|
LONG_LINE_LENGTH = 200 # From 100 to 200 which is stupidly long
|
||||||
|
|
||||||
attr_reader :full_filepath, :source, :stat, :name
|
# Status codes
|
||||||
|
OK = 0x00
|
||||||
|
WARNINGS = 0x10
|
||||||
|
ERRORS = 0x20
|
||||||
|
|
||||||
|
attr_reader :full_filepath, :source, :stat, :name, :status
|
||||||
|
|
||||||
def initialize(source_file)
|
def initialize(source_file)
|
||||||
@full_filepath = source_file
|
@full_filepath = source_file
|
||||||
@source = load_file(source_file)
|
@source = load_file(source_file)
|
||||||
|
@status = OK
|
||||||
@name = File.basename(source_file)
|
@name = File.basename(source_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
public
|
public
|
||||||
|
|
||||||
##
|
|
||||||
#
|
#
|
||||||
# The following two functions only print what you throw at them,
|
# Display a warning message, given some text and a number. Warnings
|
||||||
# with the option of displying the line number. error() is meant
|
# are usually style issues that may be okay for people who aren't core
|
||||||
# for mistakes that might actually break something.
|
# Framework developers.
|
||||||
#
|
#
|
||||||
##
|
# @return status [Integer] Returns WARNINGS unless we already have an
|
||||||
|
# error.
|
||||||
def warn(txt, line=0)
|
def warn(txt, line=0) line_msg = (line>0) ? ":#{line}" : ''
|
||||||
line_msg = (line>0) ? ":#{line}" : ''
|
|
||||||
puts "#{@full_filepath}#{line_msg} - [#{'WARNING'.yellow}] #{txt}"
|
puts "#{@full_filepath}#{line_msg} - [#{'WARNING'.yellow}] #{txt}"
|
||||||
|
@status == ERRORS ? @status = ERRORS : @status = WARNINGS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Display an error message, given some text and a number. Errors
|
||||||
|
# can break things or are so egregiously bad, style-wise, that they
|
||||||
|
# really ought to be fixed.
|
||||||
|
#
|
||||||
|
# @return status [Integer] Returns ERRORS
|
||||||
def error(txt, line=0)
|
def error(txt, line=0)
|
||||||
line_msg = (line>0) ? ":#{line}" : ''
|
line_msg = (line>0) ? ":#{line}" : ''
|
||||||
puts "#{@full_filepath}#{line_msg} - [#{'ERROR'.red}] #{txt}"
|
puts "#{@full_filepath}#{line_msg} - [#{'ERROR'.red}] #{txt}"
|
||||||
|
@status = ERRORS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Currently unused, but some day msftidy will fix errors for you.
|
||||||
def fixed(txt, line=0)
|
def fixed(txt, line=0)
|
||||||
line_msg = (line>0) ? ":#{line}" : ''
|
line_msg = (line>0) ? ":#{line}" : ''
|
||||||
puts "#{@full_filepath}#{line_msg} - [#{'FIXED'.green}] #{txt}"
|
puts "#{@full_filepath}#{line_msg} - [#{'FIXED'.green}] #{txt}"
|
||||||
|
@ -465,6 +480,11 @@ class Msftidy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Run all the msftidy checks.
|
||||||
|
#
|
||||||
|
# @param full_filepath [String] The full file path to check
|
||||||
|
# @return status [Integer] A status code suitable for use as an exit status
|
||||||
def run_checks(full_filepath)
|
def run_checks(full_filepath)
|
||||||
tidy = Msftidy.new(full_filepath)
|
tidy = Msftidy.new(full_filepath)
|
||||||
tidy.check_mode
|
tidy.check_mode
|
||||||
|
@ -484,6 +504,7 @@ def run_checks(full_filepath)
|
||||||
tidy.check_snake_case_filename
|
tidy.check_snake_case_filename
|
||||||
tidy.check_comment_splat
|
tidy.check_comment_splat
|
||||||
tidy.check_vuln_codes
|
tidy.check_vuln_codes
|
||||||
|
return tidy
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -494,9 +515,25 @@ end
|
||||||
|
|
||||||
dirs = ARGV
|
dirs = ARGV
|
||||||
|
|
||||||
if dirs.length < 1
|
if SPOTCHECK_RECENT
|
||||||
|
msfbase = %x{\\git rev-parse --show-toplevel}.strip
|
||||||
|
if File.directory? msfbase
|
||||||
|
Dir.chdir(msfbase)
|
||||||
|
else
|
||||||
|
$stderr.puts "You need a git binary in your path to use this functionality."
|
||||||
|
exit(0x02)
|
||||||
|
end
|
||||||
|
last_release = %x{\\git tag -l #{DateTime.now.year}\\*}.split.last
|
||||||
|
new_modules = %x{\\git diff #{last_release}..HEAD --name-only --diff-filter A modules}
|
||||||
|
dirs = dirs | new_modules.split
|
||||||
|
end
|
||||||
|
|
||||||
|
# Don't print an error if there's really nothing to check.
|
||||||
|
unless SPOTCHECK_RECENT
|
||||||
|
if dirs.length < 1
|
||||||
$stderr.puts "Usage: #{File.basename(__FILE__)} <directory or file>"
|
$stderr.puts "Usage: #{File.basename(__FILE__)} <directory or file>"
|
||||||
exit(1)
|
exit(0x01)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dirs.each do |dir|
|
dirs.each do |dir|
|
||||||
|
@ -505,9 +542,12 @@ dirs.each do |dir|
|
||||||
next if full_filepath =~ /\.git[\x5c\x2f]/
|
next if full_filepath =~ /\.git[\x5c\x2f]/
|
||||||
next unless File.file? full_filepath
|
next unless File.file? full_filepath
|
||||||
next unless full_filepath =~ /\.rb$/
|
next unless full_filepath =~ /\.rb$/
|
||||||
run_checks(full_filepath)
|
msftidy = run_checks(full_filepath)
|
||||||
|
@exit_status = msftidy.status if (msftidy.status > @exit_status.to_i)
|
||||||
end
|
end
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
$stderr.puts "#{File.basename(__FILE__)}: #{dir}: No such file or directory"
|
$stderr.puts "#{File.basename(__FILE__)}: #{dir}: No such file or directory"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
exit(@exit_status.to_i)
|
||||||
|
|
Loading…
Reference in New Issue