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

Warn people that Haml 5 is not fully supported #1379

Merged
merged 1 commit into from
Jul 12, 2019

Conversation

jaredbeck
Copy link
Contributor

[Fixes #1370]

I don't have great confidence this is the best implementation, and I'd appreciate feedback.

  • How should I write a test for this? Which test file should it go in?
  • In my test, how do I assert that a Brakeman.notify occurred?

Thanks.

@jaredbeck
Copy link
Contributor Author

jaredbeck commented Jul 10, 2019

The fact that the implementation is messy doesn't bother me too much, because we can delete it all when we add support for Haml 5. (Of course, if it bothers you, please say so) My only real concern so far is that I couldn't figure out how to test it.

Copy link
Owner

@presidentbeef presidentbeef left a comment

Choose a reason for hiding this comment

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

How should I write a test for this? Which test file should it go in?
In my test, how do I assert that a Brakeman.notify occurred?

You can add it to test/tests/brakeman.rb. A bit of a catchall but it has similar tests. I'm not too picky.

You should be able to use assert_output and test that the message went to stderr. There are other examples in the test file.

For this case, you can either test a Brakeman.run on the test app, or you could add tests specifically for Tracker::Config#check_haml_version and Tracker::Config#supported_haml_versionl?.

# known Haml 5 versions and test whether the `Requirement` is satisfied. I
# included '5.99.99' in the list so that this method might stand a chance of
# working in the future.
def supported_haml_version?
Copy link
Owner

Choose a reason for hiding this comment

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

In many cases, there will be an exact gem version from Gemfile.lock.

I am okay with just using version_between? which will handle most cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

version_between? expects a single version number, but all we have is a "requirement", right? Consider the requirement > 4.99. This requirement will install Haml 5. It would be incorrect to ignore the operator and only consider the number, 4.99. version_between? would think it is Haml 4.

Copy link
Owner

Choose a reason for hiding this comment

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

That is an edge case, yes, but again most applications are going to have a lock file with the exact version, not just the requirement.

CHANGES.md Outdated
@@ -6,6 +6,7 @@
* Avoid assigning `nil` line numbers to `Sexp`s
* Add special warning code for custom checks
* Add call matching by regular expression
# Warn people that Haml 5 is not fully supported
Copy link
Owner

Choose a reason for hiding this comment

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

Should be * not #

@@ -111,6 +111,8 @@ def set_rails_version
@escape_html = true
Brakeman.notify "[Notice] Escaping HTML by default"
end

check_haml_version
Copy link
Owner

Choose a reason for hiding this comment

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

Kind of a weird place for this...but I don't know if there is a less weird place.

@jaredbeck
Copy link
Contributor Author

You can add it to test/tests/brakeman.rb.

Test added, thanks for the guidance!

:app_path => "#{TEST_PATH}/apps/rails5.2",
:run_checks => []
}
_out, err = capture_io { Brakeman.run options }
Copy link
Owner

Choose a reason for hiding this comment

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

No need to generate a config file here.

@presidentbeef presidentbeef merged commit 2d8f980 into presidentbeef:master Jul 12, 2019
@jaredbeck jaredbeck deleted the fix_issue_1370 branch July 12, 2019 21:16
Repository owner locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Valid HAML multiline comment produces "Inconsistent indentation" error
2 participants