Problem/Motivation
In order to fix our eslintrc rules we need to execute the following steps:
- Make the current .eslintrc compliant with our current code
- Therefore we will exclude all rules which rules currently don't follow
- As next step we will create a meta issue which is the hub to fix every previously excluded rule
- Fix each rule, by removing the exclusion from the .eslintrc.json file and fixing all the instances
As first step we determine all the rules which don't work right now:
node ./node_modules/eslint/bin/eslint.js --format=json --ext=.es6.js . | jq '[.[] | .messages[] | .ruleId]' | sort | uniq -c | sort -r | pbcopy
469 "func-names",
146 "no-mutable-exports",
121 "no-unused-vars",
75 "no-use-before-define",
70 "max-len",
66 "camelcase",
54 "no-restricted-syntax",
42 "no-shadow",
35 "newline-per-chained-call",
24 "vars-on-top",
24 "no-var",
24 "no-mixed-operators",
19 "no-useless-escape",
18 "new-cap",
16 "no-plusplus",
16 "default-case",
14 "no-multi-assign",
9 "no-new",
9 "no-continue",
6 "prefer-const",
3 "prefer-rest-params",
2 "padded-blocks",
2 "no-lonely-if",
2 "no-confusing-arrow",
2 "comma-dangle",
2 "array-callback-return",
1 "no-var"
1 "no-useless-concat",
1 "no-throw-literal",
1 "no-empty",
Proposed resolution
Add a .eslintrc.passing.json which extends our existing .eslintrc.jsonfile and ensures that everything is passing. Over time we can then reduce overridden rules, while not affecting new JS files to have less coverage.
Remaining tasks
User interface changes
:
API changes
Data model changes
Comments
Comment #2
dawehnerHere is a patch to turn everything off.
Comment #3
dawehnerComment #4
dawehnerComment #5
droplet commentedThis is a very bad idea. The testbot could bypass it with a custom config.
It just introduces more errors on new JS patches since the local editor lost error hints
Comment #6
dawehnerI was talking with @drpal earlier. We had an idea which introduces a second file , so people can continuously work on fixing the existing style errors, while new JS patches don't have issues.
Comment #7
dawehnerComment #9
dawehnerThis time with the right file.
Comment #10
droplet commentedComment #11
droplet commentedDon't want to hijack your guys' work and slow down the progress. But if we only used these commands temporarily. Adding a -prefix would make less confusing to other contributors. They won't adopt it to their contrib projects.
And this is make more sense to fix Errors first (and may be only)
Some rules, for example, the "no-mutable-exports". IMO, this is not useful for the CORE but good for Contrib. It seems not right to remove it from CORE .eslintrc forever. We might have to discuss in somewhere.
Attached a stat script. IMO, it's good to commit it with this issue together (, rather than chop into a new issue).
Note 1: I have a codemod for camelcase, let me know if you need my help. Cheers!
Note 2: There are few rules are formatting errors, eg. max-len, newline-per-chained-call, padded-blocks. IMO, we should group it in one slot. It's hard to introduce new bugs!
Comment #12
dawehnerIsn't that what the patch is doing right now?
That is a fair point. At least for me its all about actually sticking to rules and don't reintroduce new problems, no matter whether its errors or just warnings.
I'm glad the numbers you produced are the same as the one I put into the issue summary for myself. Yeah!
Have a look at #2912962: Step 1 JS codestyle: [meta] Fix JS coding standards in core how we can make the life easy for committers. We will have one issue per rule, so I guess you could open up the camelcase rule
At least from my point of view we should fix one rule per issue, as otherwise reviews would be harder. Please let's optimize for reviews, as this is the rare resource.
Comment #13
droplet commentedI mean a prefix like: "temp:lint:core-js-whatever'
I will wait for your guy do the first and then I copy it. BTW, I think camelcase will be the last to resolve. Renaming the var/prop is API changes in many cases. It will break contrib. (or D8.5 only)
👍👍👍
If committers stick with the policy, 3 days per commit, it would be ultra slow and that means each time invalidate our other patches again. The re-roll game is not fun :)
The reason I trying to group them together is to lower the conflicts between patches and easier for commit.
The history told me it's not good. We failed at JS native selectors clean up, some JS winter cleanup/ rewrite, and the recent CSS clean up. (Strictly, I think the Theme CSS standard (to BEM) has failure also)
https://www.drupal.org/node/2865971#comment-12098104 (4 months, zero new commits)
Comment #14
dawehnerAh I see, yeah why not :)
I doubt this is a policy :)
Let's ask the core committers how they would like to handle this kind of process. I agree though no matter how you do it, it will cause pain for someone.
Comment #15
GrandmaGlassesRopeMan#11
Awesome. I've included it with just a bit of code-style cleanup.
---
@dawehner I modified your latest patch slightly. I don't think we should be excluding warnings. They shouldn't cause the test bot to fail and most of them aren't critical. I also added
indentto the ignore list; it appeared to be missing initially.Comment #16
dawehner👍
@droplet @drpal Can we remove the "Needs subsystem maintainer review" tag?
Comment #17
GrandmaGlassesRopeManYes.
Comment #18
GrandmaGlassesRopeManI've removed the need for
Needs subsystem maintainer review. However this should probably result in a change record since we are temporarily changing our existing rules for linting JavaScript.Comment #19
droplet commentedThanks @drpal. Yeah, that stat script can improve a bit still. But as a temp script, I will leave it as it :)
We only change the testbot, I guess? No? It's loose version of our CORE standard. It's okay to without change record I think.
Comment #20
droplet commentedMake it easier to review
Manual Interdiff:
- Removed
indent- Add
--quietto mute warning reportComment #21
GrandmaGlassesRopeMan@droplet How come we don't want to track
indentissues?Comment #22
droplet commentedI removed indent and run, no errors. (D8.5)
Comment #23
dawehnerFor me instead of arguing whether we want a change record or not, we could just create one and let the core committers decide whether its worth publishing that one: https://www.drupal.org/node/2913464
Here is the interdiff for #20
Comment #24
GrandmaGlassesRopeMan@droplet I applied the patch from #20 against
12a28a5ebaand there are still 21 errors with indentation.Comment #25
droplet commentedAhh. I think you running the new version: #2910705: Update JS Build Script Packages (I notice that before)
Okay. We could add it back for future.
** And there some new autofix in the new ESLINT
Comment #26
GrandmaGlassesRopeMan@droplet
Yep. I was running a
4.x.xbranch ofeslint. I'm fine with this as it is right now and if we ever get around to updating the dependencies we can just adjust these rules then.Comment #27
droplet commentedOnce this issue gets committed, I will publish 9 new issues. These issues I picked has less controversial (and try to avoid patch conflicts), we can commit them straightforward usually. 🚀🚀🚀🚀🚀
Comment #28
dawehnerThank you @droplet
Let's ensure that you stick it under the Step 1 issue so the core committers can track process.
Comment #29
GrandmaGlassesRopeMan👏
Comment #31
lauriiiThis seems like a good way to help the process of fixing the coding standard violations.
Committed d0fa5b7, pushed to 8.5.x and published the change record. Thanks!
Comment #33
quietone commentedpublish the change record