Skip to content
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 further #1228

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gem 'parallel', '~> 1.13.0' if RUBY_VERSION < '2.2.0'
gem 'rubocop', '~> 0.49.1'

# don't try to install redcarpet under jruby
gem 'redcarpet', :platforms => :ruby
gem 'redcarpet', '~> 3.5.0', :platforms => :ruby

# Profiling
if RUBY_VERSION >= '2.3.0'
Expand Down
4 changes: 3 additions & 1 deletion lib/rouge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# stdlib
require 'pathname'

# version
require 'rouge/version'

# The containing module for Rouge
module Rouge
class << self
Expand Down Expand Up @@ -43,7 +46,6 @@ def lexer_dir(path = '')
File.join(__dir__, 'rouge', 'lexers', path)
end

load_relative 'rouge/version'
load_relative 'rouge/util'
load_relative 'rouge/text_analyzer'
load_relative 'rouge/token'
Expand Down
9 changes: 6 additions & 3 deletions lib/rouge/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ def run
formatter.format(lexer.lex(input), &method(:print))
end

private_class_method
# TODO: When we drop support for Ruby 2.0, private_class_method can
# preface this method
def self.parse_cgi(str)
pairs = CGI.parse(str).map { |k, v| [k.to_sym, v.first] }
Hash[pairs]
end
private_class_method :parse_cgi
end

class Style < CLI
Expand Down Expand Up @@ -460,8 +462,8 @@ def run
end
end


private_class_method
# TODO: When we drop support for Ruby 2.0, private_class_method can preface
# this method
def self.normalize_syntax(argv)
out = []
argv.each do |arg|
Expand All @@ -477,5 +479,6 @@ def self.normalize_syntax(argv)

out
end
private_class_method :normalize_syntax
end
end
2 changes: 1 addition & 1 deletion lib/rouge/lexers/ada.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def self.idents
end

# Flag word-like things that don't match the ID pattern.
rule %r{\b(\p{Pc}|[[alpha]])\p{Word}*}, Error
rule %r{\b(\p{Pc}|[[:alpha:]])\p{Word}*}, Error
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/rouge/lexers/elixir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ class Elixir < RegexLexer
rule %r/[\\#]/, toktype
end

uniq_chars = "#{open}#{close}".squeeze
uniq_chars = if open == close
open.squeeze
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the point of squeeze was to attempt to remove duplicate characters, but it didn't take into account escaping.
With the condition being explicit now, both squeezes can be removed.

else
"#{open}#{close}".squeeze
end
rule %r/[^##{uniq_chars}\\]+/m, toktype
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rouge/lexers/gdscript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/rouge/lexers/gherkin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def self.detect?(text)

# self-modifying method that loads the keywords file
def self.keywords
load File.join(__dir__, 'gherkin/keywords.rb')
keywords
@keywords ||= instance_eval(File.read(File.join(__dir__, "gherkin/keywords.rb")))
end

def self.step_regex
Expand Down
16 changes: 5 additions & 11 deletions lib/rouge/lexers/gherkin/keywords.rb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions lib/rouge/lexers/lua.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def self.detect?(text)
end

def self.builtins
load File.join(__dir__, 'lua/builtins.rb')
self.builtins
@builtins ||= instance_eval(File.read(File.join(__dir__, 'lua/builtins.rb')))
end

def builtins
Expand Down
30 changes: 11 additions & 19 deletions lib/rouge/lexers/lua/builtins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@
# frozen_string_literal: true

# automatically generated by `rake builtins:lua`
module Rouge
module Lexers
class Lua
def self.builtins
@builtins ||= {}.tap do |b|
b["basic"] = Set.new %w(_G _VERSION assert collectgarbage dofile error getmetatable ipairs load loadfile next pairs pcall print rawequal rawget rawlen rawset select setmetatable tonumber tostring type xpcall file:close file:flush file:lines file:read file:seek file:setvbuf file:write LUA_CPATH LUA_CPATH_5_2 LUA_INIT LUA_INIT_5_2 LUA_PATH LUA_PATH_5_2 luaopen_base luaopen_bit32 luaopen_coroutine luaopen_debug luaopen_io luaopen_math luaopen_os luaopen_package luaopen_string luaopen_table LUA_ERRERR LUA_ERRFILE LUA_ERRGCMM LUA_ERRMEM LUA_ERRRUN LUA_ERRSYNTAX LUA_HOOKCALL LUA_HOOKCOUNT LUA_HOOKLINE LUA_HOOKRET LUA_HOOKTAILCALL LUA_MASKCALL LUA_MASKCOUNT LUA_MASKLINE LUA_MASKRET LUA_MINSTACK LUA_MULTRET LUA_NOREF LUA_OK LUA_OPADD LUA_OPDIV LUA_OPEQ LUA_OPLE LUA_OPLT LUA_OPMOD LUA_OPMUL LUA_OPPOW LUA_OPSUB LUA_OPUNM LUA_REFNIL LUA_REGISTRYINDEX LUA_RIDX_GLOBALS LUA_RIDX_MAINTHREAD LUA_TBOOLEAN LUA_TFUNCTION LUA_TLIGHTUSERDATA LUA_TNIL LUA_TNONE LUA_TNUMBER LUA_TSTRING LUA_TTABLE LUA_TTHREAD LUA_TUSERDATA LUA_USE_APICHECK LUA_YIELD LUAL_BUFFERSIZE)
b["modules"] = Set.new %w(require package.config package.cpath package.loaded package.loadlib package.path package.preload package.searchers package.searchpath)
b["bit32"] = Set.new %w(bit32.arshift bit32.band bit32.bnot bit32.bor bit32.btest bit32.bxor bit32.extract bit32.lrotate bit32.lshift bit32.replace bit32.rrotate bit32.rshift)
b["coroutine"] = Set.new %w(coroutine.create coroutine.resume coroutine.running coroutine.status coroutine.wrap coroutine.yield)
b["debug"] = Set.new %w(debug.debug debug.getuservalue debug.gethook debug.getinfo debug.getlocal debug.getmetatable debug.getregistry debug.getupvalue debug.setuservalue debug.sethook debug.setlocal debug.setmetatable debug.setupvalue debug.traceback debug.upvalueid debug.upvaluejoin)
b["io"] = Set.new %w(io.close io.flush io.input io.lines io.open io.output io.popen io.read io.stderr io.stdin io.stdout io.tmpfile io.type io.write)
b["math"] = Set.new %w(math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.cosh math.deg math.exp math.floor math.fmod math.frexp math.huge math.ldexp math.log math.max math.min math.modf math.pi math.pow math.rad math.random math.randomseed math.sin math.sinh math.sqrt math.tan math.tanh)
b["os"] = Set.new %w(os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname)
b["string"] = Set.new %w(string.byte string.char string.dump string.find string.format string.gmatch string.gsub string.len string.lower string.match string.rep string.reverse string.sub string.upper)
b["table"] = Set.new %w(table.concat table.insert table.pack table.remove table.sort table.unpack)
end
end
end
end
{}.tap do |b|
b["basic"] = Set.new %w(_G _VERSION assert collectgarbage dofile error getmetatable ipairs load loadfile next pairs pcall print rawequal rawget rawlen rawset select setmetatable tonumber tostring type xpcall file:close file:flush file:lines file:read file:seek file:setvbuf file:write LUA_CPATH LUA_CPATH_5_2 LUA_INIT LUA_INIT_5_2 LUA_PATH LUA_PATH_5_2 luaopen_base luaopen_bit32 luaopen_coroutine luaopen_debug luaopen_io luaopen_math luaopen_os luaopen_package luaopen_string luaopen_table LUA_ERRERR LUA_ERRFILE LUA_ERRGCMM LUA_ERRMEM LUA_ERRRUN LUA_ERRSYNTAX LUA_HOOKCALL LUA_HOOKCOUNT LUA_HOOKLINE LUA_HOOKRET LUA_HOOKTAILCALL LUA_MASKCALL LUA_MASKCOUNT LUA_MASKLINE LUA_MASKRET LUA_MINSTACK LUA_MULTRET LUA_NOREF LUA_OK LUA_OPADD LUA_OPDIV LUA_OPEQ LUA_OPLE LUA_OPLT LUA_OPMOD LUA_OPMUL LUA_OPPOW LUA_OPSUB LUA_OPUNM LUA_REFNIL LUA_REGISTRYINDEX LUA_RIDX_GLOBALS LUA_RIDX_MAINTHREAD LUA_TBOOLEAN LUA_TFUNCTION LUA_TLIGHTUSERDATA LUA_TNIL LUA_TNONE LUA_TNUMBER LUA_TSTRING LUA_TTABLE LUA_TTHREAD LUA_TUSERDATA LUA_USE_APICHECK LUA_YIELD LUAL_BUFFERSIZE)
b["modules"] = Set.new %w(require package.config package.cpath package.loaded package.loadlib package.path package.preload package.searchers package.searchpath)
b["bit32"] = Set.new %w(bit32.arshift bit32.band bit32.bnot bit32.bor bit32.btest bit32.bxor bit32.extract bit32.lrotate bit32.lshift bit32.replace bit32.rrotate bit32.rshift)
b["coroutine"] = Set.new %w(coroutine.create coroutine.resume coroutine.running coroutine.status coroutine.wrap coroutine.yield)
b["debug"] = Set.new %w(debug.debug debug.getuservalue debug.gethook debug.getinfo debug.getlocal debug.getmetatable debug.getregistry debug.getupvalue debug.setuservalue debug.sethook debug.setlocal debug.setmetatable debug.setupvalue debug.traceback debug.upvalueid debug.upvaluejoin)
b["io"] = Set.new %w(io.close io.flush io.input io.lines io.open io.output io.popen io.read io.stderr io.stdin io.stdout io.tmpfile io.type io.write)
b["math"] = Set.new %w(math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.cosh math.deg math.exp math.floor math.fmod math.frexp math.huge math.ldexp math.log math.max math.min math.modf math.pi math.pow math.rad math.random math.randomseed math.sin math.sinh math.sqrt math.tan math.tanh)
b["os"] = Set.new %w(os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname)
b["string"] = Set.new %w(string.byte string.char string.dump string.find string.format string.gmatch string.gsub string.len string.lower string.match string.rep string.reverse string.sub string.upper)
b["table"] = Set.new %w(table.concat table.insert table.pack table.remove table.sort table.unpack)
end
3 changes: 1 addition & 2 deletions lib/rouge/lexers/mathematica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def self.keywords

# The list of built-in symbols comes from a wolfram server and is created automatically by rake
def self.builtins
load File.join(__dir__, 'mathematica/builtins.rb')
self.builtins
@builtins ||= instance_eval(File.read(File.join(__dir__, "mathematica/builtins.rb")))
end

state :root do
Expand Down
10 changes: 1 addition & 9 deletions lib/rouge/lexers/mathematica/builtins.rb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions lib/rouge/lexers/matlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def self.keywords
end

def self.builtins
load File.join(__dir__, 'matlab/builtins.rb')
self.builtins
@builtins ||= instance_eval(File.read(File.join(__dir__, "matlab/builtins.rb")))
end

state :root do
Expand Down
Loading