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

Update TypeScript and ESLint to latest versions #1256

Merged
merged 1 commit into from
Mar 12, 2023

Conversation

mszabo-wikia
Copy link
Contributor

@mszabo-wikia mszabo-wikia commented Mar 12, 2023

Which problem is this PR solving?

Short description of the changes

Update TypeScript, ESLint and @typescript-eslint to the latest versions.

Notable changes:

  • Update the list of core ESLint rules that need to be disabled because @typescript-eslint provides TypeScript-specific equivalents for them, and change existing suppressions referencing the now-disabled core rules. Group these together in the ESLint config for clarity.
  • Fix references to unimported types in serviceGraph.tsx and types.tsx.
  • It seems that the type of defaultConfig and the user-defined config wasn't correctly inferred as Config before the upgrade. Fix various type errors resulting from this:
    • '__mergeFields', i.e. the list of config options where user-specified values should be merged with the default object values in defaultConfig, was defined via defineProperty and so seemingly inferred as an unknown type. This now causes a type error when iterating over its keys to try and merge the relevant property values, as TypeScript can't guarantee that the property values are objects. Make it a separate named export instead, which also allows for strictly typing the allowable property names.
    • Make the url field of the ConfigMenuItem type optional as this was now recognized as a type error. This matches documentation and actual usage.
    • Rename the dagMaxServicesLen property definition to dagMaxNumServices as that is what the actual code uses.
    • Fix the linkPatterns config option typedef to be an array, as per actual usage.
  • Update handleError in Plexus to correctly take either an ErrorEvent or a MessageEvent to match updated typings for the Web Worker API.
  • Update catch clauses in readJsonFile because TypeScript 4.4+ types the error in catch clauses as unknown by default. We don't expect anything outside of an Error to be thrown here, so we can restore the previous behavior.

Signed-off-by: Máté Szabó <mszabo@fandom.com>
@codecov
Copy link

codecov bot commented Mar 12, 2023

Codecov Report

Patch coverage: 80.00% and project coverage change: +0.10 🎉

Comparison is base (baccc96) 95.47% compared to head (c7cbbd1) 95.57%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1256      +/-   ##
==========================================
+ Coverage   95.47%   95.57%   +0.10%     
==========================================
  Files         244      244              
  Lines        7750     7752       +2     
  Branches     2017     2016       -1     
==========================================
+ Hits         7399     7409      +10     
+ Misses        351      343       -8     
Impacted Files Coverage Δ
...ts/DeepDependencies/Graph/DdgNodeContent/index.tsx 100.00% <ø> (ø)
...ui/src/utils/DraggableManager/DraggableManager.tsx 97.22% <ø> (ø)
packages/jaeger-ui/src/utils/readJsonFile.tsx 72.22% <ø> (ø)
...ackages/jaeger-ui/src/constants/default-config.tsx 75.00% <66.66%> (+25.00%) ⬆️
...c/components/Monitor/ServicesView/serviceGraph.tsx 98.18% <100.00%> (ø)
packages/jaeger-ui/src/utils/config/get-config.tsx 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -57,7 +56,16 @@ module.exports = {
prefix: ['I'],
},
],

// Disable ESLint core rules for which @typescript-eslint provides TypeScript-specific equivalents.
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, what's the harm in keeping them? if TS flags them first, then fixing the issue would also fix ESLint issue, would it not? (basically, I prefer fewer deviations from defaults if possible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that these can cause false positives with the new version of @typescript-eslint. E.g. removing the suppression for core's no-shadow rules results in a plethora of bogus reports about TS type definitions. The recommendation of silencing the corresponding core rules comes from the plugin itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another way to fix it could be to make the root eslintrc also extend the recommended config from @typescript-eslint, because that config already does this toggling for us. This is what plexus does already. I'm thinking this could be done in a followup PR as it might cause some new errors.

Copy link
Member

Choose a reason for hiding this comment

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

+1 -- #1258

@@ -111,6 +111,7 @@ export function getNodeRenderer({
return function renderNode(vertex: TDdgVertex, _: unknown, lv: TLayoutVertex<any> | null) {
const { isFocalNode, key, operation, service } = vertex;
return (
// eslint-disable-next-line @typescript-eslint/no-use-before-define
Copy link
Member

Choose a reason for hiding this comment

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

it's good to have a comment explaining the reason (I assume it's a false positive)

};

// menu controls the dropdown menu in the top-right corner of the UI.
// When populated, this element completely overrides the default menu.
menu: (ConfigMenuGroup | ConfigMenuItem)[];
menu: readonly (ConfigMenuGroup | ConfigMenuItem)[];
Copy link
Member

Choose a reason for hiding this comment

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

curious why these specific entries need readonly and not all others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems it's specifically for array type entries. TS is apparently now better at detecting that the object passed to deepFreeze is recursively readonly.

@yurishkuro yurishkuro merged commit f08086a into jaegertracing:main Mar 12, 2023
@yurishkuro
Copy link
Member

🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳

@yurishkuro
Copy link
Member

Another awesome PR! It looks like it's going to unblock a lot of pending dependabot upgrades, several of them already turned green after failing CI for months. I'll be merging them today (unfortunately, every time I merge one I need to wait for the CI to run on all others, takes a lot of time).

@mszabo-wikia
Copy link
Contributor Author

Awesome, that's great to see :)

@mszabo-wikia mszabo-wikia deleted the ts-update branch March 12, 2023 23:03
Binrix pushed a commit to Binrix/jaeger-ui that referenced this pull request Apr 18, 2023
- Resolves jaegertracing#818

Update TypeScript, ESLint and `@typescript-eslint` to the latest
versions.

Notable changes:
* Update the list of core ESLint rules that need to be disabled because
`@typescript-eslint` provides TypeScript-specific equivalents for them,
and change existing suppressions referencing the now-disabled core
rules. Group these together in the ESLint config for clarity.
* Fix references to unimported types in `serviceGraph.tsx` and
`types.tsx`.
* It seems that the type of `defaultConfig` and the user-defined config
wasn't correctly inferred as `Config` before the upgrade. Fix various
type errors resulting from this:
* `'__mergeFields'`, i.e. the list of config options where
user-specified values should be merged with the default object values in
`defaultConfig`, was defined via `defineProperty` and so seemingly
inferred as an unknown type. This now causes a type error when iterating
over its keys to try and merge the relevant property values, as
TypeScript can't guarantee that the property values are objects. Make it
a separate named export instead, which also allows for strictly typing
the allowable property names.
* Make the `url` field of the `ConfigMenuItem` type optional as this was
now recognized as a type error. This matches documentation and actual
usage.
* Rename the `dagMaxServicesLen` property definition to
`dagMaxNumServices` as that is what the actual code uses.
* Fix the `linkPatterns` config option typedef to be an array, as per
actual usage.
* Update `handleError` in Plexus to correctly take either an
`ErrorEvent` or a `MessageEvent` to match updated typings for the Web
Worker API.
* Update `catch` clauses in `readJsonFile` because TypeScript 4.4+
[types the error in `catch` clauses as `unknown` by
default](https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#using-unknown-in-catch-variables).
We don't expect anything outside of an `Error` to be thrown here, so we
can restore the previous behavior.

Signed-off-by: Máté Szabó <mszabo@fandom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript version is outdated
2 participants