-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
221 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
|
||
# rspec failure tracking | ||
.rspec_status | ||
|
||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
Metrics/BlockLength: | ||
Enabled: false | ||
Metrics/MethodLength: | ||
Enabled: false | ||
Style/StringLiterals: | ||
Enabled: false | ||
Style/AccessModifierDeclarations: | ||
Enabled: false | ||
Layout/MultilineMethodCallIndentation: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative File.join('..', 'lib', 'refactor') | ||
require 'optparse' | ||
|
||
@options = {} | ||
|
||
OptionParser.new do |opts| | ||
opts.on('-rRULES', '--rules=RULES', 'Directory to load rules from') do |rule_directory| | ||
@options[:rule_directory] = rule_directory | ||
end | ||
|
||
opts.on('-tTARGET', '--target=TARGET', 'Target glob to run rules against') do |target_glob| | ||
@options[:target_glob] = target_glob | ||
end | ||
|
||
opts.on('-d', '--dry-run', 'Do not change underlying files, output changes') do |dry_run| | ||
@options[:dry_run] = dry_run | ||
end | ||
|
||
opts.on("-h", "--help", "Prints this help") do | ||
puts opts | ||
exit | ||
end | ||
end.parse! | ||
|
||
runner = Refactor::Runner.new(**@options) | ||
runner.run! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refactor | ||
VERSION = "0.1.0" | ||
VERSION = "0.1.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
class BigDecimalRule < Refactor::Rule | ||
def on_send(node) | ||
return unless node in [:send, _, :BigDecimal, | ||
[:float | :int, value] | ||
] | ||
|
||
replace(node, "BigDecimal('#{value}')") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class HashRefDefaultRule < Refactor::Rule | ||
def on_send(node) | ||
return unless node in [:send, [:const, nil, :Hash], :new, | ||
[:array | :hash] => reference_value | ||
] | ||
|
||
replace(node, "Hash.new { |h, k| h[k] = #{reference_value.source} }") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Inherits from base rule, which provides a lot of utilities | ||
# to match and replace with. | ||
class ShorthandRule < Refactor::Rule | ||
# The code we're trying to work with here is: | ||
# | ||
# [1, 2, 3].select { |v| v.even? } | ||
# | ||
# ...and we want to make it into: | ||
# | ||
# [1, 2, 3].select(&:even?) | ||
# | ||
def on_block(node) | ||
return unless node in [:block, receiver, | ||
[[:arg, arg_name]], [:send, [:lvar, ^arg_name], method_name] | ||
] | ||
|
||
replace(node, "#{receiver.source}(&:#{method_name})") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters