Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinakayama committed Jun 11, 2017
1 parent 55de20a commit bd424db
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 78 deletions.
26 changes: 21 additions & 5 deletions .rubocop.yml
@@ -1,12 +1,28 @@
# The default 79 character limit is sometimes unproductive.
LineLength:
Layout/IndentArray:
EnforcedStyle: consistent

Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'

Metrics/LineLength:
Max: 100

# The default 10 lines limit is unrealistic.
MethodLength:
Metrics/MethodLength:
Max: 15

RegexpLiteral:
Style/EmptyMethod:
EnforcedStyle: expanded

Style/Encoding:
Enabled: true
EnforcedStyle: never

Style/MethodMissing:
Exclude:
- spec/support/silence_output.rb

Style/RegexpLiteral:
Exclude:
- '**/*.gemspec'
- '**/Guardfile'
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -7,8 +7,8 @@ group :test do
end

platforms :rbx do
gem 'rubysl'
gem 'rubinius-developer_tools'
gem 'json'
gem 'racc' # Needed for RuboCop
gem 'rubinius-developer_tools'
gem 'rubysl'
end
4 changes: 1 addition & 3 deletions Rakefile
@@ -1,10 +1,8 @@
# coding: utf-8

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:style)

task ci: [:spec, :style]
task ci: %i[spec style]
2 changes: 0 additions & 2 deletions guard-rubocop.gemspec
@@ -1,5 +1,3 @@
# coding: utf-8

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand Down
2 changes: 0 additions & 2 deletions lib/guard/rubocop.rb
@@ -1,5 +1,3 @@
# coding: utf-8

require 'guard'
require 'guard/plugin'

Expand Down
8 changes: 3 additions & 5 deletions lib/guard/rubocop/runner.rb
@@ -1,5 +1,3 @@
# coding: utf-8

require 'json'

module Guard
Expand Down Expand Up @@ -29,7 +27,7 @@ def build_command(paths)
command = ['rubocop']

if should_add_default_formatter_for_console?
command.concat(%w(--format progress)) # Keep default formatter for console.
command.concat(%w[--format progress]) # Keep default formatter for console.
end

command.concat(['--format', 'json', '--out', json_file_path])
Expand All @@ -49,7 +47,7 @@ def args_specified_by_user
when Array then args
when String then args.shellsplit
when NilClass then []
else fail ArgumentError, ':cli option must be either an array or string'
else raise ArgumentError, ':cli option must be either an array or string'
end
end
end
Expand Down Expand Up @@ -115,7 +113,7 @@ def failed_paths
def pluralize(number, thing, options = {})
text = ''

if number == 0 && options[:no_for_zero]
if number.zero? && options[:no_for_zero]
text = 'no'
else
text << number.to_s
Expand Down
2 changes: 0 additions & 2 deletions lib/guard/rubocop/version.rb
@@ -1,5 +1,3 @@
# coding: utf-8

module Guard
# A workaround for declaring `class RuboCop`
# before `class RuboCop < Guard` in rubocop.rb
Expand Down
5 changes: 0 additions & 5 deletions spec/.rubocop.yml

This file was deleted.

82 changes: 37 additions & 45 deletions spec/guard/rubocop/runner_spec.rb
@@ -1,5 +1,3 @@
# coding: utf-8

require 'spec_helper.rb'

describe Guard::RuboCop::Runner do
Expand Down Expand Up @@ -77,39 +75,39 @@

context 'when :notification option is true' do
let(:options) { { notification: true } }
include_examples 'notification', { passed: true, failed: true }
include_examples 'notification', passed: true, failed: true
end

context 'when :notification option is :failed' do
let(:options) { { notification: :failed } }
include_examples 'notification', { passed: false, failed: true }
include_examples 'notification', passed: false, failed: true
end

context 'when :notification option is false' do
let(:options) { { notification: false } }
include_examples 'notification', { passed: false, failed: false }
include_examples 'notification', passed: false, failed: false
end
end

describe '#build_command' do
subject(:build_command) { runner.build_command(paths) }
let(:options) { { cli: %w(--debug --rails) } }
let(:paths) { %w(file1.rb file2.rb) }
let(:options) { { cli: %w[--debug --rails] } }
let(:paths) { %w[file1.rb file2.rb] }

context 'when :hide_stdout is not set' do
context 'and :cli option includes formatter for console' do
before { options[:cli] = %w(--format simple) }
before { options[:cli] = %w[--format simple] }

it 'does not add args for the default formatter for console' do
expect(build_command[0..2]).not_to eq(%w(rubocop --format progress))
expect(build_command[0..2]).not_to eq(%w[rubocop --format progress])
end
end

context 'and :cli option does not include formatter for console' do
before { options[:cli] = %w(--format simple --out simple.txt) }
before { options[:cli] = %w[--format simple --out simple.txt] }

it 'adds args for the default formatter for console' do
expect(build_command[0..2]).to eq(%w(rubocop --format progress))
expect(build_command[0..2]).to eq(%w[rubocop --format progress])
end
end
end
Expand All @@ -118,24 +116,24 @@
before { options[:hide_stdout] = true }

context 'and :cli option includes formatter for console' do
before { options[:cli] = %w(--format simple) }
before { options[:cli] = %w[--format simple] }

it 'does not add args for the default formatter for console' do
expect(build_command[0..2]).not_to eq(%w(rubocop --format progress))
expect(build_command[0..2]).not_to eq(%w[rubocop --format progress])
end
end

context 'and :cli option does not include formatter for console' do
before { options[:cli] = %w(--format simple --out simple.txt) }
before { options[:cli] = %w[--format simple --out simple.txt] }

it 'does not add args for the default formatter for console' do
expect(build_command[0..2]).not_to eq(%w(rubocop --format progress))
expect(build_command[0..2]).not_to eq(%w[rubocop --format progress])
end
end
end

it 'adds args for JSON formatter' do
expect(build_command[3..4]).to eq(%w(--format json))
expect(build_command[3..4]).to eq(%w[--format json])
end

it 'adds args for output file path of JSON formatter' do
Expand All @@ -148,11 +146,11 @@
end

it 'adds args specified by user' do
expect(build_command[8..9]).to eq(%w(--debug --rails))
expect(build_command[8..9]).to eq(%w[--debug --rails])
end

it 'adds the passed paths' do
expect(build_command[10..-1]).to eq(%w(file1.rb file2.rb))
expect(build_command[10..-1]).to eq(%w[file1.rb file2.rb])
end
end

Expand Down Expand Up @@ -195,23 +193,23 @@

context 'when the passed args include a -f/--format' do
context 'but does not include an -o/--output' do
let(:args) { %w(--format simple --debug) }
let(:args) { %w[--format simple --debug] }

it 'returns true' do
expect(include_formatter_for_console?).to be_truthy
end
end

context 'and include an -o/--output just after the -f/--format' do
let(:args) { %w(--format simple --out simple.txt) }
let(:args) { %w[--format simple --out simple.txt] }

it 'returns false' do
expect(include_formatter_for_console?).to be_falsey
end
end

context 'and include an -o/--output after the -f/--format across another arg' do
let(:args) { %w(--format simple --debug --out simple.txt) }
let(:args) { %w[--format simple --debug --out simple.txt] }

it 'returns false' do
expect(include_formatter_for_console?).to be_falsey
Expand All @@ -221,15 +219,15 @@

context 'when the passed args include a -f with its arg without separator' do
context 'but does not include an -o/--output' do
let(:args) { %w(-fs --debug) }
let(:args) { %w[-fs --debug] }

it 'returns true' do
expect(include_formatter_for_console?).to be_truthy
end
end

context 'and include an -o with its arg without separator just after the -f/--format' do
let(:args) { %w(-fs -osimple.txt) }
let(:args) { %w[-fs -osimple.txt] }

it 'returns false' do
expect(include_formatter_for_console?).to be_falsey
Expand All @@ -239,23 +237,23 @@

context 'when the passed args include multiple -f/--format' do
context 'and all -f/--format have associated -o/--out' do
let(:args) { %w(--format simple --out simple.txt --format emacs --out emacs.txt) }
let(:args) { %w[--format simple --out simple.txt --format emacs --out emacs.txt] }

it 'returns false' do
expect(include_formatter_for_console?).to be_falsey
end
end

context 'and any -f/--format has associated -o/--out' do
let(:args) { %w(--format simple --format emacs --out emacs.txt) }
let(:args) { %w[--format simple --format emacs --out emacs.txt] }

it 'returns true' do
expect(include_formatter_for_console?).to be_truthy
end
end

context 'and no -f/--format has associated -o/--out' do
let(:args) { %w(--format simple --format emacs) }
let(:args) { %w[--format simple --format emacs] }

it 'returns true' do
expect(include_formatter_for_console?).to be_truthy
Expand All @@ -264,7 +262,7 @@
end

context 'when the passed args do not include -f/--format' do
let(:args) { %w(--debug) }
let(:args) { %w[--debug] }

it 'returns false' do
expect(include_formatter_for_console?).to be_falsey
Expand Down Expand Up @@ -334,12 +332,10 @@
describe '#notify' do
before do
allow(runner).to receive(:result).and_return(
{
summary: {
offense_count: 4,
target_file_count: 3,
inspected_file_count: 2
}
summary: {
offense_count: 4,
target_file_count: 3,
inspected_file_count: 2
}
)
end
Expand Down Expand Up @@ -380,12 +376,10 @@
describe '#summary_text' do
before do
allow(runner).to receive(:result).and_return(
{
summary: {
offense_count: offense_count,
target_file_count: target_file_count,
inspected_file_count: inspected_file_count
}
summary: {
offense_count: offense_count,
target_file_count: target_file_count,
inspected_file_count: inspected_file_count
}
)
end
Expand Down Expand Up @@ -441,12 +435,10 @@
context 'with spelling "offence" in old RuboCop' do
before do
allow(runner).to receive(:result).and_return(
{
summary: {
offence_count: 2,
target_file_count: 1,
inspected_file_count: 1
}
summary: {
offence_count: 2,
target_file_count: 1,
inspected_file_count: 1
}
)
end
Expand Down
4 changes: 1 addition & 3 deletions spec/guard/rubocop_spec.rb
@@ -1,5 +1,3 @@
# coding: utf-8

require 'spec_helper.rb'

describe Guard::RuboCop, :silence_output do
Expand Down Expand Up @@ -111,7 +109,7 @@
end
end

[:run_on_additions, :run_on_modifications].each do |method|
%i[run_on_additions run_on_modifications].each do |method|
describe "##{method}", :processes_after_running do
subject { super().send(method, changed_paths) }
let(:changed_paths) do
Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
@@ -1,5 +1,3 @@
# coding: utf-8

RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.syntax = :expect
Expand Down
2 changes: 0 additions & 2 deletions spec/support/silence_output.rb
@@ -1,5 +1,3 @@
# coding: utf-8

shared_context 'silence output', silence_output: true do
null_object = BasicObject.new

Expand Down

0 comments on commit bd424db

Please sign in to comment.