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

Conversation

pyrmont
Copy link
Contributor

@pyrmont pyrmont commented Jun 26, 2019

This commit reduces to zero all warnings generated internally by Rouge when Ruby is run with warnings enabled.

@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Jun 26, 2019
@ashmaroli
Copy link
Contributor

Wow!! This is AWESOME, @pyrmont !! 👏 👏
Just one thought though:
"Is there a way that instance_eval(File.read(File.join(__dir__, <keyword-source>))) could be converted into a method and work as it does currently..?"

@pyrmont
Copy link
Contributor Author

pyrmont commented Jun 26, 2019

@ashmaroli Thanks :) You and @pocke made it a lot easier by clearing up almost all the regular expression warnings.

"Is there a way that instance_eval(File.read(File.join(__dir__, <keyword-source>))) could be converted into a method and work as it does currently..?"

I'm not sure I follow. instance_eval is a method and each call is wrapped in a memoised method. Could you explain in a bit more detail what you meant?

@ashmaroli
Copy link
Contributor

Could you explain in a bit more detail what you meant?

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..!!

return @mode if arg == :absent
if arg == :absent
return (defined?(@mode) ? @mode : nil)
end
Copy link
Member

Choose a reason for hiding this comment

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

this seems excessive...

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@pyrmont pyrmont Jun 27, 2019

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)
Copy link
Member

Choose a reason for hiding this comment

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

??? is this not defaulted?

Copy link
Contributor Author

@pyrmont pyrmont Jun 27, 2019

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@pyrmont pyrmont Jun 27, 2019

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:

Redcarpet::Markdown.new(redcarpet.new, :fenced_code_blocks => true)

Copy link
Contributor

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.

Copy link
Contributor Author

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.

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 this was fixed in 3.5.0, so the change may no longer be needed: vmg/redcarpet@6b86656

Rakefile Outdated Show resolved Hide resolved
@ashmaroli
Copy link
Contributor

@pyrmont Can you push the correction to the profiler_memory task separately to master and then update this branch..?
The reason I ask is comparing the memory usage on master and this PR isn't giving concrete results..

@pyrmont
Copy link
Contributor Author

pyrmont commented Jul 2, 2019

@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.

@ashmaroli
Copy link
Contributor

You don't have to submit a PR. You can push the fix directly, can't you?
This branch should be updated after wards so that a new build is triggered on Travis

@pyrmont
Copy link
Contributor Author

pyrmont commented Jul 3, 2019

@ashmaroli I can push directly to master but for documentary purposes have avoided doing this. Thanks for submitting #1243 :)

@ashmaroli
Copy link
Contributor

Conflicts galore on this branch..

@pyrmont pyrmont force-pushed the bugfix.reduce-ruby-warnings branch from 3aa37e3 to 34d21ce Compare August 9, 2019 15:00
@pyrmont
Copy link
Contributor Author

pyrmont commented Aug 9, 2019

MathWorks have made it so that the webpage with the MatLab functions requires JavaScript… >_<

@pyrmont pyrmont added dependent-pr The PR is dependent on other changes being merged and will be reviewed later. and removed needs-review The PR needs to be reviewed labels Aug 10, 2019
@pyrmont
Copy link
Contributor Author

pyrmont commented Aug 10, 2019

This is dependent on PR #1300.

@pyrmont pyrmont closed this Jan 8, 2020
@pyrmont pyrmont deleted the bugfix.reduce-ruby-warnings branch January 8, 2020 20:08
@pyrmont pyrmont restored the bugfix.reduce-ruby-warnings branch January 8, 2020 20:12
@pyrmont pyrmont reopened this Jan 8, 2020
@hugopeixoto
Copy link
Contributor

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
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.

@@ -13,7 +13,7 @@
}

let(:markdown) {
Redcarpet::Markdown.new(redcarpet.new, :fenced_code_blocks => true)
Redcarpet::Markdown.new(redcarpet.new({}), :fenced_code_blocks => true)
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 this was fixed in 3.5.0, so the change may no longer be needed: vmg/redcarpet@6b86656

@tancnle tancnle added needs-review The PR needs to be reviewed and removed dependent-pr The PR is dependent on other changes being merged and will be reviewed later. labels May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review The PR needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants