Skip to content

Commit 42b996d

Browse files
committed
- Refactor with rubocop
1 parent 3c7331e commit 42b996d

26 files changed

+273
-266
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
strategy:
13-
matrix: { ruby: ['2.7', '3.0', '3.1'] }
13+
matrix: { ruby: ['2.7', '3.0', '3.1', head] }
1414

1515
steps:
1616
- name: Checkout code

.rubocop.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
inherit_gem:
2+
rentacop: rentacop.yml
3+
4+
AllCops:
5+
TargetRubyVersion: 2.7
6+
Exclude:
7+
- 'debug.rb'
8+
- 'dev/**/*'
9+
10+
# Allow `set_compline_vars` here, it is more readable
11+
Naming/AccessorMethodName:
12+
Exclude:
13+
- 'lib/completely/tester.rb'
14+
15+
# Allow long lines in specs and commands
16+
Layout/LineLength:
17+
Exclude:
18+
- 'spec/**/*'
19+
- 'lib/completely/commands/**/*'

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

33
gem 'byebug'
44
gem 'lp'
5+
gem 'rentacop'
56
gem 'rspec'
67
gem 'rspec_approvals'
78
gem 'runfile'

bin/completely

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ runner = Completely::CLI.runner
88

99
begin
1010
exit runner.run ARGV
11-
1211
rescue => e
1312
puts e.backtrace.reverse if ENV['DEBUG']
1413
say! "!undred!#{e.class}!txtrst!\n#{e.message}"
1514
exit 1
16-
end
15+
end

bin/console

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

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

77
include Completely
88

9-
IRB.start
9+
IRB.start

completely.gemspec

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path('lib', __dir__)
22
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3-
require 'date'
43
require 'completely/version'
54

65
Gem::Specification.new do |s|
76
s.name = 'completely'
87
s.version = Completely::VERSION
9-
s.date = Date.today.to_s
10-
s.summary = "Bash Completions Generator"
11-
s.description = "Generate bash completion scripts using simple YAML configuration"
12-
s.authors = ["Danny Ben Shitrit"]
8+
s.summary = 'Bash Completions Generator'
9+
s.description = 'Generate bash completion scripts using simple YAML configuration'
10+
s.authors = ['Danny Ben Shitrit']
1311
s.email = 'db@dannyben.com'
1412
s.files = Dir['README.md', 'lib/**/*.*']
1513
s.executables = ['completely']
1614
s.homepage = 'https://github.com/dannyben/completely'
1715
s.license = 'MIT'
18-
s.required_ruby_version = ">= 2.7.0"
16+
s.required_ruby_version = '>= 2.7.0'
1917

2018
s.add_runtime_dependency 'colsole', '~> 0.6'
2119
s.add_runtime_dependency 'mister_bin', '~> 0.7'
20+
21+
s.metadata['rubygems_mfa_required'] = 'true'
2222
end

lib/completely/cli.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module Completely
99
class CLI
1010
def self.runner
1111
runner = MisterBin::Runner.new version: Completely::VERSION,
12-
header: "Completely - Bash Completions Generator",
13-
footer: "Run !txtpur!completely COMMAND --help!txtrst! for more information"
12+
header: 'Completely - Bash Completions Generator',
13+
footer: 'Run !txtpur!completely COMMAND --help!txtrst! for more information'
1414

1515
runner.route 'init', to: Commands::Init
1616
runner.route 'preview', to: Commands::Preview

lib/completely/commands/base.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
module Completely
44
module Commands
55
class Base < MisterBin::Command
6-
76
class << self
87
def param_config_path
9-
param "CONFIG_PATH", "Path to the YAML configuration file [default: completely.yaml]\nCan also be set by an environment variable"
8+
param 'CONFIG_PATH', "Path to the YAML configuration file [default: completely.yaml]\nCan also be set by an environment variable"
109
end
1110

1211
def option_function
13-
option "-f --function NAME", "Modify the name of the function in the generated script"
12+
option '-f --function NAME', 'Modify the name of the function in the generated script'
1413
end
1514

1615
def environment_config_path
17-
environment "COMPLETELY_CONFIG_PATH", "Path to a completely configuration file [default: completely.yaml]"
16+
environment 'COMPLETELY_CONFIG_PATH', 'Path to a completely configuration file [default: completely.yaml]'
1817
end
1918

2019
def environment_debug
21-
environment "COMPLETELY_DEBUG", "It not empty, the generated script will include an additional debugging snippet that outputs the compline and current word to a text file when a completion is requested"
20+
environment 'COMPLETELY_DEBUG', 'It not empty, the generated script will include an additional debugging snippet that outputs the compline and current word to a text file when a completion is requested'
2221
end
2322
end
2423

@@ -46,7 +45,7 @@ def config_basename
4645

4746
def syntax_warning
4847
say! "\n!txtred!WARNING:\nYour configuration is invalid."
49-
say! "!txtred!All patterns must start with the same word."
48+
say! '!txtred!All patterns must start with the same word.'
5049
end
5150
end
5251
end

lib/completely/commands/generate.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
module Completely
44
module Commands
55
class Generate < Base
6-
help "Generate the bash completion script to a file"
6+
help 'Generate the bash completion script to a file'
77

8-
usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]"
9-
usage "completely generate (-h|--help)"
8+
usage 'completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]'
9+
usage 'completely generate (-h|--help)'
1010

1111
option_function
12-
option "-w --wrap NAME", "Wrap the completion script inside a function that echos the script. This is useful if you wish to embed it directly in your script"
12+
option '-w --wrap NAME', 'Wrap the completion script inside a function that echos the script. This is useful if you wish to embed it directly in your script'
1313

1414
param_config_path
15-
param "OUTPUT_PATH", "Path to the output bash script. When not provided, the name of the input file will be used with a .bash extension\nCan also be set by an environment variable"
15+
param 'OUTPUT_PATH', "Path to the output bash script. When not provided, the name of the input file will be used with a .bash extension\nCan also be set by an environment variable"
1616

1717
environment_config_path
18-
environment "COMPLETELY_OUTPUT_PATH", "Path to the output bash script"
18+
environment 'COMPLETELY_OUTPUT_PATH', 'Path to the output bash script'
1919
environment_debug
2020

2121
def run
@@ -31,7 +31,6 @@ def run
3131
def wrapper_function(wrapper_name)
3232
completions.wrapper_function wrapper_name
3333
end
34-
3534
end
3635
end
3736
end

lib/completely/commands/init.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
module Completely
44
module Commands
55
class Init < Base
6-
help "Create a new sample YAML configuration file"
6+
help 'Create a new sample YAML configuration file'
77

8-
usage "completely init [CONFIG_PATH]"
9-
usage "completely init (-h|--help)"
8+
usage 'completely init [CONFIG_PATH]'
9+
usage 'completely init (-h|--help)'
1010

1111
param_config_path
1212
environment_config_path
1313

1414
def run
15-
if File.exist? config_path
16-
raise "File already exists: #{config_path}"
17-
else
18-
File.write config_path, sample
19-
say "Saved !txtpur!#{config_path}"
20-
end
15+
raise "File already exists: #{config_path}" if File.exist? config_path
16+
17+
File.write config_path, sample
18+
say "Saved !txtpur!#{config_path}"
2119
end
2220

2321
private
@@ -27,9 +25,8 @@ def sample
2725
end
2826

2927
def sample_path
30-
@sample_path ||= File.expand_path "../templates/sample.yaml", __dir__
28+
@sample_path ||= File.expand_path '../templates/sample.yaml', __dir__
3129
end
32-
3330
end
3431
end
3532
end

0 commit comments

Comments
 (0)