Skip to content

Commit

Permalink
Merge branch 'rubocop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nishidayuya committed Aug 3, 2014
2 parents 4804263 + f4f9673 commit ab699cf
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 19 deletions.
50 changes: 50 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,50 @@
# We adopt "Semantic Block".
# In "Semantic Block" way, "{...}" block and "do ... end" block are
# NOT same semantics.
#
# * "{...}" block specifies last evaluated value.
# Block caller can use block result.
# * "do ... end" block doesn't specify last evaluated value.
# So, block caller MUST NOT use block result.
Style/Blocks:
Enabled: false

# For low indent level.
Style/ClassAndModuleChildren:
EnforcedStyle: compact

# From number of terminal lines - 2 ("def" line and "end" line).
Style/MethodLength:
Max: 22

# "if !a" is better than "unless a", we think.
# Because condition(s) often will be appended another codition(s).
# In "unless a" case, we'll inverse codition(s).
#
# Which do you like?
# * unless: "unless a" + "&& b"
# We'll waver between "unless a || !b" and "if !a && b".
# In either case, our brain must inverse condition.
# * if !: "if !a" + "&& b"
# We'll write "if !a && b" without inverse.
Style/NegatedIf:
Enabled: false

# Don't allow /\//.
Style/RegexpLiteral:
MaxSlashes: 0

# Sometimes we add "#{...}" to string which is already exists.
#
# Which do you like?
# * single_quotes: 'foo' + "#{a}" => "foo#{a}"
# Oops, we must change from ' to ". And we take extra differences.
# (Try "git diff --color-words=." or "git log -p --color-words=.")
# * double_quotes: "foo" + "#{a}" => "foo#{a}"
# There is no problem on another case.
Style/StringLiterals:
EnforcedStyle: double_quotes

# To define private constants.
Lint/UselessAccessModifier:
Enabled: false
7 changes: 6 additions & 1 deletion Rakefile
@@ -1,6 +1,11 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"

RSpec::Core::RakeTask.new

task :default => :spec
RuboCop::RakeTask.new do |task|
task.patterns = %w(lib/**/*.rb spec/**/*.rb **/*.gemspec)
end

task default: %i(rubocop spec)
3 changes: 2 additions & 1 deletion git-dust.gemspec
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/nishidayuya/git-dust"
spec.license = "X11"

spec.files = `git ls-files`.split($/)
spec.files = `git ls-files -z`.split("\0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
Expand All @@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "guard-bundler"
spec.add_development_dependency "guard-rspec"
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "rubocop"
end
23 changes: 11 additions & 12 deletions lib/git/dust.rb
Expand Up @@ -3,13 +3,15 @@
require "open3"
require "pathname"

# A namespace for Git::Dust.
module Git
end

# Main class.
class Git::Dust
def self.help(args = [])
def self.help(_args = [])
$stderr.puts(<<EOS)
#{File.basename($0)} <command> [<args>]
#{File.basename($PROGRAM_NAME)} <command> [<args>]
git dust commands are:
* commit
Expand All @@ -35,7 +37,7 @@ def self.commit(args)
run_command(*%w(git commit -m), COMMIT_MESSAGE, *args)
end

def self.fix(args)
def self.fix(_args)
base_sha1 = find_non_dust_commit
saved_editor_environment = ENV["GIT_SEQUENCE_EDITOR"]
begin
Expand All @@ -54,10 +56,9 @@ def self.edit_rebase_commit_list(args)
rebase_todo_path.open do |f|
lines = f.each_line
lines.each do |l| # write first commit
if !/\A\s*#/.match(l)
output << l
break
end
next if /\A\s*#/.match(l)
output << l
break
end
lines.each do |l| # change "pick" to "fixup"
output << l.sub(/\Apick/, "fixup")
Expand All @@ -73,19 +74,17 @@ def self.edit_rebase_commit_list(args)
COMMIT_MESSAGE = "git dust commit.".freeze

def self.run_command(*args)
if !system(*args)
raise "failed: args=<#{args.inspect}>"
end
fail "failed: args=<#{args.inspect}>" if !system(*args)
end

def self.find_non_dust_commit
Open3.popen2("git log --format=oneline") do |stdin, stdout, wait_thread|
Open3.popen2("git log --format=oneline") do |_stdin, stdout, _wait_thread|
stdout.each_line.each do |line|
sha1, subject = line.chomp.split(" ", 2)
return sha1 if COMMIT_MESSAGE != subject
end
end
raise "non dust commit is not exist."
fail "non dust commit is not exist."
end
end

Expand Down
12 changes: 8 additions & 4 deletions spec/git/dust_spec.rb
Expand Up @@ -88,8 +88,8 @@ def chenv(environments = {})
expect do
Git::Dust.run(%w(invaid-command))
end.to raise_error(SystemExit)
end.to output(/\Asub command not found: sub_command=<invaid-command>/).
to_stderr
end.to output(/\Asub command not found: sub_command=<invaid-command>/)
.to_stderr
end

it "invoke help method" do
Expand All @@ -106,7 +106,9 @@ def chenv(environments = {})
g.chdir do
expect do
Git::Dust.commit([])
end.to change {g.log.count}.by(1)
end.to change {
g.log.count
}.by(1)
end
expect(g.log.first.message).to eq("git dust commit.")
end
Expand Down Expand Up @@ -155,7 +157,9 @@ def chenv(environments = {})
GIT_EDITOR: git_editor_path) do
expect do
Git::Dust.fix([])
end.to change {g.log.count}.from(3).to(2)
end.to change {
g.log.count
}.from(3).to(2)
end
end
expect(g.log.first.message).to eq("some commit message.")
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -16,8 +16,8 @@
BIN_PATH = TOP_PATH + "bin"
LIB_PATH = TOP_PATH + "lib"

# compatibility
if !Pathname.public_method_defined?(:write)
# For 2.0.x compatibility.
class Pathname
def write(*args)
open("w") do |f|
Expand Down

0 comments on commit ab699cf

Please sign in to comment.