mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
68.69k stars 6.07k forks source link

[PR#5468] refactor: remove TypeScript non null assertions #5518

Closed aloisklink closed 1 month ago

aloisklink commented 1 month ago

:bookmark_tabs: Summary

[!Note]

This PR does not target the develop branch. Instead it targets:

  • 5468

I'm not a big fan of using TypeScript's non-null assertion operator (e.g. map.get(val)!).

Instead, I've tried to rewrite the code when possible, so it's not needed. E.g., instead of doing:

if (map.has(x)) {
  return map.get(x);
}

I've tried to do things that TypeScript can understand, e.g.

const val = map.get(x);
if (val !== undefined) {
  return val;
}

There's also some other misc improvements I found when reviewing #5468.

There should be no functional changes to the code, this is a refactoring only change.

:straight_ruler: Design Decisions

Describe the way your implementation works or what design decisions you made if applicable.

:clipboard: Tasks

Make sure you

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 0% with 84 lines in your changes are missing coverage. Please review.

Project coverage is 5.72%. Comparing base (50c9ede) to head (730fa89).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518/graphs/tree.svg?width=650&height=150&src=pr&token=BaET4V1BdM&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js)](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) ```diff @@ Coverage Diff @@ ## fix/maps #5518 +/- ## ======================================== Coverage 5.72% 5.72% ======================================== Files 278 277 -1 Lines 42018 42012 -6 Branches 490 515 +25 ======================================== Hits 2407 2407 + Misses 39611 39605 -6 ``` | [Flag](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) | Coverage Δ | | |---|---|---| | [unit](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) | `5.72% <0.00%> (+<0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) | Coverage Δ | | |---|---|---| | [packages/mermaid/src/diagrams/git/gitGraphAst.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fgit%2FgitGraphAst.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvZ2l0L2dpdEdyYXBoQXN0Lmpz) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/state/stateDb.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fstate%2FstateDb.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvc3RhdGUvc3RhdGVEYi5qcw==) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/pie/pieRenderer.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fpie%2FpieRenderer.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvcGllL3BpZVJlbmRlcmVyLnRz) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/mermaidAPI.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2FmermaidAPI.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvbWVybWFpZEFQSS50cw==) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/class/classDb.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fclass%2FclassDb.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvY2xhc3MvY2xhc3NEYi50cw==) | `0.00% <0.00%> (ø)` | | | [...ges/mermaid/src/diagrams/class/classRenderer-v2.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fclass%2FclassRenderer-v2.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvY2xhc3MvY2xhc3NSZW5kZXJlci12Mi50cw==) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/sankey/sankeyDB.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fsankey%2FsankeyDB.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvc2Fua2V5L3NhbmtleURCLnRz) | `0.00% <0.00%> (ø)` | | | [...ckages/mermaid/src/diagrams/sequence/sequenceDb.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fsequence%2FsequenceDb.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvc2VxdWVuY2Uvc2VxdWVuY2VEYi50cw==) | `0.00% <0.00%> (ø)` | | | [...id/src/diagrams/requirement/requirementRenderer.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Frequirement%2FrequirementRenderer.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvcmVxdWlyZW1lbnQvcmVxdWlyZW1lbnRSZW5kZXJlci5qcw==) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/block/blockDB.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fblock%2FblockDB.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvYmxvY2svYmxvY2tEQi50cw==) | `0.00% <0.00%> (ø)` | | | ... and [1 more](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5518/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js)
Yash-Singh1 commented 1 month ago

Yeah, this is definitely a better way to interact with Maps 👍🏾 .