Skip to content

Commit f15f34d

Browse files
jneenjneen
andauthored
Add Rubocop rule to catch arrays of size > 300. Also fix a bunch of .rubocop_todo.yml (#2256)
* Add no-huge-arrays rule to fail on array or set literals over 300 * fix constant lookup in dynamically defined class --------- Co-authored-by: jneen <[email protected]>
1 parent 08f83ba commit f15f34d

File tree

12 files changed

+182
-263
lines changed

12 files changed

+182
-263
lines changed

.rubocop.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ inherit_from: .rubocop_todo.yml
22

33
require:
44
- ./lib/rubocop/cop/rouge/no_building_alternation_pattern_in_regexp.rb
5+
- ./lib/rubocop/cop/rouge/no_huge_collections.rb
56

67
plugins:
78
- rubocop-performance
@@ -18,6 +19,9 @@ AllCops:
1819
- "lib/rouge/lexers/**/builtins.rb"
1920
NewCops: enable
2021

22+
Rouge:
23+
Enabled: true
24+
2125
Style:
2226
Enabled: false
2327

@@ -76,12 +80,41 @@ Lint/IneffectiveAccessModifier:
7680
Lint/AmbiguousOperatorPrecedence:
7781
Enabled: false
7882

83+
# this just is plain broken, disabling
84+
Lint/OutOfRangeRegexpRef:
85+
Enabled: false
86+
87+
# there are actual reasons to do this
88+
Lint/MissingSuper:
89+
Enabled: false
90+
91+
# sometimes the arguments are deprecated you guys
92+
Lint/ToEnumArguments:
93+
Enabled: false
94+
95+
# sometimes we deal with very gnarly strings, this is not useful
96+
Lint/NestedPercentLiteral:
97+
Enabled: false
98+
99+
# usually not actionable
100+
Lint/DuplicateBranch:
101+
Enabled: false
102+
79103
Naming/BlockForwarding:
80104
Enabled: false
81105

82106
Naming/PredicateMethod:
83107
Enabled: false
84108

109+
Naming/MethodParameterName:
110+
Enabled: false
111+
112+
Naming/HeredocDelimiterNaming:
113+
Enabled: false
114+
115+
Naming/VariableNumber:
116+
Enabled: false
117+
85118
Performance/RegexpMatch:
86119
Enabled: false
87120

.rubocop_todo.yml

Lines changed: 24 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,23 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config --exclude-limit 50`
3-
# on 2026-02-27 15:13:26 UTC using RuboCop version 1.85.0.
3+
# on 2026-03-20 18:54:21 UTC using RuboCop version 1.84.2.
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
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 8
10-
# Configuration parameters: AllowedMethods.
11-
# AllowedMethods: enums
12-
Lint/ConstantDefinitionInBlock:
13-
Exclude:
14-
- 'spec/formatters/html_spec.rb'
15-
- 'spec/lexer_spec.rb'
16-
- 'spec/theme_spec.rb'
17-
18-
# Offense count: 38
19-
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
20-
Lint/DuplicateBranch:
21-
Exclude:
22-
- 'lib/rouge/cli.rb'
23-
- 'lib/rouge/lexers/apache.rb'
24-
- 'lib/rouge/lexers/apex.rb'
25-
- 'lib/rouge/lexers/batchfile.rb'
26-
- 'lib/rouge/lexers/brightscript.rb'
27-
- 'lib/rouge/lexers/common_lisp.rb'
28-
- 'lib/rouge/lexers/coq.rb'
29-
- 'lib/rouge/lexers/css.rb'
30-
- 'lib/rouge/lexers/cython.rb'
31-
- 'lib/rouge/lexers/ecl.rb'
32-
- 'lib/rouge/lexers/idlang.rb'
33-
- 'lib/rouge/lexers/llvm.rb'
34-
- 'lib/rouge/lexers/php.rb'
35-
- 'lib/rouge/lexers/python.rb'
36-
- 'lib/rouge/lexers/robot_framework.rb'
37-
- 'lib/rouge/lexers/ruby.rb'
38-
- 'lib/rouge/lexers/sas.rb'
39-
- 'lib/rouge/lexers/sqf.rb'
40-
- 'lib/rouge/lexers/stan.rb'
41-
- 'lib/rouge/lexers/varnish.rb'
42-
- 'lib/rouge/lexers/viml.rb'
43-
- 'lib/rouge/lexers/yang.rb'
44-
45-
# Offense count: 3
9+
# Offense count: 1
4610
# Configuration parameters: AllowComments, AllowEmptyLambdas.
4711
Lint/EmptyBlock:
4812
Exclude:
4913
- 'lib/rouge/lexers/nix.rb'
50-
- 'spec/lexers/terraform_spec.rb'
51-
52-
# Offense count: 27
53-
# Configuration parameters: AllowedParentClasses.
54-
Lint/MissingSuper:
55-
Exclude:
56-
- 'lib/rouge/cli.rb'
57-
- 'lib/rouge/formatters/html_inline.rb'
58-
- 'lib/rouge/formatters/html_legacy.rb'
59-
- 'lib/rouge/formatters/html_line_highlighter.rb'
60-
- 'lib/rouge/formatters/html_line_table.rb'
61-
- 'lib/rouge/formatters/html_linewise.rb'
62-
- 'lib/rouge/formatters/html_pygments.rb'
63-
- 'lib/rouge/formatters/html_table.rb'
64-
- 'lib/rouge/formatters/null.rb'
65-
- 'lib/rouge/formatters/terminal256.rb'
66-
- 'lib/rouge/formatters/tex.rb'
67-
- 'lib/rouge/guesser.rb'
68-
- 'lib/rouge/guessers/disambiguation.rb'
69-
- 'lib/rouge/guessers/filename.rb'
70-
- 'lib/rouge/guessers/glob_mapping.rb'
71-
- 'lib/rouge/guessers/mimetype.rb'
72-
- 'lib/rouge/guessers/modeline.rb'
73-
- 'lib/rouge/guessers/source.rb'
74-
- 'lib/rouge/regex_lexer.rb'
75-
- 'lib/rouge/theme.rb'
76-
- 'lib/rouge/util.rb'
7714

7815
# Offense count: 4
79-
Lint/NestedPercentLiteral:
80-
Exclude:
81-
- 'lib/rouge/lexers/hylang.rb'
82-
- 'lib/rouge/lexers/janet.rb'
83-
- 'lib/rouge/lexers/powershell.rb'
84-
- 'spec/lexers/j_spec.rb'
85-
86-
# Offense count: 1
87-
Lint/OutOfRangeRegexpRef:
88-
Exclude:
89-
- 'lib/rouge/tex_theme_renderer.rb'
90-
91-
# Offense count: 1
92-
Lint/ToEnumArguments:
93-
Exclude:
94-
- 'lib/rouge/lexer.rb'
95-
96-
# Offense count: 43
9716
Naming/ConstantName:
9817
Exclude:
9918
- 'lib/rouge/lexers/eiffel.rb'
100-
- 'lib/rouge/themes/gruvbox.rb'
101-
102-
# Offense count: 8
103-
# Configuration parameters: ForbiddenDelimiters.
104-
# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))
105-
Naming/HeredocDelimiterNaming:
106-
Exclude:
107-
- 'lib/rouge/tex_theme_renderer.rb'
108-
- 'spec/lexers/mason_spec.rb'
109-
- 'spec/lexers/matlab_spec.rb'
110-
- 'spec/lexers/swift_spec.rb'
11119

112-
# Offense count: 8
20+
# Offense count: 5
11321
# This cop supports unsafe autocorrection (--autocorrect-all).
11422
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
11523
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
@@ -120,7 +28,6 @@ Naming/MemoizedInstanceVariableName:
12028
- 'lib/rouge/lexers/hack.rb'
12129
- 'lib/rouge/lexers/python.rb'
12230
- 'lib/rouge/lexers/verilog.rb'
123-
- 'lib/rouge/lexers/yang.rb'
12431

12532
# Offense count: 16
12633
# Configuration parameters: EnforcedStyle, AllowedPatterns, ForbiddenIdentifiers, ForbiddenPatterns.
@@ -131,35 +38,6 @@ Naming/MethodName:
13138
- 'lib/rouge/lexers/igorpro.rb'
13239
- 'lib/rouge/lexers/xpath.rb'
13340

134-
# Offense count: 68
135-
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
136-
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
137-
Naming/MethodParameterName:
138-
Exclude:
139-
- 'lib/rouge.rb'
140-
- 'lib/rouge/cli.rb'
141-
- 'lib/rouge/formatter.rb'
142-
- 'lib/rouge/formatters/html.rb'
143-
- 'lib/rouge/formatters/html_legacy.rb'
144-
- 'lib/rouge/formatters/html_line_table.rb'
145-
- 'lib/rouge/formatters/html_linewise.rb'
146-
- 'lib/rouge/formatters/html_pygments.rb'
147-
- 'lib/rouge/formatters/html_table.rb'
148-
- 'lib/rouge/formatters/null.rb'
149-
- 'lib/rouge/formatters/terminal256.rb'
150-
- 'lib/rouge/formatters/tex.rb'
151-
- 'lib/rouge/guessers/disambiguation.rb'
152-
- 'lib/rouge/lexer.rb'
153-
- 'lib/rouge/lexers/coq.rb'
154-
- 'lib/rouge/lexers/escape.rb'
155-
- 'lib/rouge/lexers/plain_text.rb'
156-
- 'lib/rouge/regex_lexer.rb'
157-
- 'lib/rouge/tex_theme_renderer.rb'
158-
- 'lib/rouge/theme.rb'
159-
- 'lib/rouge/token.rb'
160-
- 'lib/rouge/util.rb'
161-
- 'spec/support/lexing.rb'
162-
16341
# Offense count: 40
16442
# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns, ForbiddenIdentifiers, ForbiddenPatterns.
16543
# SupportedStyles: snake_case, camelCase
@@ -172,15 +50,6 @@ Naming/VariableName:
17250
- 'lib/rouge/lexers/kotlin.rb'
17351
- 'lib/rouge/lexers/xpath.rb'
17452

175-
# Offense count: 5
176-
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
177-
# SupportedStyles: snake_case, normalcase, non_integer
178-
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
179-
Naming/VariableNumber:
180-
Exclude:
181-
- 'lib/rouge/lexers/c.rb'
182-
- 'lib/rouge/themes/gruvbox.rb'
183-
18453
# Offense count: 2
18554
# This cop supports unsafe autocorrection (--autocorrect-all).
18655
Performance/StringInclude:
@@ -230,3 +99,24 @@ Rouge/NoBuildingAlternationPatternInRegexp:
23099
- 'lib/rouge/lexers/vala.rb'
231100
- 'lib/rouge/lexers/wollok.rb'
232101
- 'lib/rouge/lexers/xojo.rb'
102+
103+
# Offense count: 20
104+
Rouge/NoHugeCollections:
105+
Exclude:
106+
- 'lib/rouge/lexers/abap.rb'
107+
- 'lib/rouge/lexers/apple_script.rb'
108+
- 'lib/rouge/lexers/cobol.rb'
109+
- 'lib/rouge/lexers/common_lisp.rb'
110+
- 'lib/rouge/lexers/css.rb'
111+
- 'lib/rouge/lexers/datastudio.rb'
112+
- 'lib/rouge/lexers/freefem.rb'
113+
- 'lib/rouge/lexers/hql.rb'
114+
- 'lib/rouge/lexers/idlang.rb'
115+
- 'lib/rouge/lexers/igorpro.rb'
116+
- 'lib/rouge/lexers/janet.rb'
117+
- 'lib/rouge/lexers/openedge.rb'
118+
- 'lib/rouge/lexers/plsql.rb'
119+
- 'lib/rouge/lexers/racket.rb'
120+
- 'lib/rouge/lexers/sas.rb'
121+
- 'lib/rouge/lexers/sql.rb'
122+
- 'lib/rouge/lexers/stata.rb'

lib/rouge/cli.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,7 @@ def run
514514
out = []
515515
argv.each do |arg|
516516
case arg
517-
when /^(--\w+)=(.*)$/
518-
out << $1 << $2
519-
when /^(-\w)(.+)$/
517+
when /^(--\w+)=(.*)$/, /^(-\w)(.+)$/
520518
out << $1 << $2
521519
else
522520
out << arg

lib/rouge/lexers/apache.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ class Apache < RegexLexer
1717
end
1818

1919
def name_for_token(token, tktype)
20-
if SECTIONS.include? token
21-
tktype
22-
elsif DIRECTIVES.include? token
23-
tktype
24-
elsif VALUES.include? token
25-
tktype
26-
else
27-
Text
28-
end
20+
return tktype if SECTIONS.include?(token)
21+
return tktype if DIRECTIVES.include?(token)
22+
return tktype if VALUES.include?(token)
23+
24+
Text
2925
end
3026

3127
state :whitespace do

lib/rouge/lexers/viml.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class VimL < RegexLexer
4949

5050
if KEYWORDS[:command].include? name
5151
token Keyword
52-
elsif KEYWORDS[:function].include? name
53-
token Name::Builtin
54-
elsif KEYWORDS[:option].include? name
55-
token Name::Builtin
56-
elsif KEYWORDS[:auto].include? name
52+
elsif (
53+
KEYWORDS[:function].include?(name) ||
54+
KEYWORDS[:option].include?(name) ||
55+
KEYWORDS[:auto].include?(name)
56+
)
5757
token Name::Builtin
5858
else
5959
token Text

0 commit comments

Comments
 (0)