Linter: Implement erb-no-method-definitions rule - #2172
Conversation
0298b09 to
a6e7b7f
Compare
| `) | ||
| }) | ||
|
|
||
| test("ignores lambdas", () => { |
There was a problem hiding this comment.
not sure if we want to catch these
issue description was somewhat specific regarding def ... end blocks, but knowing ruby there are a bunch of other ways to define "methods"
There was a problem hiding this comment.
I think it's fine to leave them for now. If'd want to catch them we could still introduce a new rule specifically for lambdas.
4260a9f to
87e8417
Compare
87e8417 to
76ff309
Compare
There was a problem hiding this comment.
Thanks @markokajzer! 🙏🏼
To only thing to note here is that we can't catch issues like #990 because they are just straight up a parser error.
Though, we might be able to set consumesParserErrors = true on the rule itself, and then, since we can look at the extracted Ruby from that file, detect the method definition that way since then its all valid Ruby again 🤔
|
i didnt even know that was possible haha |
closes #195
Rule:
erb-no-method-definitionsDescription
Disallow defining Ruby methods inside ERB files using
def ... endordefine_method. View templates should only contain logic necessary for rendering the page. Defining methods in ERB mixes concerns and breaks MVC conventions.Rationale
Defining methods in a view template:
Method definitions belong in helpers, presenters, or view components, not in view files.
Examples
✅ Good
🚫 Bad