☂️ Clean up eslint usage - remove 'legacyCode' ignoring
See original GitHub issue☂️ This is an epic / umbrella issue We expect this to be done in multiple PRs as it’s better to change a few pages at a time, please reference this issue in any new PRs
Description
- As part of the ongoing improvements to the Wagtail frontend codebase the plan is to ensure that new code and existing code can adopt the baseline eslint rules.
- The goal is to incrementally clean up eslint rules, with mostly adopting the rules provided by https://github.com/wagtail/eslint-config-wagtail and adjusting that repo if needed.
- This is so that newer code can be written without ignoring too much and to get to the bottom of which rules are not really ‘legacy’ rules.
Approach
Part 1 - Remove unnecessary rules or rules that are formatting fixes only
- https://github.com/wagtail/wagtail/pull/8734
- https://github.com/wagtail/wagtail/pull/8736
- https://github.com/wagtail/wagtail/pull/8737
Part 2 - Move some rules to global ignore as they really do not suit existing code approaches
- https://github.com/wagtail/wagtail/pull/8738
- Note: May want to add issues/PRs to adopt some of the global rules in eslint-wagtail
- May be others
Part 3 - Assess small fixes when removing linting rules
- There may be some rules that are quick wins and only require one or two changes/fixes to files
Part 4 - Try to scope overrides rules: legacyCode,
to specific files
- There may be rules ignored via
legacyCode
that are harder to fix by only really touch one or two files, try to ignore these explicitly instead of whole folders like entrypoints/utils
Links
Issue Analytics
- State:
- Created a year ago
- Comments:19 (19 by maintainers)
Top Results From Across the Web
Ignoring Code - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Command Line Interface - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Rules - ESLint - Pluggable JavaScript Linter
Rules are the core building block of ESLint. A rule validates if your code meets a certain expectation, and what to do if...
Read more >Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Configuration Files - ESLint - Pluggable JavaScript Linter
JavaScript - use .eslintrc.js and export an object containing your ... If you are using one configuration file and want ESLint to ignore...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was just studying up on eslint and was getting ready to dive in! 😝
Oh well, another time! 😁
@Lovelyfin00 there is one small chunk left, it would be great if you could pick this up if you get the chance this week.
Step 1 - remove legacy rules
This whole block can be removed now.
Step 2 - Remove legacy overrides
This block can also be removed
Step 3 - Add back two ignore rules for components
Add back
no-continue
andno-restricted-syntax
to the components ignoring - I did a bit of digging and the changes needed here to satisfy these rules would take a long time and will not give us a big benefit.Step 4 - run fix & format
Now run
npm run lint:js -- --fix
This will run the eslint fixer to fix up a few automatic things (no-else-return items)
Then run
npm run format
to clean up any odd formatting from EslintStep 5 - Ignore a few inline items
These two files will flag a linting warning
default-param-last
- but to refactor this code to meet the eslint rules will require a rethink of a key part of the redux structure in this code and is not worth it - just add an inline ignore.Try to do it inline like this for them - it reads a bit better
Step 6 - The actual clean up bit 😃
Once you have done this, running
npm run lint
should expose only a few small linting items to fix up.All of these problems are with the usage of
for in...
loops, give a go at changing them to array methods (such as myArray.forEach or myArray.map or myArray.some / find).For example, here is how we could solve the issue in
page-editor.js
original
proposed
I realise this is a bit odd as we are still disabling a rule but there may be a better way with jquery to set a hidden attribute.
Recap
It’s 100% ok if we have to ignore a few discrete files for a specific rule here and there. The reason we want to finish this is so that we do not have to much ‘blanket’ ignoring of entire files or areas of code if it can be avoided.
So even if you end up fixing 1 or 2 of the files from step 6 above - that’s all good.