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 eslint-plugin-userscripts & sort headers #126

Closed
double-beep opened this issue May 16, 2022 · 3 comments
Closed

Use eslint-plugin-userscripts & sort headers #126

double-beep opened this issue May 16, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@double-beep
Copy link
Member

Since 4.15, Tampermonkey uses eslint-plugin-userscripts to validate userscript headers. The docs are here.

It'd be nice if this package used the plugin to lint headers before actually prepending them to the file.

@double-beep double-beep added the enhancement New feature or request label May 16, 2022
@double-beep double-beep moved this to 💡 Idea in Userscripts/projects May 16, 2022
@double-beep double-beep moved this from 💡 Idea to 📝 Todo in Userscripts/projects May 16, 2022
@Oaphi Oaphi self-assigned this May 16, 2022
@Oaphi Oaphi moved this from 📝 Todo to 🚧 In Progress in Userscripts/projects May 16, 2022
@Oaphi
Copy link
Member

Oaphi commented May 16, 2022

Agreed, @double-beep. I've been trying to get it feature-complete first, and since that is mostly out of the way, it's time to look into header linting. That said, most of the rules should be already baked in (if anything supported does not pass, do let me know, I'll review and fix):

Rule Supported Notes
filename-user
no-invalid-grant built-in
no-invalid-metadata built-in
require-name package.json, required
require-description package.json, required
require-version semver validation
use-homepage-and-url package.json + overrides + default
use-download-and-update-url package.json + overrides + default
align-attributes built-in, num spaces configurable
require-attribute-space-prefix built-in
metadata-spacing
no-invalid-headers built-in
compat-grant built-in
compat-headers built-in

As for sorting - I am already looking into it: currently, the headers are sorted alphabetically, but I know that @name header should be the first one according to the linter. That change is coming the next patch release.

@double-beep
Copy link
Member Author

@Oaphi how should we order the headers? I suggest the following (by default):

  • First "group": @name, @namespace, @description, @version (not necessarily in that order)
  • Second "group": @author(s) and @contributors
  • Third "group": @match/@include, @exclude
  • Fourth "group": @connect, @require, @grant and @run-at
  • Fifth "group": The rest

It'd be nice if the user was able to customise the order as well (though I suppose the implementation would be complicated)!

What do you think?

@Oaphi
Copy link
Member

Oaphi commented Jun 28, 2022

@double-beep to avoid making a breaking change, I think the default behavior should be left as is (alphabetical order + @name first as per liner rules), but I like the idea of providing an option to choose different sort options, specifically, the group approach you proposed above. As soon as I am out of the woods with linting (as you can see from commits, it's basically ready, but IRL keeps me from making a few finalizing touches) we can definitely address that!

@Oaphi Oaphi closed this as completed in 3849bcf Jul 3, 2022
Repository owner moved this from 🚧 In Progress to ✔️ Done in Userscripts/projects Jul 3, 2022
@Oaphi Oaphi moved this to Done in Packages/issues Jul 3, 2022
@double-beep double-beep added enhancement New feature or request and removed enhancement New feature or request labels Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Status: ✔️ Done
Development

No branches or pull requests

2 participants