Skip to content

Commit c781696

Browse files
authored
Fix various RuboCop todos offences (#2231)
1 parent f515a3b commit c781696

File tree

20 files changed

+44
-156
lines changed

20 files changed

+44
-156
lines changed

.rubocop.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ Lint/AmbiguousOperatorPrecedence:
5757
Naming/BlockForwarding:
5858
Enabled: false
5959

60+
Naming/PredicateMethod:
61+
Enabled: false
62+
6063
Performance/RegexpMatch:
6164
Enabled: false
6265

6366
Performance/ConstantRegexp:
6467
Enabled: false
68+
69+
Performance/UnfreezeString:
70+
Enabled: false

.rubocop_todo.yml

Lines changed: 3 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2026-02-13 03:44:28 UTC using RuboCop version 1.84.2.
3+
# on 2026-02-26 22:49:47 UTC using RuboCop version 1.85.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -20,12 +20,6 @@ Lint/ConstantDefinitionInBlock:
2020
Lint/DuplicateBranch:
2121
Enabled: false
2222

23-
# Offense count: 41
24-
# This cop supports safe autocorrection (--autocorrect).
25-
Lint/DuplicateSetElement:
26-
Exclude:
27-
- 'lib/rouge/lexers/glsl.rb'
28-
2923
# Offense count: 3
3024
# Configuration parameters: AllowComments, AllowEmptyLambdas.
3125
Lint/EmptyBlock:
@@ -51,21 +45,11 @@ Lint/OutOfRangeRegexpRef:
5145
Exclude:
5246
- 'lib/rouge/tex_theme_renderer.rb'
5347

54-
# Offense count: 1
55-
Lint/SharedMutableDefault:
56-
Exclude:
57-
- 'lib/rouge/lexers/j.rb'
58-
5948
# Offense count: 1
6049
Lint/ToEnumArguments:
6150
Exclude:
6251
- 'lib/rouge/lexer.rb'
6352

64-
# Offense count: 1
65-
Lint/UselessConstantScoping:
66-
Exclude:
67-
- 'lib/rouge/formatters/terminal256.rb'
68-
6953
# Offense count: 43
7054
Naming/ConstantName:
7155
Exclude:
@@ -110,17 +94,6 @@ Naming/MethodName:
11094
Naming/MethodParameterName:
11195
Enabled: false
11296

113-
# Offense count: 4
114-
# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
115-
# AllowedMethods: call
116-
# WaywardPredicates: infinite?, nonzero?
117-
Naming/PredicateMethod:
118-
Exclude:
119-
- 'lib/rouge/guessers/util.rb'
120-
- 'lib/rouge/lexers/javascript.rb'
121-
- 'lib/rouge/regex_lexer.rb'
122-
- 'spec/visual/app.rb'
123-
12497
# Offense count: 40
12598
# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns, ForbiddenIdentifiers, ForbiddenPatterns.
12699
# SupportedStyles: snake_case, camelCase
@@ -144,96 +117,10 @@ Naming/VariableNumber:
144117

145118
# Offense count: 2
146119
# This cop supports unsafe autocorrection (--autocorrect-all).
147-
Performance/MapCompact:
148-
Exclude:
149-
- 'lib/rouge/guessers/glob_mapping.rb'
150-
- 'lib/rouge/guessers/modeline.rb'
151-
152-
# Offense count: 1
153-
Performance/MapMethodChain:
154-
Exclude:
155-
- 'lib/rouge/regex_lexer.rb'
156-
157-
# Offense count: 7
158-
Performance/MethodObjectAsBlock:
159-
Exclude:
160-
- 'lib/rouge/cli.rb'
161-
- 'lib/rouge/formatters/tex.rb'
162-
- 'lib/rouge/lexers/console.rb'
163-
- 'spec/visual/app.rb'
164-
165-
# Offense count: 12
166-
# This cop supports unsafe autocorrection (--autocorrect-all).
167120
Performance/StringInclude:
168121
Exclude:
169-
- 'lib/rouge/cli.rb'
170122
- 'lib/rouge/lexers/hack.rb'
171-
- 'lib/rouge/lexers/igorpro.rb'
172-
- 'lib/rouge/lexers/lua.rb'
173-
- 'lib/rouge/lexers/moonscript.rb'
174-
- 'spec/formatters/html_pygments_spec.rb'
175-
- 'spec/lexers/escape_spec.rb'
176-
- 'spec/theme_spec.rb'
177123

178-
# Offense count: 5
179-
# This cop supports unsafe autocorrection (--autocorrect-all).
180-
Performance/UnfreezeString:
181-
Exclude:
182-
- 'lib/rouge/cli.rb'
183-
- 'lib/rouge/formatter.rb'
184-
- 'lib/rouge/formatters/terminal_truecolor.rb'
185-
- 'lib/rouge/tex_theme_renderer.rb'
186-
- 'spec/lexers_spec.rb'
187-
188-
# Offense count: 2
189-
# This cop supports safe autocorrection (--autocorrect).
190-
Rake/Desc:
191-
Exclude:
192-
- 'Rakefile'
193-
194-
# Offense count: 119
124+
# Offense count: 118
195125
Rouge/NoBuildingAlternationPatternInRegexp:
196-
Exclude:
197-
- 'lib/rouge/lexers/apple_script.rb'
198-
- 'lib/rouge/lexers/armasm.rb'
199-
- 'lib/rouge/lexers/bbcbasic.rb'
200-
- 'lib/rouge/lexers/bicep.rb'
201-
- 'lib/rouge/lexers/cfscript.rb'
202-
- 'lib/rouge/lexers/cmhg.rb'
203-
- 'lib/rouge/lexers/console.rb'
204-
- 'lib/rouge/lexers/crystal.rb'
205-
- 'lib/rouge/lexers/csharp.rb'
206-
- 'lib/rouge/lexers/d.rb'
207-
- 'lib/rouge/lexers/dart.rb'
208-
- 'lib/rouge/lexers/eiffel.rb'
209-
- 'lib/rouge/lexers/elm.rb'
210-
- 'lib/rouge/lexers/erlang.rb'
211-
- 'lib/rouge/lexers/haskell.rb'
212-
- 'lib/rouge/lexers/http.rb'
213-
- 'lib/rouge/lexers/idris.rb'
214-
- 'lib/rouge/lexers/idris.rb'
215-
- 'lib/rouge/lexers/isabelle.rb'
216-
- 'lib/rouge/lexers/java.rb'
217-
- 'lib/rouge/lexers/jsp.rb'
218-
- 'lib/rouge/lexers/kotlin.rb'
219-
- 'lib/rouge/lexers/lean.rb'
220-
- 'lib/rouge/lexers/magik.rb'
221-
- 'lib/rouge/lexers/make.rb'
222-
- 'lib/rouge/lexers/mason.rb'
223-
- 'lib/rouge/lexers/moonscript.rb'
224-
- 'lib/rouge/lexers/mosel.rb'
225-
- 'lib/rouge/lexers/nix.rb'
226-
- 'lib/rouge/lexers/p4.rb'
227-
- 'lib/rouge/lexers/pascal.rb'
228-
- 'lib/rouge/lexers/perl.rb'
229-
- 'lib/rouge/lexers/postscript.rb'
230-
- 'lib/rouge/lexers/python.rb'
231-
- 'lib/rouge/lexers/r.rb'
232-
- 'lib/rouge/lexers/ruby.rb'
233-
- 'lib/rouge/lexers/rust.rb'
234-
- 'lib/rouge/lexers/scala.rb'
235-
- 'lib/rouge/lexers/sml.rb'
236-
- 'lib/rouge/lexers/stata.rb'
237-
- 'lib/rouge/lexers/vala.rb'
238-
- 'lib/rouge/lexers/wollok.rb'
239-
- 'lib/rouge/lexers/xojo.rb'
126+
Enabled: false

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ task :test => [:check]
1616
task :build => [:clean, :check, "generate:docs"]
1717

1818
# Add utility tasks
19+
desc 'Add a newline'
1920
task :newline do
2021
puts
2122
end
@@ -29,6 +30,7 @@ end
2930
def alias_task(aliases)
3031
aliases.each do |alias_name,task_name|
3132
t = Rake::Task[task_name]
33+
desc "Add legacy alias #{alias_name} for modern #{task_name} task"
3234
task alias_name, *t.arg_names do |_, args|
3335
args = t.arg_names.map { |a| args[a] }
3436
t.invoke(args)

lib/rouge/cli.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def initialize(opts={})
159159
end
160160

161161
def run
162-
@mode.doc.each(&method(:puts))
162+
@mode.doc.each { |line| puts line }
163163
end
164164
end
165165

@@ -212,7 +212,7 @@ def self.doc
212212
# and we provide explicit opt-in and opt-out with $COLORTERM
213213
def self.supports_truecolor?
214214
return true if %w(24bit truecolor).include?(ENV['COLORTERM'])
215-
return false if ENV['COLORTERM'] && ENV['COLORTERM'] =~ /256/
215+
return false if ENV['COLORTERM'] && ENV['COLORTERM'].include?('256')
216216

217217
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
218218
ENV['ConEmuANSI'] == 'ON' && !ENV['ANSICON']
@@ -344,7 +344,7 @@ def initialize(opts={})
344344

345345
def run
346346
Formatter.enable_escape! if @escape
347-
formatter.format(lexer.lex(input), &method(:print))
347+
formatter.format(lexer.lex(input)) { |piece| print piece }
348348
end
349349

350350
private_class_method def self.parse_cgi(str)
@@ -439,7 +439,7 @@ def initialize(opts)
439439
end
440440

441441
def run
442-
@theme.render(&method(:puts))
442+
@theme.render { |line| puts line }
443443
end
444444
end
445445

lib/rouge/formatters/terminal256.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module Formatters
77
class Terminal256 < Formatter
88
tag 'terminal256'
99

10+
# max distance between two colors, #000000 to #ffffff
11+
MAX_DISTANCE = 257 * 257 * 3
12+
1013
# @private
1114
attr_reader :theme
1215

@@ -138,9 +141,6 @@ def self.get_rgb(color)
138141
hexes.map { |h| h.to_i(16) }
139142
end
140143

141-
# max distance between two colors, #000000 to #ffffff
142-
MAX_DISTANCE = 257 * 257 * 3
143-
144144
def self.closest_color(r, g, b)
145145
@@colors_cache ||= {}
146146
key = (r << 16) + (g << 8) + b

lib/rouge/formatters/tex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Tex < Formatter
2828
"\t" => '{\tab}',
2929
}
3030

31-
ESCAPE_REGEX = /[#{ESCAPE.keys.map(&Regexp.method(:escape)).join}]/om
31+
ESCAPE_REGEX = /[#{ESCAPE.keys.map { |k| Regexp.escape(k) }.join}]/om
3232

3333
def initialize(opts={})
3434
@prefix = opts.fetch(:prefix) { 'RG' }

lib/rouge/guessers/disambiguation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def match?(filename)
9090
disambiguate '*.m' do
9191
next ObjectiveC if matches?(/@(end|implementation|protocol|property)\b/)
9292
next ObjectiveC if contains?('@"')
93-
93+
9494
# Objective-C dereferenced pointers and Mathematica comments are similar.
9595
# Disambiguate for Mathematica by looking for any amount of whitespace (or no whitespace)
9696
# followed by "(*" (e.g. `(* comment *)`).
@@ -107,7 +107,7 @@ def match?(filename)
107107
next Matlab if matches?(/^\s*?%/)
108108
# Matlab cell array creation: data = {
109109
next Matlab if matches?(/^\s*[a-zA-Z]\w*\s*=\s*\{/)
110-
110+
111111
next Mason if matches? %r!(</?%|<&)!
112112
end
113113

lib/rouge/guessers/glob_mapping.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def filter(lexers)
3232
basename = File.basename(filename)
3333

3434
collect_best(lexers) do |lexer|
35-
(@glob_map[lexer.name] || []).map do |pattern|
35+
(@glob_map[lexer.name] || []).filter_map do |pattern|
3636
if test_glob(pattern, basename)
3737
# specificity is better the fewer wildcards there are
3838
-pattern.scan(/[*?\[]/).size
3939
end
40-
end.compact.min
40+
end.min
4141
end
4242
end
4343
end

lib/rouge/guessers/modeline.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def filter(lexers)
3535

3636
search_space = (lines.first(@lines) + lines.last(@lines)).join("\n")
3737

38-
matches = MODELINES.map { |re| re.match(search_space) }.compact
38+
matches = MODELINES.filter_map { |re| re.match(search_space) }
3939
return lexers unless matches.any?
4040

4141
match_set = Set.new(matches.map { |m| m[1] })

lib/rouge/lexers/console.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def end_chars
8585

8686
def error_regex
8787
@error_regex ||= if @error.any?
88-
/^(?:#{@error.map(&Regexp.method(:escape)).join('|')})/
88+
/^(?:#{@error.map { |e| Regexp.escape(e) }.join('|')})/
8989
end
9090
end
9191

@@ -174,7 +174,7 @@ def prompt_prefix_regex
174174

175175
def prompt_regex
176176
@prompt_regex ||= begin
177-
/^#{prompt_prefix_regex}(?:#{end_chars.map(&Regexp.method(:escape)).join('|')})/
177+
/^#{prompt_prefix_regex}(?:#{end_chars.map { |c| Regexp.escape(c) }.join('|')})/
178178
end
179179
end
180180

0 commit comments

Comments
 (0)