Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RuboCopper
class RuboCopper
def analyze
system 'rubocop', '--display-cop-names', *files
end
def autofix
system 'rubocop', '--auto-correct', '--display-cop-names', *files
end
def valid?
`rubocop #{files.join(' ')}`.include? 'no offenses detected'
end
private
def files
@files ||= (changed_files + untracked_files + staged_files)
.split("\n")
.uniq
.select { |f| ruby_file?(f) && File.exist?(f) }
end
def changed_files
@changed_files ||= `git diff --name-only master #{branch}`
end
def untracked_files
@untracked_files ||= `git ls-files . --exclude-standard --others`
end
def staged_files
@staged_files ||= `git diff --name-only --cached`
end
def ruby_file?(file)
file[-3..(file.length)] == '.rb'
end
def branch
@branch ||= `git rev-parse --abbrev-ref HEAD`.chomp
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.