-
Notifications
You must be signed in to change notification settings - Fork 743
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
base: master
Are you sure you want to change the base?
Conversation
Wow!! This is AWESOME, @pyrmont !! 👏 👏 |
@ashmaroli Thanks :) You and @pocke made it a lot easier by clearing up almost all the regular expression warnings.
I'm not sure I follow. |
I was thinking of something along the following lines: module Rouge
def self.get_kewords(source)
instance_eval(File.read(File.join(__dir__, source)))
end
end class FooLexer < Rouge::RegexLexer
def self.keywords
@keywords ||= Rouge.get_keywords('foo/keywords.rb")
end
end But nevermind.., I tested it. Won't work..!! |
lib/rouge/theme.rb
Outdated
return @mode if arg == :absent | ||
if arg == :absent | ||
return (defined?(@mode) ? @mode : nil) | ||
end |
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.
this seems excessive...
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.
I agree in principle but was the simplest way I could think of to fix the warning.
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.
Again, I'm actually completely okay with rouge depending on uninitialized instance variables. This code is basically a fancy version of ||=
, which ruby explicitly supports.
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.
I don't run Rouge with warnings turned on so I don't really care but for a library like Rouge that's typically part of a larger project (eg. Jekyll, GitLab, etc), being able to run without warnings seems like a nice feature.
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.
Oh, and in case it helps, here's the message for this one:
lib/rouge/theme.rb:138: warning: instance variable @mode not initialized
@@ -13,7 +13,7 @@ | |||
} | |||
|
|||
let(:markdown) { | |||
Redcarpet::Markdown.new(redcarpet.new, :fenced_code_blocks => true) | |||
Redcarpet::Markdown.new(redcarpet.new({}), :fenced_code_blocks => true) |
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.
??? is this not defaulted?
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.
My best guess is that the issue here is that the class that the redcarpet
object represents is defined in C directly. If you look at the documentation the implementing file is a C file and the constructor's source is a C function. I think the reference in the C function to @options
is what the warning is picking up and complaining about when defined implicitly.
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.
I'm not... actually concerned at all about implicit instance variable usage, it's a feature of ruby that I rely on quite a bit and I'm a bit miffed that ruby warns about it to be honest.
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.
I don't think implicit instance variable usage is the problem per se. It's the way that it works with the C implementation that's causing the warning.
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.
Although, again, that's a best guess. This is the warning:
spec/plugins/redcarpet_spec.rb:16: warning: instance variable @options not initialized
Given this is line 16, that's rather oblique:
rouge/spec/plugins/redcarpet_spec.rb
Line 16 in 904afdc
Redcarpet::Markdown.new(redcarpet.new, :fenced_code_blocks => true) |
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.
@pyrmont I think this warning should be fixed at the upstream source itself instead in the test-suite here. Besides, this warning won't affect end-users of Jekyll, Gitlab since its not part of Rouge core.
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.
@ashmaroli The last release of Redcarpet was in December 2016. I wouldn't hold my breath on an update. We still have a circular require warning from their library that was fixed in a patch from January 2017 and that hasn't been released.
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.
I think this was fixed in 3.5.0, so the change may no longer be needed: vmg/redcarpet@6b86656
@pyrmont Can you push the correction to the |
@ashmaroli So submit a separate PR, merge the PR and then update this branch against master? The last strep shouldn't be necessary, right? This PR already incorporates the change. |
You don't have to submit a PR. You can push the fix directly, can't you? |
@ashmaroli I can push directly to master but for documentary purposes have avoided doing this. Thanks for submitting #1243 :) |
Conflicts galore on this branch.. |
This commit reduces to zero all warnings generated internally by Rouge when Ruby is run with warnings enabled.
3aa37e3
to
34d21ce
Compare
MathWorks have made it so that the webpage with the MatLab functions requires JavaScript… >_< |
This is dependent on PR #1300. |
The dependency PR has been merged, so I think this can now move forward. I can help with the rebase, but I don't think I can update this PR. Meanwhile, I'll add some review notes. |
@@ -120,7 +120,11 @@ class Elixir < RegexLexer | |||
rule %r/[\\#]/, toktype | |||
end | |||
|
|||
uniq_chars = "#{open}#{close}".squeeze | |||
uniq_chars = if open == close | |||
open.squeeze |
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.
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 squeeze
s can be removed.
@@ -13,7 +13,7 @@ | |||
} | |||
|
|||
let(:markdown) { | |||
Redcarpet::Markdown.new(redcarpet.new, :fenced_code_blocks => true) | |||
Redcarpet::Markdown.new(redcarpet.new({}), :fenced_code_blocks => true) |
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.
I think this was fixed in 3.5.0, so the change may no longer be needed: vmg/redcarpet@6b86656
This commit reduces to zero all warnings generated internally by Rouge when Ruby is run with warnings enabled.