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

Add a lint plugin for detecting common anti-patterns #66

Closed
1 of 8 tasks
lambda-fairy opened this issue Dec 4, 2016 · 7 comments
Closed
1 of 8 tasks

Add a lint plugin for detecting common anti-patterns #66

lambda-fairy opened this issue Dec 4, 2016 · 7 comments

Comments

@lambda-fairy
Copy link
Owner

lambda-fairy commented Dec 4, 2016

We can lint these things:

  • Use maud::DOCTYPE instead of PreEscaped("<!DOCTYPE html>")

  • Rather than writing output.push_str(&html! { ... }.into_string()), just implement the render method instead

  • Use format_args! (or list the values individually) instead of format!

The following lints inspect the structure of the template itself. It's not clear yet how they can be implemented under the current design. We'll probably need to do some refactoring before these can work.

  • Use .foo instead of class="foo", and #foo instead of id="foo"

    • Use .foo[bar] instead of class=@if bar { "foo" }
  • Warn against a target="..." without rel="noopener"

  • Warn against dynamic data in CSS and JS contexts, e.g. script { "var name = '" (user.name) "'" }

  • Warn about non-standard elements and attributes

Further suggestions welcome!

@ernestas-poskus
Copy link
Contributor

thus elements that contains empty tags like id="" or class="" could be removed to minimize html size

@lambda-fairy
Copy link
Owner Author

@ernestas-poskus that can be extended to other attributes like style and rel as well

@ernestas-poskus
Copy link
Contributor

that can be extended to other attributes like style and rel as well

sure, all empty tags could be removed

@lambda-fairy
Copy link
Owner Author

sure, all empty tags could be removed

Not all of them. <script> tags are almost always empty, for example. Empty tags can also be used as hooks for scripts and styling. And on an <img> tag, an empty alt attribute and a missing alt attribute have different meanings.

@lambda-fairy
Copy link
Owner Author

I have started improving the lint plugin on the better-lints branch. When I'm done, the proc macro will use compile-time "markers" to communicate the structure of the original template to the lint plugin.

@lambda-fairy
Copy link
Owner Author

#127 🎉

@lambda-fairy
Copy link
Owner Author

This issue has become a bit of a laundry list of suggestions. It's unclear how half of these can be implemented on stable (given that third-party lints are so far away) and the tractable stuff has already been split out (e.g. #181). So I'm going to close this as wontfix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants