Consolidate ruby style

This commit is contained in:
Markus Schirp 2014-05-27 15:12:36 +00:00
parent cff1bceaed
commit cc69582cb2
30 changed files with 96 additions and 83 deletions

View file

@ -30,6 +30,19 @@ CollectionMethods:
find: 'detect'
find_all: 'select'
# Use square brackets for literal Array objects
PercentLiteralDelimiters:
PreferredDelimiters:
'%': ()
'%i': '[]'
'%q': ()
'%Q': ()
'%r': '{}'
'%s': ()
'%w': '[]'
'%W': '[]'
'%x': ()
MethodLength:
CountComments: false
Max: 17 # TODO: Bring down to 10

View file

@ -1,7 +0,0 @@
# encoding: UTF-8
require 'rspec'
require 'mutant/rspec'
require 'mutant/rspec/strategy'
require 'mutant/rspec/test'

View file

@ -285,7 +285,7 @@ module Mutant
# @api private
#
def use(name)
require "mutant-#{name}"
require "mutant/#{name}"
@strategy = Strategy.lookup(name).new
rescue LoadError
$stderr.puts("Cannot load plugin: #{name.inspect}")
@ -339,7 +339,7 @@ module Mutant
def add_debug_options(opts)
opts.on('--fail-fast', 'Fail fast') do
@fail_fast = true
end.on('--version', 'Print mutants version') do |name|
end.on('--version', 'Print mutants version') do
puts("mutant-#{Mutant::VERSION}")
Kernel.exit(0)
end.on('-d', '--debug', 'Enable debugging output') do

View file

@ -132,7 +132,7 @@ module Mutant
# @api private
#
abstract_method :matcher
private :matcher
private :matcher
end # Classifier
end # CLI

View file

@ -5,20 +5,20 @@ module Mutant
symbolset = ->(strings) { strings.map(&:to_sym).to_set.freeze }
# Set of nodes that cannot be on the LHS of an assignment
NOT_ASSIGNABLE = symbolset.(%w(int float str dstr class module self))
NOT_ASSIGNABLE = symbolset.(%w[int float str dstr class module self])
# Set of op-assign types
OP_ASSIGN = symbolset.call(%w(or_asgn and_asgn op_asgn))
OP_ASSIGN = symbolset.call(%w[or_asgn and_asgn op_asgn])
# Set of node types that are not valid when emitted standalone
NOT_STANDALONE = symbolset.(%w( splat restarg block_pass))
INDEX_OPERATORS = symbolset.(%w([] []=))
UNARY_METHOD_OPERATORS = symbolset.(%w(~@ +@ -@ !))
NOT_STANDALONE = symbolset.(%w[ splat restarg block_pass])
INDEX_OPERATORS = symbolset.(%w[[] []=])
UNARY_METHOD_OPERATORS = symbolset.(%w[~@ +@ -@ !])
# Operators ruby implementeds as methods
METHOD_OPERATORS = symbolset.(%w(
METHOD_OPERATORS = symbolset.(%w[
<=> === []= [] <= >= == !~ != =~ <<
>> ** * % / | ^ & < > + - ~@ +@ -@ !
))
])
BINARY_METHOD_OPERATORS = (
METHOD_OPERATORS - (INDEX_OPERATORS + UNARY_METHOD_OPERATORS)
@ -32,10 +32,10 @@ module Mutant
#
# not - 1.8 only, mutant does not support 1.8
#
NODE_BLACKLIST = symbolset.(%w(not))
NODE_BLACKLIST = symbolset.(%w[not])
# Nodes that are NOT generated by parser but used by mutant / unparser.
NODE_EXTRA = symbolset.(%w(empty))
NODE_EXTRA = symbolset.(%w[empty])
NODE_TYPES = ((Parser::Meta::NODE_TYPES + NODE_EXTRA) - NODE_BLACKLIST).to_set.freeze

View file

@ -46,7 +46,7 @@ module Mutant
def skip?
location = source_location
if location.nil? || BLACKLIST.match(location.first)
message = sprintf(
message = format(
'%s does not have valid source location unable to emit matcher',
method.inspect
)

View file

@ -94,7 +94,7 @@ module Mutant
when :const
receiver_name?(receiver)
else
message = sprintf(
message = format(
'Can only match :defs on :self or :const got %s unable to match',
receiver.type.inspect
)

View file

@ -16,7 +16,7 @@ module Mutant
#
# @api private
#
def each(&block)
def each
return to_enum unless block_given?
self
end

View file

@ -43,7 +43,7 @@ module Mutant
# @api private
#
def mlhs_childs_with_index
children.each_with_index.select do |child, index|
children.each_with_index.select do |child, _index|
child.type == :mlhs
end
end

View file

@ -145,7 +145,7 @@ module Mutant
#
def mutate_arguments
emit_self(receiver, selector)
remaining_children_with_index.each do |node, index|
remaining_children_with_index.each do |_node, index|
mutate_child(index)
delete_child(index)
end

View file

@ -60,7 +60,7 @@ module Mutant
# @api private
#
def info(string, *arguments)
puts(sprintf(string, *arguments))
puts(format(string, *arguments))
end
# Print a status line to output
@ -70,7 +70,7 @@ module Mutant
# @api private
#
def status(string, *arguments)
puts(colorize(status_color, sprintf(string, *arguments)))
puts(colorize(status_color, format(string, *arguments)))
end
# Print a line to output

View file

@ -23,13 +23,13 @@ module Mutant
#
def run
failed_subjects.each(&method(:visit))
info 'Subjects: %s', amount_subjects
info 'Mutations: %s', amount_mutations
info 'Kills: %s', amount_kills
info 'Alive: %s', amount_alive
info 'Runtime: %0.2fs', runtime
info 'Killtime: %0.2fs', killtime
info 'Overhead: %0.2f%%', overhead
info 'Subjects: %s', amount_subjects
info 'Mutations: %s', amount_mutations
info 'Kills: %s', amount_kills
info 'Alive: %s', amount_alive
info 'Runtime: %0.2fs', runtime
info 'Killtime: %0.2fs', killtime
info 'Overhead: %0.2f%%', overhead
status 'Coverage: %0.2f%%', coverage
status 'Expected: %0.2f%%', object.config.expected_coverage
print_generic_stats

View file

@ -5,3 +5,7 @@ module Mutant
module Rspec
end # Rspec
end # Mutant
require 'mutant/rspec'
require 'mutant/rspec/strategy'
require 'mutant/rspec/test'

View file

@ -125,7 +125,7 @@ module Mutant
# @api private
#
def options
options = RSpec::Core::ConfigurationOptions.new(%w(--fail-fast spec))
options = RSpec::Core::ConfigurationOptions.new(%w[--fail-fast spec])
options.parse_options if rspec2?
options
end

View file

@ -83,8 +83,6 @@ module Mutant
[]
end
private
# Null strategy that never kills a mutation
class Null < self

View file

@ -43,8 +43,6 @@ module Mutant
self
end
private
# Mutator for memoized instance methods
class Memoized < self
include NodeHelpers

View file

@ -6,16 +6,16 @@ module Mutant
include Adamantium::Flat, Concord.new(:namespace)
# Excluded into zombification
includes = %w(
includes = %w[
mutant
morpher
adamantium
equalizer
anima
concord
)
]
INCLUDES = %r(\A#{Regexp.union(includes)}(?:/.*)?\z).freeze
INCLUDES = %r{\A#{Regexp.union(includes)}(?:/.*)?\z}.freeze
# Initialize object
#

View file

@ -11,7 +11,7 @@ module Mutant
# @api private
#
def zombify(namespace)
$stderr.puts("Zombifying #{path.to_s}")
$stderr.puts("Zombifying #{path}")
eval(
Unparser.unparse(namespaced_node(namespace)),
TOPLEVEL_BINDING,

View file

@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
gem.license = 'MIT'
gem.require_paths = %w[lib]
gem.files = `git ls-files -- lib/mutant{-,/}rspec.rb lib/mutant/rspec`.split("\n")
gem.files = `git ls-files -- lib/mutant/rspec.rb lib/mutant/rspec`.split("\n")
gem.test_files = `git ls-files -- spec/{unit/mutant/rspec,integration/rspec}`.split("\n")
gem.extra_rdoc_files = %w[TODO LICENSE]

View file

@ -23,13 +23,14 @@ describe 'Mutant on ruby corpus' do
# @raise [Exception]
# otherwise
#
# rubocop:disable MethodLength
def verify
checkout
total = 0
parse_errors = []
start = Time.now
Pathname.glob(repo_path.join('**/*.rb')).sort.each do |path|
puts "Generating mutations for: #{path.to_s}"
puts "Generating mutations for: #{path}"
begin
node = Parser::CurrentRuby.parse(path.read)
# Ignore known parser bugs
@ -39,7 +40,7 @@ describe 'Mutant on ruby corpus' do
end
next if node.nil?
count = 0
Mutant::Mutator::Node.each(node) do |mutant|
Mutant::Mutator::Node.each(node) do
count += 1
if (count % 1000).zero?
puts count
@ -49,9 +50,13 @@ describe 'Mutant on ruby corpus' do
total += count
end
took = Time.now - start
puts "Total Mutations/Time/Parse-Errors: %s/%0.2fs/%i - %0.2f/s" % [
total, took, parse_errors.size, total / took
]
puts format(
'Total Mutations/Time/Parse-Errors: %s/%0.2fs/%i - %0.2f/s',
total,
took,
parse_errors.size,
total / took
)
if parse_errors.any?
puts 'Files with parse errors:'
parse_errors.each(&method(:puts))
@ -69,11 +74,11 @@ describe 'Mutant on ruby corpus' do
TMP.mkdir unless TMP.directory?
if repo_path.exist?
Dir.chdir(repo_path) do
system(%w(git pull origin master))
system(%w(git clean -f -d -x))
system(%w[git pull origin master])
system(%w[git clean -f -d -x])
end
else
system(%W(git clone #{repo_uri} #{repo_path}))
system(%W[git clone #{repo_uri} #{repo_path}])
end
self
end

View file

@ -4,7 +4,7 @@ require 'spec_helper'
describe 'as a zombie' do
specify 'it allows to create zombie from mutant' do
expect { Mutant.zombify }.to change { !!defined?(Zombie) }.from(false).to(true)
expect { Mutant.zombify }.to change { defined?(Zombie) }.from(nil).to('constant')
expect(Zombie.constants).to include(:Mutant)
end
end

View file

@ -15,7 +15,7 @@ shared_examples_for 'a cli parser' do
it { expect(subject.strategy).to eql(expected_strategy) }
it { expect(subject.reporter).to eql(expected_reporter) }
it { expect(subject.matcher).to eql(expected_matcher) }
it { expect(subject.matcher).to eql(expected_matcher) }
end
describe Mutant::CLI, '.new' do
@ -39,7 +39,7 @@ describe Mutant::CLI, '.new' do
subject { cli }
context 'with unknown flag' do
let(:arguments) { %w(--invalid) }
let(:arguments) { %w[--invalid] }
let(:expected_message) { 'invalid option: --invalid' }
@ -47,7 +47,7 @@ describe Mutant::CLI, '.new' do
end
context 'with unknown option' do
let(:arguments) { %w(--invalid Foo) }
let(:arguments) { %w[--invalid Foo] }
let(:expected_message) { 'invalid option: --invalid' }
@ -63,14 +63,14 @@ describe Mutant::CLI, '.new' do
end
context 'with code filter and missing argument' do
let(:arguments) { %w(--code) }
let(:arguments) { %w[--code] }
let(:expected_message) { 'missing argument: --code' }
it_should_behave_like 'an invalid cli run'
end
context 'with explicit method pattern' do
let(:arguments) { %w(TestApp::Literal#float) }
let(:arguments) { %w[TestApp::Literal#float] }
let(:expected_matcher) do
ns::Method::Instance.new(cache, TestApp::Literal, TestApp::Literal.instance_method(:float))
@ -81,7 +81,7 @@ describe Mutant::CLI, '.new' do
context 'with debug flag' do
let(:pattern) { '::TestApp*' }
let(:arguments) { %W(--debug #{pattern}) }
let(:arguments) { %W[--debug #{pattern}] }
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
it_should_behave_like 'a cli parser'
@ -93,7 +93,7 @@ describe Mutant::CLI, '.new' do
context 'with zombie flag' do
let(:pattern) { '::TestApp*' }
let(:arguments) { %W(--zombie #{pattern}) }
let(:arguments) { %W[--zombie #{pattern}] }
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
it_should_behave_like 'a cli parser'
@ -104,8 +104,8 @@ describe Mutant::CLI, '.new' do
end
context 'with namespace pattern' do
let(:pattern) { '::TestApp*' }
let(:arguments) { %W(#{pattern}) }
let(:pattern) { '::TestApp*' }
let(:arguments) { [pattern] }
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
it_should_behave_like 'a cli parser'
@ -113,7 +113,7 @@ describe Mutant::CLI, '.new' do
context 'with subject code filter' do
let(:pattern) { 'TestApp::Literal#float' }
let(:arguments) { %W(--code faa --code bbb #{pattern}) }
let(:arguments) { %W[--code faa --code bbb #{pattern}] }
let(:expected_filter) do
Morpher.evaluator(

View file

@ -12,7 +12,7 @@ describe Mutant::Diff do
let(:old_string) { "foo\nbar" }
let(:new_string) { "bar\nbaz" }
it { should eql(Mutant::Diff.new(%w(foo bar), %w(bar baz))) }
it { should eql(Mutant::Diff.new(%w[foo bar], %w[bar baz])) }
end
@ -46,8 +46,8 @@ describe Mutant::Diff do
subject { object.diff }
context 'when there is a diff at begin of hunk' do
let(:old) { %w(foo bar) }
let(:new) { %w(baz bar) }
let(:old) { %w[foo bar] }
let(:new) { %w[baz bar] }
let(:expectation) do
strip_indent(<<-STR)
@ -64,8 +64,8 @@ describe Mutant::Diff do
end
context 'when there is a diff NOT at begin of hunk' do
let(:old) { %w(foo bar) }
let(:new) { %w(foo baz bar) }
let(:old) { %w[foo bar] }
let(:new) { %w[foo baz bar] }
let(:expectation) do
strip_indent(<<-STR)
@ -82,8 +82,8 @@ describe Mutant::Diff do
end
context 'when the diff has a long context at begin' do
let(:old) { %w(foo bar baz boz a b c) }
let(:new) { %w(foo bar baz boz a b c other) }
let(:old) { %w[foo bar baz boz a b c] }
let(:new) { %w[foo bar baz boz a b c other] }
let(:expectation) do
strip_indent(<<-STR)
@ -105,8 +105,8 @@ describe Mutant::Diff do
end
context 'when the diff has a long context at end, deleting' do
let(:old) { %w(other foo bar baz boz a b c) }
let(:new) { %w(foo bar baz boz a b c) }
let(:old) { %w[other foo bar baz boz a b c] }
let(:new) { %w[foo bar baz boz a b c] }
let(:expectation) do
strip_indent(<<-STR)
@ -128,8 +128,8 @@ describe Mutant::Diff do
end
context 'when the diff has a long context at end, inserting' do
let(:old) { %w(foo bar baz boz a b c) }
let(:new) { %w(other foo bar baz boz a b c) }
let(:old) { %w[foo bar baz boz a b c] }
let(:new) { %w[other foo bar baz boz a b c] }
let(:expectation) do
strip_indent(<<-STR)

View file

@ -2,6 +2,7 @@
require 'spec_helper'
# rubocop:disable ClassAndModuleChildren
describe Mutant::Matcher::Method::Instance do
let(:cache) { Fixtures::AST_CACHE }
@ -44,7 +45,7 @@ describe Mutant::Matcher::Method::Instance do
def bar
end
def bar(arg)
def bar(_arg)
end
end
@ -57,7 +58,7 @@ describe Mutant::Matcher::Method::Instance do
context 'on the same line' do
let(:base) { __LINE__ }
class self::Foo
def bar; end; def bar(arg); end
def bar; end; def bar(_arg); end
end
let(:method_line) { 2 }
@ -69,7 +70,7 @@ describe Mutant::Matcher::Method::Instance do
context 'on the same line with differend scope' do
let(:base) { __LINE__ }
class self::Foo
def self.bar; end; def bar(arg); end
def self.bar; end; def bar(_arg); end
end
let(:method_line) { 2 }

View file

@ -2,6 +2,7 @@
require 'spec_helper'
# rubocop:disable ClassAndModuleChildren
describe Mutant::Matcher::Method::Singleton, '#each' do
subject { object.each { |subject| yields << subject } }
@ -80,7 +81,7 @@ describe Mutant::Matcher::Method::Singleton, '#each' do
module Bar
def self.baz
end
def Foo.baz(arg)
def Foo.baz(_arg)
end
end
end

View file

@ -7,7 +7,7 @@ describe Mutant::Mutator::Node::Literal, 'boolean' do
let(:source) { 'true' }
let(:mutations) do
%w(nil false)
%w[nil false]
end
it_should_behave_like 'a mutator'
@ -17,7 +17,7 @@ describe Mutant::Mutator::Node::Literal, 'boolean' do
let(:source) { 'false' }
let(:mutations) do
%w(nil true)
%w[nil true]
end
it_should_behave_like 'a mutator'

View file

@ -6,7 +6,7 @@ describe Mutant::Mutator::Node::Literal, 'fixnum' do
let(:source) { '10' }
let(:mutations) do
%W(nil 0 1 -10 9 11)
%w[nil 0 1 -10 9 11]
end
it_should_behave_like 'a mutator'

View file

@ -8,7 +8,7 @@ describe Mutant::Mutator::Node::Literal, 'string' do
let(:source) { '"foo"' }
let(:mutations) do
%W(nil)
%w[nil]
end
it_should_behave_like 'a mutator'

View file

@ -8,7 +8,7 @@ describe Mutant::Mutator::Node::Literal, 'symbol' do
let(:source) { ':foo' }
let(:mutations) do
%w(nil) << ':foo__mutant__'
%w[nil :foo__mutant__]
end
it_should_behave_like 'a mutator'

View file

@ -7,7 +7,7 @@ module TestApp
true
end
def command(foo)
def command(_foo)
self
end