From fac7e1ba5cdecf1a5b90cbaeade96b4b692d6c5e Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 10 May 2023 11:54:09 -0700 Subject: [PATCH 1/6] Fix warnings about private_class_method usage --- lib/rouge/cli.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/rouge/cli.rb b/lib/rouge/cli.rb index b5b26a7cf4..49d9df4655 100644 --- a/lib/rouge/cli.rb +++ b/lib/rouge/cli.rb @@ -347,8 +347,7 @@ def run formatter.format(lexer.lex(input), &method(:print)) end - private_class_method - def self.parse_cgi(str) + private_class_method def self.parse_cgi(str) pairs = CGI.parse(str).map { |k, v| [k.to_sym, v.first] } Hash[pairs] end @@ -511,8 +510,7 @@ def run end - private_class_method - def self.normalize_syntax(argv) + private_class_method def self.normalize_syntax(argv) out = [] argv.each do |arg| case arg From 07ac7684f32901ebaf4780938acccaafbc1dc6ba Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 10 May 2023 11:54:26 -0700 Subject: [PATCH 2/6] Unused variable warnings Most of these should just be removed instead of underscored... but I want eyeballs on this first. Some aren't being used the way they think they're being used. --- lib/rouge/lexers/meson.rb | 2 +- lib/rouge/lexers/objective_c/common.rb | 2 +- lib/rouge/lexers/openedge.rb | 2 +- lib/rouge/lexers/syzlang.rb | 2 +- lib/rouge/lexers/ttcn3.rb | 2 +- lib/rouge/tex_theme_renderer.rb | 2 +- spec/guesser_spec.rb | 2 -- 7 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/rouge/lexers/meson.rb b/lib/rouge/lexers/meson.rb index 616cb4f1c1..2051c7fe4a 100644 --- a/lib/rouge/lexers/meson.rb +++ b/lib/rouge/lexers/meson.rb @@ -38,7 +38,7 @@ def self.builtin_functions end identifier = /[[:alpha:]_][[:alnum:]_]*/ - dotted_identifier = /[[:alpha:]_.][[:alnum:]_.]*/ + _dotted_identifier = /[[:alpha:]_.][[:alnum:]_.]*/ def current_string @current_string ||= StringRegister.new diff --git a/lib/rouge/lexers/objective_c/common.rb b/lib/rouge/lexers/objective_c/common.rb index a0e69e7d5e..8eeeb0a78a 100644 --- a/lib/rouge/lexers/objective_c/common.rb +++ b/lib/rouge/lexers/objective_c/common.rb @@ -4,7 +4,7 @@ module Rouge module Lexers module ObjectiveCCommon - id = /[a-z$_][a-z0-9$_]*/i + _id = /[a-z$_][a-z0-9$_]*/i def at_keywords @at_keywords ||= %w( diff --git a/lib/rouge/lexers/openedge.rb b/lib/rouge/lexers/openedge.rb index f34aff2c9e..c196869487 100644 --- a/lib/rouge/lexers/openedge.rb +++ b/lib/rouge/lexers/openedge.rb @@ -13,7 +13,7 @@ class OpenEdge < RegexLexer desc 'The OpenEdge ABL programming language' # optional comment or whitespace - ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) + _ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) id = /[a-zA-Z_&{}!][a-zA-Z0-9_\-&!}]*/ def self.keywords diff --git a/lib/rouge/lexers/syzlang.rb b/lib/rouge/lexers/syzlang.rb index f203e828c9..6eaa87143d 100644 --- a/lib/rouge/lexers/syzlang.rb +++ b/lib/rouge/lexers/syzlang.rb @@ -27,7 +27,7 @@ def self.keywords_type comment = /#.*$/ inline_spaces = /[ \t]+/ - eol_spaces = /[\n\r]+/ + _eol_spaces = /[\n\r]+/ spaces = /\s+/ state :inline_break do diff --git a/lib/rouge/lexers/ttcn3.rb b/lib/rouge/lexers/ttcn3.rb index 4b8b27d35c..c3abebe205 100644 --- a/lib/rouge/lexers/ttcn3.rb +++ b/lib/rouge/lexers/ttcn3.rb @@ -47,7 +47,7 @@ def self.types end # optional comment or whitespace - ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) + _ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) id = /[a-zA-Z_]\w*/ digit = /\d_+\d|\d/ bin_digit = /[01]_+[01]|[01]/ diff --git a/lib/rouge/tex_theme_renderer.rb b/lib/rouge/tex_theme_renderer.rb index e107d16579..e912e2ec8d 100644 --- a/lib/rouge/tex_theme_renderer.rb +++ b/lib/rouge/tex_theme_renderer.rb @@ -109,7 +109,7 @@ def token_name(tok) end def render_blank(tok, &b) - out = "\\expandafter\\def#{token_name(tok)}#1{#1}" + "\\expandafter\\def#{token_name(tok)}#1{#1}" end def render_style(tok, style, &b) diff --git a/spec/guesser_spec.rb b/spec/guesser_spec.rb index e6d80fe6bc..bcc9ba9478 100644 --- a/spec/guesser_spec.rb +++ b/spec/guesser_spec.rb @@ -47,8 +47,6 @@ it 'sequentially filters' do custom = Class.new(Rouge::Guesser) { define_method(:filter) { |lexers| - passed_lexers = lexers - [Rouge::Lexers::Javascript, Rouge::Lexers::Prolog] } }.new From 7576f89215859dbd28f3f9c4abf6fcc92e2b5f75 Mon Sep 17 00:00:00 2001 From: Tan Le Date: Mon, 18 Mar 2024 13:24:44 +1100 Subject: [PATCH 3/6] Remove unused variable warnings in GDScript --- lib/rouge/lexers/gdscript.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rouge/lexers/gdscript.rb b/lib/rouge/lexers/gdscript.rb index 372b6c1ded..123bbc0505 100644 --- a/lib/rouge/lexers/gdscript.rb +++ b/lib/rouge/lexers/gdscript.rb @@ -12,7 +12,7 @@ class GDScript < RegexLexer mimetypes 'text/x-gdscript', 'application/x-gdscript' def self.keywords - @keywords = %w( + @keywords ||= %w( and in not or as breakpoint class class_name extends is func setget signal tool const enum export onready static var break continue if elif else for pass return match while remote master puppet @@ -22,13 +22,13 @@ def self.keywords # Reserved for future implementation def self.keywords_reserved - @keywords_reserved = %w( + @keywords_reserved ||= %w( do switch case ).join('|') end def self.builtins - builtins = %w( + @builtins ||= %w( Color8 ColorN abs acos asin assert atan atan2 bytes2var ceil char clamp convert cos cosh db2linear decimals dectime deg2rad dict2inst ease exp floor fmod fposmod funcref hash inst2dict instance_from_id @@ -41,7 +41,7 @@ def self.builtins end def self.builtins_type - @builtins_type = %w( + @builtins_type ||= %w( bool int float String Vector2 Rect2 Transform2D Vector3 AABB Plane Quat Basis Transform Color RID Object NodePath Dictionary Array PoolByteArray PoolIntArray PoolRealArray PoolStringArray From cab225d5661a1184fe4b7d2dba36f22dc40c6650 Mon Sep 17 00:00:00 2001 From: Tan Le Date: Mon, 18 Mar 2024 13:31:24 +1100 Subject: [PATCH 4/6] Remove unused variables --- lib/rouge/lexers/meson.rb | 1 - lib/rouge/lexers/objective_c/common.rb | 2 -- lib/rouge/lexers/openedge.rb | 2 -- lib/rouge/lexers/syzlang.rb | 1 - lib/rouge/lexers/ttcn3.rb | 2 -- 5 files changed, 8 deletions(-) diff --git a/lib/rouge/lexers/meson.rb b/lib/rouge/lexers/meson.rb index 2051c7fe4a..ab0bd64ccd 100644 --- a/lib/rouge/lexers/meson.rb +++ b/lib/rouge/lexers/meson.rb @@ -38,7 +38,6 @@ def self.builtin_functions end identifier = /[[:alpha:]_][[:alnum:]_]*/ - _dotted_identifier = /[[:alpha:]_.][[:alnum:]_.]*/ def current_string @current_string ||= StringRegister.new diff --git a/lib/rouge/lexers/objective_c/common.rb b/lib/rouge/lexers/objective_c/common.rb index 8eeeb0a78a..2cb8107944 100644 --- a/lib/rouge/lexers/objective_c/common.rb +++ b/lib/rouge/lexers/objective_c/common.rb @@ -4,8 +4,6 @@ module Rouge module Lexers module ObjectiveCCommon - _id = /[a-z$_][a-z0-9$_]*/i - def at_keywords @at_keywords ||= %w( selector private protected public encode synchronized try diff --git a/lib/rouge/lexers/openedge.rb b/lib/rouge/lexers/openedge.rb index c196869487..82501276c4 100644 --- a/lib/rouge/lexers/openedge.rb +++ b/lib/rouge/lexers/openedge.rb @@ -12,8 +12,6 @@ class OpenEdge < RegexLexer title 'OpenEdge ABL' desc 'The OpenEdge ABL programming language' - # optional comment or whitespace - _ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) id = /[a-zA-Z_&{}!][a-zA-Z0-9_\-&!}]*/ def self.keywords diff --git a/lib/rouge/lexers/syzlang.rb b/lib/rouge/lexers/syzlang.rb index 6eaa87143d..dbaea03e51 100644 --- a/lib/rouge/lexers/syzlang.rb +++ b/lib/rouge/lexers/syzlang.rb @@ -27,7 +27,6 @@ def self.keywords_type comment = /#.*$/ inline_spaces = /[ \t]+/ - _eol_spaces = /[\n\r]+/ spaces = /\s+/ state :inline_break do diff --git a/lib/rouge/lexers/ttcn3.rb b/lib/rouge/lexers/ttcn3.rb index c3abebe205..6ccac4ea11 100644 --- a/lib/rouge/lexers/ttcn3.rb +++ b/lib/rouge/lexers/ttcn3.rb @@ -46,8 +46,6 @@ def self.types ) end - # optional comment or whitespace - _ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) id = /[a-zA-Z_]\w*/ digit = /\d_+\d|\d/ bin_digit = /[01]_+[01]|[01]/ From b6561421043dfa994de534655f4e48f6ef88b194 Mon Sep 17 00:00:00 2001 From: Tan Le Date: Mon, 18 Mar 2024 13:49:14 +1100 Subject: [PATCH 5/6] Remove parentheses after method name warnings --- tasks/builtins/lasso.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/builtins/lasso.rake b/tasks/builtins/lasso.rake index 13788ec679..9db355e624 100644 --- a/tasks/builtins/lasso.rake +++ b/tasks/builtins/lasso.rake @@ -46,7 +46,7 @@ module Rouge keywords end - def render_output (keywords, &b) + def render_output(keywords, &b) return enum_for(:render_output, keywords).to_a.join("\n") unless b yield "# -*- coding: utf-8 -*- #" From 56952bc1af2c2ee229d0d6a4ad542af6174abb5a Mon Sep 17 00:00:00 2001 From: Tan Le Date: Mon, 18 Mar 2024 13:50:14 +1100 Subject: [PATCH 6/6] Remove regexp ambiguity warnings --- tasks/builtins/sqf.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/builtins/sqf.rake b/tasks/builtins/sqf.rake index 5f415f0ff0..1720affdf8 100644 --- a/tasks/builtins/sqf.rake +++ b/tasks/builtins/sqf.rake @@ -24,7 +24,7 @@ module Rouge module Builtins class SQF def extract_keywords(input) - input.scrub.scan /(?<=\(").+?(?=")/ + input.scrub.scan(/(?<=\(").+?(?=")/) end def render_output(keywords, &b)