Skip to content

Commit 50ed3d0

Browse files
committed
- Refactor with rentactop ruleset
1 parent 57c9dbd commit 50ed3d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1270
-1295
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/doc
66
/Gemfile.lock
77
/gems
8-
/rc.md
98
/spec/tmp
109
/tmp
1110
/toc.txt

.rubocop.yml

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,37 @@
1+
require: rubocop-rspec
2+
13
inherit_gem:
2-
google-style: google-style.yml
4+
rentacop: rentacop.yml
35

46
AllCops:
57
TargetRubyVersion: 2.7
68

9+
# The `ConfigValidator` class is a DSL, give it some complexity leeway
710
Metrics/AbcSize:
811
Exclude:
912
- lib/bashly/config_validator.rb
1013

11-
Metrics/BlockLength:
12-
Exclude:
13-
- 'spec/**/*_spec.rb'
14-
14+
# (same as previous rule)
1515
Metrics/CyclomaticComplexity:
1616
Exclude:
1717
- lib/bashly/config_validator.rb
1818

19+
# (same as previous rule)
1920
Metrics/PerceivedComplexity:
2021
Exclude:
2122
- lib/bashly/config_validator.rb
2223

24+
# (same as previous rule)
2325
Metrics/MethodLength:
2426
Exclude:
2527
- lib/bashly/config_validator.rb
2628

29+
# Guard clauses are less readable in the case of `ConfigValidator`
2730
Style/GuardClause:
2831
Exclude:
2932
- lib/bashly/config_validator.rb
3033

31-
Style/RescueStandardError:
32-
Exclude:
33-
- bin/bashly
34-
35-
Style/MixinUsage:
34+
# Commands may include long lines
35+
Layout/LineLength:
3636
Exclude:
37-
- bin/*
38-
- spec/spec_helper.rb
39-
40-
Layout/ArgumentAlignment: { Enabled: false }
41-
Layout/CaseIndentation: { Enabled: false }
42-
Layout/ElseAlignment: { Enabled: false }
43-
Layout/EndAlignment: { Enabled: false }
44-
Layout/IndentationWidth: { Enabled: false }
45-
Layout/LineLength: { Enabled: false }
46-
Layout/MultilineMethodCallIndentation: { Enabled: false }
47-
Lint/ElseLayout: { Enabled: false }
48-
Lint/NonAtomicFileOperation: { Enabled: false }
49-
Metrics/ClassLength: { Enabled: false }
50-
Style/AccessorGrouping: { Enabled: false }
51-
Style/Documentation: { Enabled: false }
52-
Style/EmptyElse: { Enabled: false }
53-
Style/FormatString: { Enabled: false }
54-
Style/PercentLiteralDelimiters: { Enabled: false }
55-
Style/SymbolArray: { Enabled: false }
56-
Style/WordArray: { Enabled: false }
57-
Style/StringConcatenation: { Enabled: false }
37+
- 'lib/bashly/commands/*'

Gemfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
gem "byebug"
4-
gem "google-style"
5-
gem "lp"
6-
gem "rspec"
7-
gem "rspec_approvals"
8-
gem "runfile"
9-
gem "runfile-tasks"
10-
gem "simplecov"
3+
gem 'byebug'
4+
gem 'lp'
5+
gem 'rentacop', path: '/vagrant/gems/rentacop'
6+
gem 'rspec'
7+
gem 'rspec_approvals'
8+
gem 'rubocop'
9+
gem 'rubocop-rspec'
10+
gem 'runfile'
11+
gem 'runfile-tasks'
12+
gem 'simplecov'
1113

1214
gemspec

Runfile

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,4 @@ action :examples do
5252
end
5353
end
5454

55-
56-
command :rubocop
57-
58-
help "Save RuboCop Inspection Report"
59-
action :save do |args|
60-
say "generating report at rc.md"
61-
system "bundle exec rubocop -fm -o rc.md"
62-
end
63-
64-
help "Fix a single rule"
65-
usage "fix RULE"
66-
action :fix do |args|
67-
rule = args['RULE']
68-
say "!txtgrn!fixing #{rule}"
69-
system "bundle exec rubocop -a --only #{rule}"
70-
end
71-
72-
help "Check all or a single rule"
73-
usage "check [RULE]"
74-
action :check do |args|
75-
rule = args['RULE']
76-
if rule
77-
say "!txtgrn!checking #{rule}"
78-
system "bundle exec rubocop --only #{rule}"
79-
else
80-
system "bundle exec rubocop"
81-
end
82-
end
83-
84-
endcommand
85-
8655
require './debug.rb' if File.exist? 'debug.rb'

bashly.gemspec

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1-
lib = File.expand_path "lib", __dir__
1+
lib = File.expand_path 'lib', __dir__
22
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
3-
require "bashly/version"
3+
require 'bashly/version'
44

55
Gem::Specification.new do |s|
6-
s.name = "bashly"
6+
s.name = 'bashly'
77
s.version = Bashly::VERSION
8-
s.summary = "Bash Command Line Tool Generator"
9-
s.description = "Generate bash command line tools using YAML configuration"
10-
s.authors = ["Danny Ben Shitrit"]
11-
s.email = "db@dannyben.com"
12-
s.files = Dir["README.md", "lib/**/*"]
13-
s.executables = ["bashly"]
14-
s.homepage = "https://github.com/dannyben/bashly"
15-
s.license = "MIT"
16-
s.required_ruby_version = ">= 2.7.0"
8+
s.summary = 'Bash Command Line Tool Generator'
9+
s.description = 'Generate bash command line tools using YAML configuration'
10+
s.authors = ['Danny Ben Shitrit']
11+
s.email = 'db@dannyben.com'
12+
s.files = Dir['README.md', 'lib/**/*']
13+
s.executables = ['bashly']
14+
s.homepage = 'https://github.com/dannyben/bashly'
15+
s.license = 'MIT'
16+
s.required_ruby_version = '>= 2.7.0'
1717

1818
# Sensitive dependencies, stricter version requirements
19-
s.add_runtime_dependency "completely", "~> 0.5.0"
20-
s.add_runtime_dependency "gtx", "~> 0.1.0"
19+
s.add_runtime_dependency 'completely', '~> 0.5.0'
20+
s.add_runtime_dependency 'gtx', '~> 0.1.0'
2121

22-
s.add_runtime_dependency "colsole", "~> 0.7"
23-
s.add_runtime_dependency "filewatcher", "~> 2.0"
24-
s.add_runtime_dependency "lp", "~> 0.2"
25-
s.add_runtime_dependency "mister_bin", "~> 0.7"
26-
s.add_runtime_dependency "requires", "~> 0.2"
22+
s.add_runtime_dependency 'colsole', '~> 0.7'
23+
s.add_runtime_dependency 'filewatcher', '~> 2.0'
24+
s.add_runtime_dependency 'lp', '~> 0.2'
25+
s.add_runtime_dependency 'mister_bin', '~> 0.7'
26+
s.add_runtime_dependency 'requires', '~> 0.2'
2727

2828
s.metadata = {
29-
"bug_tracker_uri" => "https://github.com/DannyBen/bashly/issues",
30-
"changelog_uri" => "https://github.com/DannyBen/bashly/blob/master/CHANGELOG.md",
31-
"homepage_uri" => "https://bashly.dannyb.co/",
32-
"source_code_uri" => "https://github.com/DannyBen/bashly"
29+
'bug_tracker_uri' => 'https://github.com/DannyBen/bashly/issues',
30+
'changelog_uri' => 'https://github.com/DannyBen/bashly/blob/master/CHANGELOG.md',
31+
'homepage_uri' => 'https://bashly.dannyb.co/',
32+
'source_code_uri' => 'https://github.com/DannyBen/bashly',
33+
'rubygems_mfa_required' => 'true',
3334
}
3435
end

bin/bashly

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
2-
require "bashly"
3-
require "colsole"
2+
require 'bashly'
3+
require 'colsole'
44
include Colsole
55

66
runner = Bashly::CLI.runner
@@ -11,7 +11,7 @@ rescue Bashly::Interrupt
1111
say! "\nGoodbye"
1212
exit 1
1313
rescue => e
14-
puts e.backtrace.reverse if ENV["DEBUG"]
14+
puts e.backtrace.reverse if ENV['DEBUG']
1515
say! "!undred!#{e.class}!txtrst!\n#{e.message}"
1616
exit 1
1717
end

bin/console

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env ruby
22

3-
require "irb"
4-
require "irb/completion"
5-
require "bashly"
3+
require 'irb'
4+
require 'irb/completion'
5+
require 'bashly'
66

77
include Bashly
88

helpers/example.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class Example
33
class << self
44
def dirs
5-
@dirs ||= Dir["examples/*"].select { |f| File.directory? f }
5+
@dirs ||= Dir['examples/*'].select { |f| File.directory? f }
66
end
77

88
def all
@@ -16,7 +16,7 @@ def executables
1616

1717
attr_reader :dir
1818

19-
def initialize dir
19+
def initialize(dir)
2020
@dir = dir
2121
end
2222

@@ -45,13 +45,13 @@ def test_commands
4545
result = File.read(filename)
4646
.split(/\s*### Try Me ###\s*/).last
4747
.split("\n")
48-
.reject { |line| line.empty? or line.start_with? "#" }
48+
.reject { |line| line.empty? or line.start_with? '#' }
4949
abort "Can't find ### Try Me ### marker in #{filename}" if result.empty?
5050
result
5151
end
5252

5353
def test_output
54-
result = ""
54+
result = ''
5555
test_commands.each do |command|
5656
result += "### `$ #{command}`\n\n"
5757
result += "```shell\n"
@@ -69,9 +69,9 @@ def regenerate_readme
6969
end
7070

7171
def generated_readme
72-
marker = "-----"
72+
marker = '-----'
7373
content = readme.split(marker)[0].strip
74-
extra_files = ""
74+
extra_files = ''
7575
if content =~ /<!-- include: (.*) -->/
7676
included_files = ::Regexp.last_match(1).split
7777
extra_files = files_markdown included_files
@@ -97,7 +97,7 @@ def generated_readme
9797
MARKDOWN
9898
end
9999

100-
def files_markdown files
100+
def files_markdown(files)
101101
result = []
102102
files.each do |file|
103103
lang = markdown_lang file
@@ -110,19 +110,20 @@ def files_markdown files
110110
result.join "\n"
111111
end
112112

113-
def markdown_lang file
113+
def markdown_lang(file)
114114
result = langs[File.extname file]
115115
raise "Cannot determine language for #{file}" unless result
116+
116117
result
117118
end
118119

119120
def langs
120121
@langs ||= {
121-
"" => "bash",
122-
".sh" => "bash",
123-
".ini" => "ini",
124-
".yml" => "yaml",
125-
".yaml" => "yaml"
122+
'' => 'bash',
123+
'.sh' => 'bash',
124+
'.ini' => 'ini',
125+
'.yml' => 'yaml',
126+
'.yaml' => 'yaml',
126127
}
127128
end
128129

lib/bashly.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
require "requires"
1+
require 'requires'
22

3-
if ENV["BYEBUG"]
4-
require "byebug"
5-
require "lp"
3+
if ENV['BYEBUG']
4+
require 'byebug'
5+
require 'lp'
66
end
77

8-
requires "bashly/concerns"
8+
requires 'bashly/concerns'
99

10-
requires "bashly/extensions"
11-
requires "bashly/settings"
12-
requires "bashly/exceptions"
13-
requires "bashly/refinements"
14-
requires "bashly/script/base"
15-
requires "bashly/commands/base"
16-
requires "bashly/libraries/base"
17-
requires "bashly"
10+
requires 'bashly/extensions'
11+
requires 'bashly/settings'
12+
requires 'bashly/exceptions'
13+
requires 'bashly/refinements'
14+
requires 'bashly/script/base'
15+
requires 'bashly/commands/base'
16+
requires 'bashly/libraries/base'
17+
requires 'bashly'

lib/bashly/cli.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
require "mister_bin"
1+
require 'mister_bin'
22

33
module Bashly
44
# The CLI class is used by the bashly binary and forwards incoming CLI
55
# commands to the relevant Bashly::Commands class
66
class CLI
77
def self.runner
88
runner = MisterBin::Runner.new version: Bashly::VERSION,
9-
header: "Bashly - Bash CLI Generator",
9+
header: 'Bashly - Bash CLI Generator',
1010
footer: "Help: !txtpur!bashly COMMAND --help!txtrst!\nDocs: !undblu!https://bashly.dannyb.co"
1111

12-
runner.route "init", to: Commands::Init
13-
runner.route "preview", to: Commands::Preview
14-
runner.route "validate", to: Commands::Validate
15-
runner.route "generate", to: Commands::Generate
16-
runner.route "add", to: Commands::Add
12+
runner.route 'init', to: Commands::Init
13+
runner.route 'preview', to: Commands::Preview
14+
runner.route 'validate', to: Commands::Validate
15+
runner.route 'generate', to: Commands::Generate
16+
runner.route 'add', to: Commands::Add
1717

1818
runner
1919
end

0 commit comments

Comments
 (0)