Skip to content

Commit f21cdf6

Browse files
committed
- Refactor with rubocop
1 parent c18aaae commit f21cdf6

41 files changed

Lines changed: 479 additions & 456 deletions

Some content is hidden

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

.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.6', '2.7', '3.0', '3.1'] }
13+
matrix: { ruby: ['2.6', '2.7', '3.0', '3.1', head] }
1414

1515
steps:
1616
- name: Checkout code

.rubocop.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
inherit_gem:
2+
rentacop: rentacop.yml
3+
4+
AllCops:
5+
TargetRubyVersion: 2.6
6+
SuggestExtensions: false
7+
8+
# We allow `$stderr.puts` in a command line
9+
Style/StderrPuts:
10+
Exclude:
11+
- 'lib/madness/command_line.rb'
12+
13+
# FIXME: These files have some complexities
14+
Metrics/PerceivedComplexity:
15+
Exclude:
16+
- lib/madness/command_line.rb
17+
18+
# FIXME: These files have some complexities
19+
Metrics/CyclomaticComplexity:
20+
Exclude:
21+
- lib/madness/command_line.rb
22+
23+
# FIXME: These files have some complexities
24+
Metrics/AbcSize:
25+
Exclude:
26+
- lib/madness/command_line.rb
27+
28+
# FIXME: The `set_config` method needs to be renamed without conflicting
29+
# with `config`
30+
Naming/AccessorMethodName:
31+
Exclude:
32+
- lib/madness/command_line.rb

Gemfile

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
group :development do
3+
# gem 'jekyll'
44

5-
# gem 'jekyll'
5+
# This gem is for local GitHub pages development, but it conflicts with
6+
# CmomonMarker (it requires a lower version than we need)
7+
# gem 'github-pages', group: :jekyll_plugins
68

7-
# This gem is for local GitHub pages development, but it conflicts with
8-
# CmomonMarker (it requires a lower version than we need)
9-
# gem 'github-pages', group: :jekyll_plugins
10-
11-
gem 'byebug'
12-
gem 'lp'
13-
gem 'rack-test'
14-
gem 'rdoc'
15-
gem 'rspec'
16-
gem 'rspec-html-matchers'
17-
gem 'rspec_approvals'
18-
gem 'runfile'
19-
gem 'runfile-tasks'
20-
gem 'sasstool'
21-
gem 'simplecov'
22-
gem 'yard'
23-
24-
end
9+
gem 'byebug'
10+
gem 'lp'
11+
gem 'rack-test'
12+
gem 'rdoc'
13+
gem 'rentacop'
14+
gem 'rspec'
15+
gem 'rspec_approvals'
16+
gem 'rspec-html-matchers'
17+
gem 'runfile'
18+
gem 'runfile-tasks'
19+
gem 'sasstool'
20+
gem 'simplecov'
21+
gem 'yard'
2522

2623
gemspec

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" # easy tab completion
5-
require "madness"
3+
require 'irb'
4+
require 'irb/completion' # easy tab completion
5+
require 'madness'
66

77
include Madness
88

9-
IRB.start
9+
IRB.start

bin/madness

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ rescue => e
1010
puts e.backtrace.reverse if ENV['DEBUG']
1111
say! "!undred!#{e.class}!txtrst!\n#{e.message}"
1212
exit 1
13-
end
13+
end

lib/madness.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
require 'requires'
77

88
requires 'madness/refinements', 'madness/server_helper', 'madness'
9-

lib/madness/breadcrumbs.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
module Madness
2-
32
# Handle breadcumbs generation by converting a path to an array
43
# of links
54
class Breadcrumbs
65
using StringRefinements
7-
6+
87
attr_reader :path
98

109
def initialize(path)
1110
@path = path
1211
end
1312

1413
def links
15-
path == "" ? [] : get_breadcrumbs
14+
path == '' ? [] : breadcrumbs
1615
end
1716

1817
private
1918

20-
def get_breadcrumbs
21-
home = OpenStruct.new({ label: "Home", href: '/' })
19+
def breadcrumbs
20+
home = OpenStruct.new({ label: 'Home', href: '/' })
2221
result = breadcrumbs_maker(path).reverse.unshift home
2322
result.last.last = true
2423
result
2524
end
2625

2726
def breadcrumbs_maker(partial_path)
2827
parent, basename = File.split partial_path
29-
item = OpenStruct.new({
30-
label: basename.to_label,
31-
href: "/#{partial_path}" }
28+
item = OpenStruct.new(
29+
{
30+
label: basename.to_label,
31+
href: "/#{partial_path}",
32+
}
3233
)
3334
result = [item]
3435
result += breadcrumbs_maker parent unless parent == '.'

lib/madness/browser.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class Browser
77
attr_reader :host, :port
88

99
def initialize(host, port)
10-
@host, @port = host, port
10+
@host = host
11+
@port = port
1112
end
1213

1314
# Returns a URL based on host, port and MADNESS_FORCE_SSL.
@@ -51,7 +52,7 @@ def open
5152

5253
# Runs the appropriate command (based on OS) to open a browser.
5354
def open!
54-
system *open_command, err: File::NULL, in: File::NULL, out: File::NULL
55+
system(*open_command, err: File::NULL, in: File::NULL, out: File::NULL)
5556
end
5657

5758
# Returns the appropriate command (based on OS) to open a browser.

lib/madness/command_line.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
require 'docopt'
55

66
module Madness
7-
87
# Handle command line execution. Used by bin/madness.
98
class CommandLine
109
include Singleton
1110
include Colsole
1211

1312
# Process ARGV by putting it through docopt
14-
def execute(argv=[])
13+
def execute(argv = [])
1514
doc = File.read File.expand_path('docopt.txt', __dir__)
16-
15+
1716
begin
1817
args = Docopt.docopt(doc, argv: argv, version: VERSION)
1918
handle args
@@ -49,7 +48,7 @@ def launch_server_with_options(args)
4948
# and static files folder.
5049
def launch_server
5150
unless File.directory? config.path
52-
STDERR.puts "Invalid path (#{config.path})"
51+
$stderr.puts "Invalid path (#{config.path})"
5352
return
5453
end
5554

@@ -61,7 +60,7 @@ def launch_server
6160
# Get the arguments as provided by docopt, and set them to our own
6261
# config object.
6362
def set_config(args)
64-
config.path = args['PATH'] if args['PATH']
63+
config.path = args['PATH'] if args['PATH']
6564
config.port = args['--port'].to_i if args['--port']
6665
config.bind = args['--bind'] if args['--bind']
6766
config.toc = args['--toc'] if args['--toc']
@@ -76,7 +75,7 @@ def set_config(args)
7675
config.copy_code = false if args['--no-copy-code']
7776
config.shortlinks = true if args['--shortlinks']
7877
config.open = true if args['--open']
79-
78+
8079
config.theme = File.expand_path(args['--theme'], config.path) if args['--theme']
8180
end
8281

@@ -105,7 +104,7 @@ def create_theme(path)
105104
end
106105
end
107106

108-
# Say hello to everybody when the server starts, showing the known
107+
# Say hello to everybody when the server starts, showing the known
109108
# config.
110109
def show_status
111110
say_status :start, 'the madness'
@@ -115,7 +114,7 @@ def show_status
115114
say_status :use, config.filename if config.file_exist?
116115
say_status :theme, config.theme, :txtblu if config.theme
117116

118-
say "-" * 60
117+
say '-' * 60
119118
end
120119

121120
# Generate the table of contents file

lib/madness/directory.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Directory
99
def initialize(dir)
1010
@dir = dir
1111
end
12-
12+
1313
def list
1414
@list ||= (dirs + files)
1515
end
@@ -18,9 +18,8 @@ def list
1818

1919
def files
2020
result = Dir["#{dir}/#{config.dir_glob}"]
21-
result.reject! do |f|
22-
basename = File.basename(f)
23-
basename == 'README.md' or basename == 'index.md'
21+
result.reject! do |f|
22+
['README.md', 'index.md'].include? File.basename(f)
2423
end
2524
result.nat_sort.map { |path| Item.new path, :file }
2625
end
@@ -33,6 +32,7 @@ def dirs
3332

3433
def exclude?(path)
3534
return false unless config.exclude.is_a? Array
35+
3636
basename = File.basename path
3737
config.exclude.each do |pattern|
3838
return true if basename =~ Regexp.new(pattern)
@@ -43,6 +43,5 @@ def exclude?(path)
4343
def config
4444
@config ||= Settings.instance
4545
end
46-
4746
end
4847
end

0 commit comments

Comments
 (0)