Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd ESLint rules from client codebase #1894
Conversation
This comment has been minimized.
This comment has been minimized.
Just a side-note -- (of course a gnarly workaround can be made by physically splitting the translators into header and code files, linting them separately and recombining them if |
This comment has been minimized.
This comment has been minimized.
Oh and personally I'm all for a high level of encouraged consistency in the translators. Given that most new translators seem to be copy-and-change jobs from existing translators, enforcing rules would be low-impact (since they'd be copying fairly clean code after the first major sweep) and it'd not further proliferate bad code styles. |
retorquere
reviewed
Feb 26, 2019
"no-return-await": "error", | ||
"no-script-url": "error", | ||
"no-self-compare": "error", | ||
"no-sequences": "error", | ||
"no-shadow": "off", |
This comment has been minimized.
This comment has been minimized.
retorquere
Feb 26, 2019
Contributor
I can't assess how impactful/useful this would be for Zotero, but this one has saved me on occasion from some confusion.
This comment has been minimized.
This comment has been minimized.
Oh, that's annoying. I guess not making these proper JS files was shortsighted, but we're at least a decade out from that decision, so we're probably stuck with it.
I don't know — it seems fairly trivial to just have a script that splits a translator, runs |
This comment has been minimized.
This comment has been minimized.
It is annoying, and we're also stuck with it. I dunno -- it wouldn't be hard to make a script that just does what the preprocessor does and undoes it after. But it'd be changing files on disk, inside the repo. If it bombs out, it would leave changed files which could accidentally be checked in. |
This comment has been minimized.
This comment has been minimized.
I'm not really concerned with accidental commits — anyone committing should be reviewing the diff first, and |
This comment has been minimized.
This comment has been minimized.
I can have a stab at that. |
This comment has been minimized.
This comment has been minimized.
I'll just do the split to a separate directory and stick that in .gitignore, that should minimize the risk. |
This comment has been minimized.
This comment has been minimized.
I'll wait for #1895 to clear though, it would build on some of those changes. |
This comment has been minimized.
This comment has been minimized.
That's not necessary. The header can just stay in memory, and the code can go in a temp file, and then they can be recombined back into the original file. The temp file can be cleaned up in an exit trap in case something goes wrong. |
This comment has been minimized.
This comment has been minimized.
You mean by running eslint from the script itself? Wouldn't this split off the messages about the header from the rest of the eslint output? Just adding the temp dir to .gitignore would achieve much the same and we could just run eslint as usual. |
This comment has been minimized.
This comment has been minimized.
Yes, we'd just have an eslint-fix script in .ci that took a filename. This is just for running |
This comment has been minimized.
This comment has been minimized.
I don't completely follow, but I think we agree on what we want to achieve and roughly how to do it. |
This comment has been minimized.
This comment has been minimized.
Are we though? What would be the harm from optionally allowing a translator to start with |
This comment has been minimized.
This comment has been minimized.
I don't think it's worth it. We'd have to make changes in many places in many repos, we'd have to either cut off translator updates or send backported translators to older versions, and we'd risk bugs in critical infrastructure, all with very little to be gained. We already have your postprocessor to get ESLint checks working, and making a |
This comment has been minimized.
This comment has been minimized.
I have a wrapperless solution that I'm testing now. |
This comment has been minimized.
This comment has been minimized.
Alright, the results are at https://github.com/retorquere/translators/tree/eslint-split-merge It looks a little baroque, I know, but the current implementation achieves a few goals I think are interesting:
Fix inside editors is not (currently) possible because they must load the plugin processor. |
This comment has been minimized.
This comment has been minimized.
I had forgotten that there are more environments than just the Zotero client that load the translators. |
This comment has been minimized.
This comment has been minimized.
Are the test cases at the end required to be valid JSON or just valid JS? |
This comment has been minimized.
This comment has been minimized.
JSON, from the looks of it, which doesn't really make sense, but they're only ever generated by Scaffold anyway. |
This comment has been minimized.
This comment has been minimized.
That's ok but then the fixer workaround needs to protect them. I'll add that. |
This comment has been minimized.
This comment has been minimized.
It's not that bad an idea -- JSON can be parsed safely using JSON.parse. Otherwise you'd have to get fancy with either sandboxes or esprima or whatnot. I've merged the changes into #1895, and added two test for testCases. Fix now works without touching the header or the testCases. |
This comment has been minimized.
This comment has been minimized.
I have some time available this week and I'd love to plow through the translators based on this. I've done some test and after fix (which I did mostly manually so far), the linter reports quite a few genuine errors. |
This comment has been minimized.
This comment has been minimized.
My weekend looks (reasonably) good, so I can help speed-review & merge. |
This comment has been minimized.
This comment has been minimized.
I take it it is still best if I do one pr per translator? Or do you want them batched at any size? |
This comment has been minimized.
This comment has been minimized.
Unless it's much more work, one per translator is easiest in case there are blockers/questions, so if it doesn't make a difference to you, do that. If you find it takes extra time, batches of 5 are fine, too. And thanks! |
This comment has been minimized.
This comment has been minimized.
Nope, I have a few scripts to manage this process, one per is no problem whatsoever. |
This comment has been minimized.
This comment has been minimized.
What about the existing PRs? Squash or submit new ones? |
This comment has been minimized.
This comment has been minimized.
squash if you don't mind. (you don't even need to squash now that github allows me to do that on merge) |
This comment has been minimized.
This comment has been minimized.
No problem. I know what to do now. |
This comment has been minimized.
This comment has been minimized.
Oh if I don't have to... that saves me updating my scripts. |
dstillman commentedFeb 26, 2019
So this is what the config would be if we added all rules from the client. See #1847 (comment) for context. I don't know whether we care about having this level of conformity in translators.
The warning/error distinction is also fairly arbitrary right now. Some things, particularly spacing rules, are warnings because they appear all throughout the existing client codebase, but conflicts are less of an issue here, so we could just make those errors and fix them, hopefully mostly with
--fix
. Or we might want to reserve errors for things that are more likely to cause bugs, but I'm not really sure what the point of style rules are if we're not going to enforce them consistently.