Skip to content

Commit 58554c0

Browse files
committed
Update rubocop config
1 parent 67a43b0 commit 58554c0

File tree

269 files changed

+1901
-2042
lines changed

Some content is hidden

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

269 files changed

+1901
-2042
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
with:
2323
ruby-version: ${{ matrix.ruby }}
2424
bundler-cache: true
25+
- name: Lint
26+
run: bundle exec rubocop
2527
- name: Run Test
2628
run: |
2729
ruby -v

.rubocop.yml

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
#inherit_from:
2-
# - .rubocop_todo.yml
3-
1+
plugins:
2+
- rubocop-rake
3+
- rubocop-performance
4+
AllCops:
5+
TargetRubyVersion: 2.0
6+
SuggestExtensions: false
7+
NewCops: enable
8+
Exclude:
9+
- lib/yard/parser/ruby/legacy/irb/slex.rb
10+
- lib/yard/parser/ruby/legacy/ruby_lex.rb
11+
- lib/yard/server/http_utils.rb
412
Metrics:
513
Enabled: false
14+
Performance:
15+
Exclude:
16+
- spec/**/*.rb
17+
Gemspec/RequireMFA:
18+
Enabled: false
619
Layout/LineLength:
720
AutoCorrect: true
8-
Max: 100
21+
Max: 120
22+
Exclude:
23+
- spec/**/*.rb
24+
Naming/MethodParameterName:
25+
Enabled: false
26+
Layout/EmptyLineAfterMagicComment:
27+
Enabled: false
28+
Layout/EmptyLineAfterGuardClause:
29+
Enabled: false
930
Style/Semicolon:
1031
AllowAsExpressionSeparator: true
1132
Style/Documentation:
@@ -30,19 +51,57 @@ Layout/FirstArrayElementIndentation:
3051
EnforcedStyle: consistent
3152
Layout/FirstHashElementIndentation:
3253
EnforcedStyle: consistent
33-
34-
# Disable these until we know what to do with them
3554
Style/SafeNavigation:
3655
Enabled: false # not supported in 1.8...2.1
56+
Style/DocumentDynamicEvalDefinition: # not helpful
57+
Enabled: false
58+
Style/OpenStructUse:
59+
Enabled: false
60+
Style/MixinUsage:
61+
Exclude:
62+
- docs/**/*.rb
63+
- benchmarks/**/*.rb
64+
- spec/**/*
65+
- templates/**/*
66+
- lib/yard/templates/**/*
67+
Style/PercentLiteralDelimiters:
68+
PreferredDelimiters:
69+
"%w": "()"
70+
"%W": "()"
71+
"%i": "()"
72+
"%I": "()"
73+
Style/MultilineIfModifier: # autocorrect usually fails
74+
Enabled: false
75+
Style/OptionalBooleanParameter:
76+
Enabled: false
3777
Style/GuardClause: # does not provide much value
3878
Enabled: false
79+
Style/IfWithBooleanLiteralBranches: # this isn't reliable
80+
Enabled: false
81+
Lint/DuplicateMethods:
82+
Enabled: false
83+
Lint/ConstantDefinitionInBlock:
84+
Exclude:
85+
- benchmarks/**/*.rb
86+
- docs/**/*.rb
87+
- spec/**/*.rb
88+
Style/FormatStringToken:
89+
Enabled: false
90+
Lint/UselessConstantScoping:
91+
Enabled: false
92+
Lint/SuppressedException:
93+
Enabled: false
94+
Bundler/GemFilename:
95+
Enabled: false
3996
Naming/VariableNumber:
4097
Enabled: false
4198
Naming/AccessorMethodName: # this creates breaking changes in the API
4299
Enabled: false
43100
Naming/PredicateName: # this creates breaking changes in the API
44101
Enabled: false
45-
Style/MethodMissingSuper: # this doesn't exist in 1.8/1.9
102+
Naming/HeredocDelimiterNaming:
103+
Enabled: false
104+
Lint/MissingSuper: # this doesn't exist in 1.8/1.9
46105
Enabled: false
47106
Style/MissingRespondToMissing: # this doesn't exist in 1.8/1.9
48107
Enabled: false
@@ -62,6 +121,10 @@ Style/ClassAndModuleChildren:
62121
Enabled: false
63122
Layout/EmptyLineBetweenDefs:
64123
AllowAdjacentOneLineDefs: true
124+
Layout/EmptyLinesAroundAttributeAccessor:
125+
Enabled: false
126+
Style/EvalWithLocation:
127+
Enabled: false
65128
Style/SingleLineMethods:
66129
Enabled: false
67130
Style/SingleLineBlockParams:
@@ -89,13 +152,20 @@ Style/GlobalVars:
89152
Exclude:
90153
- benchmarks/**/*.rb
91154
- spec/**/*.rb
155+
Style/StderrPuts:
156+
Enabled: false
157+
Style/FileWrite:
158+
Enabled: false
159+
Style/FileRead:
160+
Enabled: false
92161
Lint/RedundantSplatExpansion:
93162
Enabled: false
94163
Security/Eval:
95164
Exclude:
96165
- benchmarks/**/*.rb
97166
- spec/**/*.rb
98-
167+
Security/MarshalLoad:
168+
Enabled: false
99169
Layout/SpaceAroundMethodCallOperator:
100170
Enabled: false
101171
Lint/RaiseException:

Gemfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@
22
source 'https://rubygems.org'
33

44
group :development do
5-
gem 'rspec', '>= 3.11.0'
5+
gem 'coveralls_reborn', :require => false
6+
gem 'json'
67
gem 'rake'
78
gem 'rdoc', '= 6.1.2.1'
8-
gem 'json'
9-
gem 'simplecov'
9+
gem 'rspec', '>= 3.11.0'
1010
gem 'samus', '~> 3.0.9', :require => false
11-
gem 'coveralls_reborn', :require => false
11+
gem 'simplecov'
1212
gem 'webrick'
1313
end
1414

15+
group :lint do
16+
gem 'rubocop'
17+
gem 'rubocop-performance'
18+
gem 'rubocop-rake'
19+
end
20+
1521
group :asciidoc do
1622
gem 'asciidoctor'
23+
gem 'logger' # needed for asciidoctor
1724
end
1825

1926
group :markdown do
27+
gem 'commonmarker', '~> 0.x'
2028
gem 'redcarpet'
21-
gem 'commonmarker'
2229
end
2330

2431
group :textile do

Rakefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# frozen_string_literal: true
2-
require File.dirname(__FILE__) + '/lib/yard'
3-
require File.dirname(__FILE__) + '/lib/yard/rubygems/specification'
2+
require "#{File.dirname(__FILE__)}/lib/yard"
3+
require "#{File.dirname(__FILE__)}/lib/yard/rubygems/specification"
44
require 'rbconfig'
55

66
YARD::VERSION.replace(ENV['YARD_VERSION']) if ENV['YARD_VERSION']
77

8-
Dir['tasks/**/*.rake'].each { |task_file| load task_file }
8+
Dir['tasks/**/*.rake'].each {|task_file| load task_file }
99

1010
desc "Builds the gem"
1111
task :gem do
@@ -29,7 +29,7 @@ task :test_doc do
2929
sh "ruby bin/yard --fail-on-warning #{"--no-progress" if ENV["CI"]}"
3030
end
3131

32-
task :default => [:spec, :test_doc]
32+
task :default => %i(spec test_doc)
3333

3434
YARD::Rake::YardocTask.new do |t|
3535
t.options += ['--title', "YARD #{YARD::VERSION} Documentation"]

benchmarks/builtins_vs_eval.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def bench_builtins(name)
1010

1111
def bench_eval(name)
1212
eval(name).is_a?(Class)
13-
rescue
13+
rescue StandardError
1414
false
1515
end
1616

benchmarks/erb_vs_erubis.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,41 @@ def rungen
1313

1414
Benchmark.bmbm do |x|
1515
x.report("erubis") do
16-
eval <<-eof
16+
eval <<-EOF
1717
module YARD; module Templates; module Template
1818
def erb_with(str, x) Erubis::Eruby.new(str) end
1919
end end end
20-
eof
20+
EOF
2121

2222
rungen
2323
end
2424

2525
x.report("fast-erubis") do
26-
eval <<-eof
26+
eval <<-EOF
2727
module YARD; module Templates; module Template
2828
def erb_with(str, x) Erubis::FastEruby.new(str) end
2929
end end end
30-
eof
30+
EOF
3131

3232
rungen
3333
end
3434

3535
x.report("tiny-erubis") do
36-
eval <<-eof
36+
eval <<-EOF
3737
module YARD; module Templates; module Template
3838
def erb_with(str, x) Erubis::TinyEruby.new(str) end
3939
end end end
40-
eof
40+
EOF
4141

4242
rungen
4343
end
4444

4545
x.report("erb") do
46-
eval <<-eof
46+
eval <<-EOF
4747
module YARD; module Templates; module Template
4848
def erb_with(str, x) ERB.new(str) end
4949
end end end
50-
eof
50+
EOF
5151

5252
rungen
5353
end

benchmarks/format_args.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ def format_args_regex(object)
1111
end
1212

1313
def format_args_parameters(object)
14-
if !object.parameters.empty?
14+
if object.parameters.empty?
15+
""
16+
else
1517
args = object.parameters.map {|n, v| v ? "#{n} = #{v}" : n.to_s }.join(", ")
1618
"(#{args})"
17-
else
18-
""
1919
end
2020
end
2121

2222
YARD::Registry.load
2323
$object = YARD::Registry.at('YARD::Generators::Base#G')
2424

25-
log.puts "regex: " + format_args_regex($object)
26-
log.puts "params: " + format_args_parameters($object)
25+
log.puts "regex: #{format_args_regex($object)}"
26+
log.puts "params: #{format_args_parameters($object)}"
2727
log.puts
2828

2929
TIMES = 100_000

benchmarks/generation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ def rungen
1212
end
1313

1414
def redef(lock = false)
15-
eval <<-eof
15+
eval <<-EOF
1616
class YARD::CodeObjects::Proxy;
1717
def to_obj
1818
@obj #{lock ? '||' : ''}= YARD::Registry.resolve(@namespace, @name)
1919
end
2020
end
21-
eof
21+
EOF
2222
end
2323

2424
Benchmark.bmbm do |x|

benchmarks/marshal_vs_dbm.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22
require 'benchmark'
33
require 'dbm'
4+
require 'fileutils'
45

56
MARSHAL_FILE = "marshal_test.db"
67
DBM_FILE = "dbm_test"
@@ -14,7 +15,7 @@ def generate_index
1415
end
1516

1617
def write_dbm
17-
File.unlink(DBM_FILE + ".db") if File.exist?(DBM_FILE + ".db")
18+
FileUtils.rm_f("#{DBM_FILE}.db")
1819
handle = DBM.new(DBM_FILE)
1920
NUM_INDICES.times {|t| handle[t.to_s] = Marshal.dump(generate_index) }
2021
handle.close
@@ -27,7 +28,7 @@ def read_dbm
2728
end
2829

2930
def write_marshal
30-
File.unlink(MARSHAL_FILE) if File.exist?(MARSHAL_FILE)
31+
FileUtils.rm_f(MARSHAL_FILE)
3132
handle = {}
3233
NUM_INDICES.times {|t| handle[t.to_s] = generate_index }
3334
File.open(MARSHAL_FILE, "wb") {|f| f.write(Marshal.dump(handle)) }
@@ -46,7 +47,7 @@ def read_marshal
4647
end
4748

4849
File.unlink(MARSHAL_FILE)
49-
File.unlink(DBM_FILE + ".db")
50+
File.unlink("#{DBM_FILE}.db")
5051

5152
__END__
5253

benchmarks/pathname_vs_string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
require 'pathname'
33
require "benchmark"
4-
require File.dirname(__FILE__) + '/../lib/yard'
4+
require "#{File.dirname(__FILE__)}/../lib/yard"
55

66
pathobj = Pathname.new("a/b/c")
77
strobj = "a/b/c"

0 commit comments

Comments
 (0)