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

[eslint] enable type-specific lint rules #114184

Merged
merged 10 commits into from
Nov 3, 2021

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Oct 6, 2021

Fixes #114175

Enables ESLint rules which require types in a separate eslint config. This requires that we run ESLint separately in every typescript project, but it gives us access to very powerful ESLint rules like:

  • @typescript-eslint/prefer-export-type: prevents using standard export statements to export types, which bloats bundles when unnecessary exports are left behind by babel and gets us closed to being able to enable isolatedModules: true on all TS Projects. This rule is enabled by this PR and autofixed in all code.
  • @typescript-eslint/no-floating-promises: allows us to check that promises are handled when they are created. This rule is not enabled by this plugin but will be the next focus, ideally we will be able to provide contributors with a method for enabling this rule in their plugin and fixing the violations if they decide they want to do so. We can also enable it in all plugins which have few or no issues to prevent new issues from popping up.

One drawback of this approach is that the code is being linted by ESLint twice, which it doesn't love. Unexpected /* eslint-disable* directives make it upset and it requires that we disable the inline directives for this config. Because of this I plan to create a POC which runs all of our ESLint configs this way so we can get back to a single ESLint config for each file. It requires config files in every plugin so that editors can load the correct config for each file, and it might not even work then, but we'll see if we can get it working.

The command implemented in this PR is:

node scripts/eslint_with_types

Run ESLint in each TS project, feeding it the TS config so it can validate our code using the type information

Options:
  --project          Only run eslint on a specific ts project
  --fix              Run eslint in --fix mode
  --verbose, -v      Log verbosely
  --debug            Log debug messages (less than verbose)
  --quiet            Only log errors
  --silent           Don't log anything
  --help             Show this message

@spalger spalger added the Team:Operations Team label for Operations Team label Oct 6, 2021
@elastic elastic deleted a comment from kibanamachine Oct 16, 2021
@spalger spalger force-pushed the implement/type-specific-linting branch 3 times, most recently from 2b53991 to 53d7fd7 Compare November 1, 2021 07:08
@spalger spalger force-pushed the implement/type-specific-linting branch from 8ebbfb1 to ed5dcd9 Compare November 1, 2021 17:57
@spalger
Copy link
Contributor Author

spalger commented Nov 1, 2021

@elasticmachine merge upstream

@spalger spalger marked this pull request as ready for review November 1, 2021 22:22
@spalger spalger requested a review from a team as a code owner November 1, 2021 22:22
@spalger spalger requested review from a team November 1, 2021 22:22
@spalger spalger requested review from a team as code owners November 1, 2021 22:22
Copy link
Member

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infra and monitoring plugin code changes LGTM

Copy link
Contributor

@mshustov mshustov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this.

@mshustov
Copy link
Contributor

mshustov commented Nov 2, 2021

@typescript-eslint/no-floating-promises: allows us to check that promises are handled when they are created. This rule is not enabled by this plugin but will be the next focus,

@spenceralger should we create a meta-issue to track the effort? or will plugins be able to add it on a voluntary basis?

@spalger
Copy link
Contributor Author

spalger commented Nov 3, 2021

@typescript-eslint/no-floating-promises: allows us to check that promises are handled when they are created. This rule is not enabled by this plugin but will be the next focus,

@spenceralger should we create a meta-issue to track the effort? or will plugins be able to add it on a voluntary basis?

I'm not planning on forcing plugins to enable it as of right now, but I think it's a reasonable initiative if folks think it's a good idea. The plan is for plugins to opt-into for now.

Copy link
Contributor

@dasansol92 dasansol92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Solution Management changes LGTM!

Copy link
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ML and Transform changes LGTM

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code only review, Presentation team changes LGTM! Super exciting change

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VisEditors changes LGTM

Copy link
Contributor

@mattkime mattkime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kibana app services change lgtm

@spalger
Copy link
Contributor Author

spalger commented Nov 3, 2021

@elasticmachine merge upstream

Copy link
Contributor

@smith smith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APM changes look good.

Copy link
Contributor

@patrykkopycinski patrykkopycinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asset management LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
advancedSettings 52 51 -1
bfetch 26 25 -1
canvas 1036 1034 -2
charts 66 65 -1
customIntegrations 18 17 -1
dashboard 275 270 -5
dashboardEnhanced 34 32 -2
data 505 500 -5
dataVisualizer 310 306 -4
embeddable 77 73 -4
embeddableEnhanced 11 10 -1
enterpriseSearch 1355 1354 -1
esUiShared 160 158 -2
expressions 161 160 -1
features 11 9 -2
fleet 528 526 -2
globalSearch 24 21 -3
globalSearchBar 24 23 -1
indexManagement 492 485 -7
infra 934 931 -3
ingestPipelines 451 449 -2
inputControlVis 106 104 -2
kibanaOverview 26 25 -1
kibanaReact 308 307 -1
kibanaUtils 166 160 -6
lens 673 670 -3
lists 295 293 -2
maps 802 797 -5
mapsEms 137 135 -2
ml 1591 1586 -5
navigation 18 16 -2
newsfeed 15 14 -1
observability 343 341 -2
presentationUtil 268 263 -5
runtimeFields 18 17 -1
savedObjects 42 39 -3
savedObjectsManagement 78 74 -4
savedObjectsTagging 91 88 -3
savedObjectsTaggingOss 13 10 -3
screenshotMode 8 7 -1
searchprofiler 82 81 -1
security 410 403 -7
securitySolution 2755 2750 -5
timelines 304 302 -2
transform 235 234 -1
uiActions 27 25 -2
uiActionsEnhanced 161 159 -2
uptime 644 641 -3
visualizations 83 82 -1
visualize 63 61 -2
total -129

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
canvas 971.8KB 971.5KB -276.0B
cases 310.2KB 310.2KB -9.0B
customIntegrations 3.4KB 3.3KB -30.0B
dashboard 275.7KB 275.6KB -10.0B
dataVisualizer 521.2KB 521.1KB -126.0B
fileUpload 668.4KB 671.6KB +3.2KB
fleet 615.1KB 615.1KB -4.0B
indexManagement 515.7KB 515.7KB -2.0B
indexPatternFieldEditor 139.4KB 139.4KB -4.0B
infra 922.9KB 921.8KB -1.1KB
lens 955.8KB 955.4KB -377.0B
licenseManagement 63.6KB 63.6KB -40.0B
maps 2.6MB 2.6MB +7.0B
ml 3.5MB 3.5MB -1.7KB
osquery 934.9KB 934.9KB -14.0B
reporting 45.6KB 45.5KB -74.0B
savedObjectsTagging 40.5KB 40.5KB +2.0B
securitySolution 4.5MB 4.5MB -26.0B
timelines 236.6KB 236.6KB -1.0B
transform 326.8KB 326.8KB -9.0B
triggersActionsUi 776.8KB 776.8KB +7.0B
upgradeAssistant 103.8KB 103.8KB -6.0B
total -542.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
advancedSettings 5.7KB 5.7KB -92.0B
apm 29.4KB 29.3KB -78.0B
bfetch 7.5KB 7.4KB -165.0B
canvas 17.2KB 17.0KB -212.0B
cases 80.4KB 80.2KB -177.0B
charts 57.1KB 56.1KB -1.1KB
cloud 6.6KB 6.5KB -75.0B
customIntegrations 6.2KB 6.1KB -96.0B
dashboard 65.0KB 64.4KB -620.0B
dashboardEnhanced 14.5KB 14.1KB -376.0B
data 435.1KB 431.0KB -4.1KB
dataEnhanced 9.4KB 9.3KB -84.0B
dataViews 37.9KB 37.4KB -608.0B
dataVisualizer 10.1KB 10.1KB -50.0B
discover 22.8KB 22.4KB -446.0B
embeddable 65.0KB 63.4KB -1.6KB
embeddableEnhanced 6.8KB 6.5KB -325.0B
esUiShared 122.9KB 122.2KB -677.0B
expressions 86.9KB 86.4KB -505.0B
features 4.2KB 3.4KB -787.0B
fieldFormats 47.6KB 46.2KB -1.4KB
fileUpload 11.2KB 7.4KB -3.8KB
fleet 106.1KB 105.3KB -816.0B
globalSearch 8.6KB 8.1KB -552.0B
indexLifecycleManagement 28.0KB 28.0KB -41.0B
indexManagement 27.2KB 27.1KB -51.0B
indexPatternEditor 10.8KB 10.6KB -139.0B
indexPatternFieldEditor 18.9KB 18.6KB -284.0B
indexPatternManagement 4.2KB 4.1KB -104.0B
inspector 22.9KB 22.3KB -660.0B
kbnUiSharedDeps-srcJs 3.8MB 3.8MB -229.0B
kibanaOverview 15.6KB 15.5KB -100.0B
kibanaReact 63.1KB 62.8KB -258.0B
kibanaUtils 71.9KB 67.3KB -4.7KB
lens 38.9KB 38.9KB -40.0B
licenseManagement 10.3KB 10.2KB -110.0B
management 10.1KB 9.8KB -255.0B
maps 41.2KB 40.7KB -550.0B
mapsEms 4.3KB 4.1KB -183.0B
ml 34.5KB 33.6KB -844.0B
navigation 8.8KB 8.7KB -183.0B
newsfeed 9.9KB 9.7KB -173.0B
observability 38.0KB 37.8KB -194.0B
osquery 7.0KB 6.8KB -177.0B
presentationUtil 62.3KB 61.3KB -1.0KB
remoteClusters 7.4KB 7.3KB -50.0B
runtimeFields 11.4KB 11.0KB -405.0B
savedObjects 31.1KB 30.5KB -654.0B
savedObjectsManagement 16.2KB 15.3KB -897.0B
savedObjectsTagging 18.1KB 17.8KB -288.0B
savedObjectsTaggingOss 3.1KB 2.4KB -714.0B
screenshotMode 2.0KB 1.9KB -100.0B
security 49.8KB 49.3KB -460.0B
securitySolution 253.2KB 252.9KB -328.0B
share 53.3KB 52.9KB -333.0B
spaces 20.2KB 20.2KB -84.0B
timelines 156.8KB 156.6KB -273.0B
triggersActionsUi 51.6KB 51.6KB -8.0B
uiActions 19.5KB 19.0KB -513.0B
uiActionsEnhanced 22.5KB 21.7KB -830.0B
upgradeAssistant 16.9KB 16.7KB -134.0B
visDefaultEditor 19.2KB 19.0KB -150.0B
visTypePie 13.8KB 13.7KB -106.0B
visTypeTimelion 10.3KB 10.3KB -51.0B
visTypeXy 40.1KB 39.7KB -419.0B
visualizations 36.0KB 35.2KB -866.0B
visualize 15.8KB 15.7KB -129.0B
total -36.2KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @spalger

@spalger
Copy link
Contributor Author

spalger commented Nov 3, 2021

Thanks to everyone who reviewed this, the changes still requiring reviews are all made automatically by well a tested eslint rule. I'm going to merge to prevent a 5th conflict resolution today.

@spalger spalger merged commit 4385ac4 into elastic:main Nov 3, 2021
@spalger spalger deleted the implement/type-specific-linting branch November 3, 2021 22:56
@spalger spalger added the auto-backport Deprecated - use backport:version if exact versions are needed label Nov 3, 2021
@kibanamachine
Copy link
Contributor

💔 Backport failed

Status Branch Result
8.0 Commit could not be cherrypicked due to conflicts
7.16 Commit could not be cherrypicked due to conflicts

To backport manually run:
node scripts/backport --pr 114184

spalger pushed a commit to spalger/kibana that referenced this pull request Nov 3, 2021
* [eslint] enable type-specific lint rules

* autofix violations

* duplicate eslint-disable to new export statement

Co-authored-by: spalger <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
# Conflicts:
#	src/plugins/share/common/index.ts
spalger added a commit that referenced this pull request Nov 4, 2021
* [eslint] enable type-specific lint rules (#114184)

* [eslint] enable type-specific lint rules

* autofix violations

* duplicate eslint-disable to new export statement

Co-authored-by: spalger <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
# Conflicts:
#	src/plugins/share/common/index.ts

* autofix more types

Co-authored-by: spalger <[email protected]>
spalger added a commit that referenced this pull request Nov 4, 2021
* [eslint] enable type-specific lint rules

(cherry picked from commit e824fdc)

* autofix all violations

Co-authored-by: spalger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Drilldowns Embeddable panel Drilldowns Feature:Embedding Embedding content via iFrame Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support Team:Operations Team label for Operations Team v7.16.1 v8.0.0 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[eslint] try linting with types in core