Linter: Implement erb-no-module-definitions rule - #2170
Conversation
0ad2adb to
346d83f
Compare
| module DisplayHelpers | ||
| def highlight(text) | ||
| "<mark>#{text}</mark>".html_safe | ||
| end | ||
| end |
There was a problem hiding this comment.
lets use a different example here. Promoting .html_safe is not great, especially since this could become a problem if highlight gets called with user-controlled data.
Maybe an example with like pluralize could work?
There was a problem hiding this comment.
switched to pluralize for example and specs, and used a more generic error message 🙏
let me know if any other changes are necessary!
i'm currently running against a few repos of https://github.com/steveclarke/real-world-rails, and i'm slowly adding more of them to have a wider base of examples. if you have a good one, feel free to suggest 👀
There was a problem hiding this comment.
@markokajzer directly related: https://github.com/marcoroth/herb-corpus
We are running against this corpus on every commit, at least for the parse + printer, but not the linter yet.
34fd701 to
ebd7c70
Compare
ebd7c70 to
831cfbe
Compare
marcoroth
left a comment
There was a problem hiding this comment.
Sweet, thank you @markokajzer! 🙏🏼
closes #197
Rule:
erb-no-module-definitionsDescription
Disallow Ruby
module ... enddefinitions inside ERB templates.Rationale
Modules introduce reusable application structure, which belongs in a helper, library, or initializer rather than a view. Defining one while rendering a template can pollute the view context, prevents normal autoloading, and makes the template harder to understand and reuse.
Examples
✅ Good
🚫 Bad