-
Notifications
You must be signed in to change notification settings - Fork 326
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
Enable ESLint stylistic typed linting in source code #4106
Conversation
Cheers! Not sure it's one we'll merge straight away, but it's good to have the steps to enable it. I'm also wondering if us throwing (rather than returning early) during initialisation will not remove a couple of these "watch out it may be |
cb96638
to
995f5d6
Compare
7b509e6
to
3d7f5fb
Compare
995f5d6
to
9083678
Compare
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for 331d7f0 |
3d7f5fb
to
20ac99f
Compare
9083678
to
30d9e94
Compare
20ac99f
to
af6acc5
Compare
9a24aa2
to
bf23090
Compare
bf23090
to
8fab7f9
Compare
8fab7f9
to
b6ac23b
Compare
b6ac23b
to
7a3411a
Compare
Just rebasing to keep this branch up to date |
Thanks @domoscargin Shame GitHub limits the number of annotations on the Summary (scroll down) But you'll see them all in the logs |
7a3411a
to
b09b44b
Compare
b09b44b
to
ba447e5
Compare
d13d1cc
to
b342721
Compare
f7f9901
to
678bb56
Compare
b342721
to
2c3cfb6
Compare
678bb56
to
bdf0658
Compare
2c3cfb6
to
fc41f25
Compare
fc41f25
to
b36b3de
Compare
bdf0658
to
e66c296
Compare
b36b3de
to
75aa358
Compare
We widely use the shorthand form already where the return value isn’t important
Built source files only, excluding tasks and tests
We have another PR open to discuss these features: #4286 Some ES2015+ features already have browser support or are enabled by Babel transforms
75aa358
to
331d7f0
Compare
JavaScript changes to
|
Other changes to
|
Stylesheets changes to
|
Following dev catch-up this week we agreed to get this PR merged to test things out I've assumed we're undecided on ES2015+ syntax suggestions from #4286 so they're turned off in 331d7f0 @domoscargin @romaricpascal Mind giving this the green tick please? Thanks 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, let's give it a go.
This PR enables ESLint stylistic typed linting
It highlights opportunities to replace older JavaScript with new, but also uses TypeScript
{ "strict": true }
to add warnings when our GOV.UK Frontend source code is too loose or unnecessarily defensiveAs part of #4323 we've already fixed:
null
defaultnull
return values not handlednull
null
astypeof value === 'object'
But this PR includes a few more:
null
attributeNamedNodeMap
valuesnull
element.parentNode
valuesnull
element.textContent
valuesWhilst quite pedantic for internal code, it's a huge safety net as we clarify our public API and catch issues like:
document.body
is not set #4394Stylistic typed linting
This change lets ESLint use types to reduce unnecessary code with suggestions to use modern syntax
Strict mode checks (existing)
Here's a list of the compiler options we already enabled in the past:
strictBindCallApply
– Functionbind
,call
andapply
must be checked (added in 73a706a)strictFunctionTypes
– Function parameters must be checked (added in 73a706a)noImplicitThis
– Context forthis
must be checked (added in 8b3d6f3)Strict mode checks (new)
Here's a list of the compiler options enabled in this PR:
alwaysStrict
– Assume code has"use strict"
strictNullChecks
– Possiblenull
andundefined
must be checkedstrictPropertyInitialization
– Class field values must be checkednoImplicitAny
– All types must be added (e.g. in JSDoc)noUncheckedIndexedAccess
– Array and object key/values must be checkeduseUnknownInCatchVariables
– Assume errors are unknown untilerror instanceof