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

Use erubi instead of erubis, upgrade haml/haml_lint #18868

Closed

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Jun 14, 2019

Fixes deprecation:

DEPRECATION WARNING: ActionView::Template::Handlers::Erubis is
deprecated and will be removed from Rails 5.2. Switch to
ActionView::Template::Handlers::ERB::Erubi instead. (called from <top
(required)> at
/Users/joerafaniello/Code/manageiq/config/application.rb:31)

Rails changed their default templating engine from erubis to erubi and
started deprecating it in 5.1:
rails/rails#27757

Even though we're only using erubis in WinRM, which is outside of
actionview, we're getting the deprecation because:

  1. We require hamlit in our Gemfile
  2. hamlit tries to require haml in the template here
  3. It loads the haml railtie
  4. Which loads the erubis template:
    https://github.com/haml/haml/blob/4.0.7/lib/haml/railtie.rb#L21
  5. Which autoloads the deprecated constant:
    https://github.com/haml/haml/blob/4.0.7/lib/haml/helpers/safe_erubis_template.rb#L3

Haml 5.0.0 fixes this loading of the deprecated constant:
haml/haml#895

Fixes deprecation:
```
DEPRECATION WARNING: ActionView::Template::Handlers::Erubis is
deprecated and will be removed from Rails 5.2. Switch to
ActionView::Template::Handlers::ERB::Erubi instead. (called from <top
(required)> at
/Users/joerafaniello/Code/manageiq/config/application.rb:31)
```

Rails changed their default templating engine from erubis to erubi and
started deprecating it in 5.1:
rails/rails#27757

Even though we're only using erubis in WinRM, which is outside of
actionview, we're getting the deprecation because:

1) We require hamlit in our Gemfile
2) It requires haml
3) It loads the haml railtie
4) Which loads the erubis template:
https://github.com/haml/haml/blob/4.0.7/lib/haml/railtie.rb#L21
5) Which autoloads the deprecated constant:
https://github.com/haml/haml/blob/4.0.7/lib/haml/helpers/safe_erubis_template.rb#L3

Haml 5.0.0 fixes this loading of the deprecated constant:
haml/haml#895
@jrafanie jrafanie requested a review from himdel June 14, 2019 00:54
@jrafanie
Copy link
Member Author

Extracted from #18076

@jrafanie
Copy link
Member Author

@himdel do you know how to verify this on master? It's needed for rails 5.1 but I'd like to get this in since it should be compatible with 5.0.

@jrafanie jrafanie mentioned this pull request Jun 14, 2019
9 tasks
@miq-bot
Copy link
Member

miq-bot commented Jun 14, 2019

Checked commit jrafanie@2c50725 with ruby 2.3.3, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 1 offense detected

Gemfile

  • ❗ - Line 47, Col 1 - Bundler/OrderedGems - Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem haml should appear before hamlit.

@bdunne
Copy link
Member

bdunne commented Jun 14, 2019

@jrafanie Do these dependencies belong in manageiq-ui-classic?

@jrafanie
Copy link
Member Author

jrafanie commented Jun 14, 2019

@jrafanie Do these dependencies belong in manageiq-ui-classic?

Honestly, I don't remember why haml-lint/hamlit were dependencies here. Maybe @himdel @mzazrivec @skateman know? Maybe we had some rake task here that was moved to ui-classic and those dependencies can now move? 🙏

Note, at one time, we were choosing to use hamlit over haml, it's unclear why it's loading haml from hamlit unless hamlit just replaces/wraps some parts of haml but still depends on it. 🤷‍♂

#3690
#5646
#9167

@skateman
Copy link
Member

@jrafanie hamlit used to be faster than haml, I think it's okay to move the stuff to the ui-classic repo.

@mzazrivec
Copy link
Contributor

hamlit used to be faster than haml

It used to be faster? As in it's no longer true?

@skateman
Copy link
Member

@mzazrivec according to their latest benchmarks, it still is. The parser is the same though.

@mzazrivec
Copy link
Contributor

OK. Anyway, we don't need these 3 gems in core, do we?

@skateman
Copy link
Member

@mzazrivec well, I'm not sure about erubi but the other 2 could live in ui-classic.

@himdel
Copy link
Contributor

himdel commented Jun 17, 2019

If this is switching us back to haml, we will have problems.

haml and hamlit are not compatible, they treat %div{:foo => true} and %div{:foo => false} differently.

@jrafanie
Copy link
Member Author

If this is switching us back to haml, we will have problems.

It's been a few months since I worked on this. Let me double check my logic in the description. I don't see how haml was being required in the first place. I don't know how much of haml was being used and where but it was definitely loading the haml railtie which led to the deprecation warning. Maybe only in test or dev mode? Let me clarify and update this.

@jrafanie jrafanie changed the title Use erubi instead of erubis, upgrade haml/haml_lint [WIP] Use erubi instead of erubis, upgrade haml/haml_lint Jun 17, 2019
@miq-bot miq-bot added the wip label Jun 17, 2019
@jrafanie
Copy link
Member Author

So, the problem is hamlit tries to require haml in the template here and because we have haml in our dependency tree due to haml_lint (for dev), it will be able to require it. Because this causes the rails 5.1 deprecated constant to be loaded, we get this deprecation warning.

Since haml_lint doesn't have a version that forces haml >= 5.0 (where this is fixed), we have to either:

  • add haml it as a direct dependency so we can say >= 5.0 (like this PR)
  • drop haml_lint entirely (so haml doesn't get in the dependency tree)
  • close this PR and ignore/live with this warning whenever you run tests or rails server/console/etc.

@mzazrivec @skateman @himdel I was trying to get rid of this warning before rails 5.1 lands in master and everyone sees this and wastes time looking at it. My point is even if we're not using haml in dev, it is being required... so we should verify the assertion that we are indeed using hamlit and not haml.

Let me know what you'd like to do.

@jrafanie jrafanie changed the title [WIP] Use erubi instead of erubis, upgrade haml/haml_lint Use erubi instead of erubis, upgrade haml/haml_lint Jun 17, 2019
@skateman
Copy link
Member

I'm okay with getting rid of all the linters from the repo, we can just move them to our Gemfile.dev.rb and problem solved. I don't think anyone else uses haml-lint except of me on a daily basis :trollface:

@miq-bot miq-bot removed the wip label Jun 17, 2019
@jrafanie
Copy link
Member Author

I'm okay with getting rid of all the linters from the repo, we can just move them to our Gemfile.dev.rb and problem solved. I don't think anyone else uses haml-lint except of me on a daily basis :trollface:

This is the correct answer 😆 PLEASE!

@himdel
Copy link
Contributor

himdel commented Jun 18, 2019

Sorry for the lag...

@himdel do you know how to verify this on master?

Yup, the difference between haml and hamlit is essentially this:

$ haml -s
%div{:foo => true, :bar => false, :quux => '', :baz => nil}
  Whatever
^D
<div foo quux=''>
Whatever
</div>

vs

$ hamlit compile -
%div{:foo => true, :bar => false, :quux => '', :baz => nil}
  Whatever
^D
_buf = []; _buf << ("<div bar='false' baz='' foo='true' quux=''>\nWhatever\n</div>\n".freeze); 
; _buf = _buf.join("".freeze)

.. so,

-haml
+hamlit
-<div foo quux=''>
+<div bar='false' baz='' foo='true' quux=''>

Adding such a thing in app/views/dashboard/show.html.haml gives me the latter
=> confirming this PR still uses hamlit 👍

@himdel
Copy link
Contributor

himdel commented Jun 18, 2019

Do these dependencies belong in manageiq-ui-classic?

Heh heh, that's the reason issue #1 is still open :).
ManageIQ/manageiq-ui-classic#1 (comment)

Theoretically we should not be needing haml or hamlit in core.

(And I agree with @skateman that we don't really use the linters in a task or on travis, so they can go.)

@himdel
Copy link
Contributor

himdel commented Jun 18, 2019

So... idk.. I'm fine with this as is,
but if dropping haml-lint achieves the same.. even better :) (I think :))

@jrafanie
Copy link
Member Author

Ok, @skateman @himdel I'll drop the haml_lint in a followup PR. It doesn't look like hamlit uses erubis/erubi so we should be good to go. Thanks for helping me through the background on this one!

@jrafanie jrafanie closed this Jun 18, 2019
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Jun 18, 2019
Followup to ManageIQ#18868

This a development dependency that can be added individually for anyone
who needs it.

The problem is `hamlit` tries to require `haml` in the template
[here](https://github.com/k0kubun/hamlit/blob/94b14839cd42e8b70715ba7c0caf18c2c47ec67a/lib/hamlit/template.rb#L8)
and because we have `haml` in our dependency tree due to `haml_lint` (for dev), it will be able to require it.
Because this causes the rails 5.1 deprecated constant to be loaded, we get this deprecation warning:

```
DEPRECATION WARNING: ActionView::Template::Handlers::Erubis is
deprecated and will be removed from Rails 5.2. Switch to
ActionView::Template::Handlers::ERB::Erubi instead. (called from <top
(required)> at
/Users/joerafaniello/Code/manageiq/config/application.rb:31)
```

Since haml_lint doesn't have a version that forces haml >= 5.0 (where this is fixed), we have to either:
* add haml it as a direct dependency so we can say >= 5.0 (like this PR)
* drop haml_lint entirely (so haml doesn't get in the dependency tree)
* ignore/live with this warning whenever you run tests or rails server/console/etc.

This commit takes option 2, drop haml_lint since it's a dev dependency
that can easily be added in bundler.d directory for any developers who want it.
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Jun 18, 2019
Followup to ManageIQ#18868

This a development dependency that can be added individually for anyone
who needs it.

The problem is `hamlit` tries to require `haml` in the template
[here](https://github.com/k0kubun/hamlit/blob/94b14839cd42e8b70715ba7c0caf18c2c47ec67a/lib/hamlit/template.rb#L8)
and because we have `haml` in our dependency tree due to `haml_lint` (for dev), it will be able to require it.
Because this causes the rails 5.1 deprecated constant to be loaded, we get this deprecation warning:

```
DEPRECATION WARNING: ActionView::Template::Handlers::Erubis is
deprecated and will be removed from Rails 5.2. Switch to
ActionView::Template::Handlers::ERB::Erubi instead. (called from <top
(required)> at
/Users/joerafaniello/Code/manageiq/config/application.rb:31)
```

Since haml_lint doesn't have a version that forces haml >= 5.0 (where this is fixed), we have to either:
* add haml it as a direct dependency so we can say >= 5.0 (like this PR)
* drop haml_lint entirely (so haml doesn't get in the dependency tree)
* ignore/live with this warning whenever you run tests or rails server/console/etc.

This commit takes option 2, drop haml_lint since it's a dev dependency
that can easily be added in bundler.d directory for any developers who want it.
@jrafanie
Copy link
Member Author

Ok, I opened #18886 after confirming that dropping just haml_lint fixes this warning. Thanks all!

@jrafanie jrafanie deleted the fix_rails_51_erubis_deprecation branch July 15, 2022 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants