-
Notifications
You must be signed in to change notification settings - Fork 745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce Ruby warnings #1197
Reduce Ruby warnings #1197
Conversation
I overlooked #1189 , that solves the same problem. Thank you. |
I found warnings that are not solved by #1189 but solved by #1197. diff --git a/lib/rouge/guessers/glob_mapping.rb b/lib/rouge/guessers/glob_mapping.rb
index f635328..615ac2b 100644
--- a/lib/rouge/guessers/glob_mapping.rb
+++ b/lib/rouge/guessers/glob_mapping.rb
@@ -32,7 +32,7 @@ module Rouge
basename = File.basename(filename)
collect_best(lexers) do |lexer|
- score = (@glob_map[lexer.name] || []).map do |pattern|
+ (@glob_map[lexer.name] || []).map do |pattern|
if test_glob(pattern, basename)
# specificity is better the fewer wildcards there are
-pattern.scan(/[*?\[]/).size
diff --git a/lib/rouge/lexers/apple_script.rb b/lib/rouge/lexers/apple_script.rb
index 5e44a63..22a4ba6 100644
--- a/lib/rouge/lexers/apple_script.rb
+++ b/lib/rouge/lexers/apple_script.rb
@@ -305,7 +305,6 @@ module Rouge
operators = %r(\b(#{self.operators.to_a.join('|')})\b)
classes = %r(\b(as )(#{self.classes.to_a.join('|')})\b)
- literals = %r(\b(#{self.literals.to_a.join('|')})\b)
commands = %r(\b(#{self.commands.to_a.join('|')})\b)
controls = %r(\b(#{self.controls.to_a.join('|')})\b)
declarations = %r(\b(#{self.declarations.to_a.join('|')})\b)
diff --git a/lib/rouge/lexers/ceylon.rb b/lib/rouge/lexers/ceylon.rb
index dab6bba..d5c9347 100644
--- a/lib/rouge/lexers/ceylon.rb
+++ b/lib/rouge/lexers/ceylon.rb
@@ -11,34 +11,6 @@ module Rouge
title "Ceylon"
desc 'Say more, more clearly.'
- keywords = %w(
- break case catch continue else finally for in
- if return switch this throw try while is exists dynamic
- nonempty then outer assert let
- )
-
- keywords_declaration = %w(
- abstracts extends satisfies super given of out assign
- )
-
- keywords_type = %w(
- function value void new
- )
-
- keywords_namespace = %w(
- assembly module package
- )
-
- keywords_constant = %w(
- true false null
- )
-
- annotations = %w(
- shared abstract formal default actual variable deprecated small
- late literal doc by see throws optional license tagged final native
- annotation sealed
- )
-
state :whitespace do
rule %r([^\S\n]+), Text
rule %r(//.*?\n), Comment::Single
diff --git a/lib/rouge/lexers/glsl.rb b/lib/rouge/lexers/glsl.rb
index a9227ff..d1d65f5 100644
--- a/lib/rouge/lexers/glsl.rb
+++ b/lib/rouge/lexers/glsl.rb
@@ -17,10 +17,6 @@ module Rouge
title "GLSL"
desc "The GLSL shader language"
- # optional comment or whitespace
- ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
- id = /[a-zA-Z_][a-zA-Z0-9_]*/
-
def self.keywords
@keywords ||= Set.new %w(
attribute const uniform varying
diff --git a/lib/rouge/lexers/haml.rb b/lib/rouge/lexers/haml.rb
index 6603c63..e63486a 100644
--- a/lib/rouge/lexers/haml.rb
+++ b/lib/rouge/lexers/haml.rb
@@ -66,10 +66,6 @@ module Rouge
# To accomodate this, use this custom faux dot instead.
dot = /[ ]\|\n(?=.*[ ]\|)|./
- # In certain places, a comma at the end of the line
- # allows line wrapping as well.
- comma_dot = /,\s*\n|#{dot}/
-
state :root do
rule %r/\s*\n/, Text
rule(/\s*/) { |m| token Text; indentation(m[0]) }
diff --git a/lib/rouge/lexers/m68k.rb b/lib/rouge/lexers/m68k.rb
index 42e4cac..2206fa7 100644
--- a/lib/rouge/lexers/m68k.rb
+++ b/lib/rouge/lexers/m68k.rb
@@ -9,7 +9,6 @@ module Rouge
title "M68k"
desc "Motorola 68k Assembler"
- ws = %r((?:\s|;.*?\n/)+)
id = /[a-zA-Z_][a-zA-Z0-9_]*/
def self.keywords
diff --git a/lib/rouge/lexers/make.rb b/lib/rouge/lexers/make.rb
index 485a88c..9140dbf 100644
--- a/lib/rouge/lexers/make.rb
+++ b/lib/rouge/lexers/make.rb
@@ -11,16 +11,6 @@ module Rouge
filenames '*.make', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile'
mimetypes 'text/x-makefile'
- bsd_special = %w(
- include undef error warning if else elif endif for endfor
- )
-
- gnu_special = %w(
- ifeq ifneq ifdef ifndef else endif include -include define endef :
- )
-
- line = /(?:\\.|\\\n|[^\\\n])*/m
-
def initialize(opts={})
super
@shell = Shell.new(opts)
diff --git a/lib/rouge/lexers/nasm.rb b/lib/rouge/lexers/nasm.rb
index c5e4805..2ebd975 100644
--- a/lib/rouge/lexers/nasm.rb
+++ b/lib/rouge/lexers/nasm.rb
@@ -11,7 +11,6 @@ module Rouge
title "Nasm"
desc "Netwide Assembler"
- ws = %r((?:\s|;.*?\n/)+)
id = /[a-zA-Z_][a-zA-Z0-9_]*/
#todo: pull more instructions from: http://www.nasm.us/doc/nasmdocb.html
diff --git a/lib/rouge/lexers/powershell.rb b/lib/rouge/lexers/powershell.rb
index 00770a7..61993e3 100644
--- a/lib/rouge/lexers/powershell.rb
+++ b/lib/rouge/lexers/powershell.rb
@@ -665,7 +665,7 @@ module Rouge
end
prepend :basic do
- rule %r(<#[\s,\S]*?#>)m, Comment::Multiline
+ rule %r(<#[\s\S]*?#>)m, Comment::Multiline
rule %r/#.*$/, Comment::Single
rule %r/\b(#{OPERATORS})\s*\b/i, Operator
rule %r/\b(#{ATTRIBUTES})\s*\b/i, Name::Attribute
diff --git a/lib/rouge/lexers/prolog.rb b/lib/rouge/lexers/prolog.rb
index c905fe7..b3b0097 100644
--- a/lib/rouge/lexers/prolog.rb
+++ b/lib/rouge/lexers/prolog.rb
@@ -27,7 +27,7 @@ module Rouge
end
state :atoms do
- rule %r/[[:lower:]]([_[:word:][:digit:]])*/, Str::Symbol
+ rule %r/[[:lower:]]([[:word:]])*/, Str::Symbol
rule %r/'[^']*'/, Str::Symbol
end
diff --git a/lib/rouge/lexers/python.rb b/lib/rouge/lexers/python.rb
index 76ddeab..584f1c5 100644
--- a/lib/rouge/lexers/python.rb
+++ b/lib/rouge/lexers/python.rb
@@ -194,7 +194,7 @@ module Rouge
rule %r(\\
( [\\abfnrtv"']
| \n
- | N{[a-zA-z][a-zA-Z ]+[a-zA-Z]}
+ | N{[a-zA-Z][a-zA-Z ]+[a-zA-Z]}
| u[a-fA-F0-9]{4}
| U[a-fA-F0-9]{8}
| x[a-fA-F0-9]{2}
diff --git a/lib/rouge/lexers/ruby.rb b/lib/rouge/lexers/ruby.rb
index 8f93311..e37561d 100644
--- a/lib/rouge/lexers/ruby.rb
+++ b/lib/rouge/lexers/ruby.rb
@@ -289,9 +289,9 @@ module Rouge
rule %r/\s+/, Text
rule %r/\(/, Punctuation, :defexpr
rule %r(
- (?:([a-zA-Z_][\w_]*)(\.))?
+ (?:([a-zA-Z_]\w*)(\.))?
(
- [a-zA-Z_][\w_]*[!?]? |
+ [a-zA-Z_]\w*[!?]? |
\*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
<<? | >>? | <=>? | >= | ===?
)
diff --git a/lib/rouge/lexers/terraform.rb b/lib/rouge/lexers/terraform.rb
index f3588be..ad4fc59 100644
--- a/lib/rouge/lexers/terraform.rb
+++ b/lib/rouge/lexers/terraform.rb
@@ -59,7 +59,7 @@ module Rouge
state :heredoc do
rule %r/\n/, Str::Heredoc, :heredoc_nl
- rule %r/[^$\n\$]+/, Str::Heredoc
+ rule %r/[^$\n]+/, Str::Heredoc
rule %r/[$]/, Str::Heredoc
mixin :strings
end
diff --git a/lib/rouge/lexers/verilog.rb b/lib/rouge/lexers/verilog.rb
index 0ef24b0..ed7a8b9 100644
--- a/lib/rouge/lexers/verilog.rb
+++ b/lib/rouge/lexers/verilog.rb
@@ -10,8 +10,6 @@ module Rouge
filenames '*.v', '*.sv', '*.svh'
mimetypes 'text/x-verilog', 'text/x-systemverilog'
- # optional comment or whitespace
- ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
id = /[a-zA-Z_][a-zA-Z0-9_]*/
def self.keywords
@@ -128,8 +126,8 @@ module Rouge
rule %r/[0-9]*'b?[01xz_?]+/, Num::Bin
rule %r/[0-9]*'d[0-9_?]+/, Num::Integer
rule %r/[0-9_]+[lu]*/i, Num::Integer
- rule %r([~!%^&*+-=\|?:<>/@{}]), Operator
- rule %r/[()\[\],.$\#]/, Punctuation
+ rule %r([-~!%^&*+=\|?:<>/@{}]), Operator
+ rule %r/[()\[\],.$\#;]/, Punctuation
rule %r/`(\w+)/, Comment::Preproc
rule id do |m|
|
#1189 has now been merged. |
I resolved the conflict. Thanks. |
@pocke Thanks for submitting this. It looks like a terrific step forward to the goal of reducing warnings! It will take a little bit of time to review but I really appreciate the detailed comment explaining the PR. It's really helpful :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you again for this, @pocke. It's truly appreciated.
@pocke Thanks so much for helping to improve Rouge. I'm sorry those warnings are still there for the local variables I asked you to put back. I'm hopeful to address this problem soon! |
Problem
Rouge gem displays many warnings on loading the gem.
This pull request will suppress most of the warnings.
Before
After
Solution
There are two types of warning. They are
assigned but unused variable
andcharacter class has duplicated range
.Assigned but unused variable
It's easy. Just remove the assignments.
Character class has duplicated range
It is a regexp warning.
For example,
/[aa]/
has the warning because the doublea
is redundant. It should be/[a]/
.I explain the individual cases.
\s
includes\t
and so on\s
includes\t
,\r
, and\n
. So/[\s\n]/
has the warning. We can remove\n
from the regular expression.\w
includes_
and\d
/[\w_]/
and/[\w\d]/
have the warning.By the way, I guess it may be a bug of syntax.
For example, I changed
/\w[\w\d]*/
to/\w+/
in groovy lexer. This change does not affect the meaning of the regexp.But I guess Groovy (and other languages) class name does not allow a number on the first of the name.
So maybe it should be
/[A-Za-z]\w*/
. But I'm not sure the languages, so this pull request does not change the behavior that looks bugs.x option does not ignore whitespaces in character class
Basically,
x
option ignores whitespaces in Regexp. But it does not ignore whitespaces in character class.So
/[a b c]/
displays the warning.Julia lexer only has the warning.
-
in the middle of character class-
works as a range in a character class. For example,/[a-z]/
matches"c"
because"c"
is between"a"
and"z"
.But rouge uses
-
unexpectedly. Rouge expects it just matches"-"
, but it is evaluated as a range.Other change does not affect the behavior, but this change affects behaviour.
I guess they are bugs.
The following files had the warnings.
Note
Scala lexer has warnings even if this pull request is merged.
I tried to suppress the warnings, but it is difficult to me.