Commit Graph

5 Commits

Author SHA1 Message Date
Alois Klink d4289e8db7 chore(dev-deps): update @typescript-eslint to v6
Update the `@typescript-eslint/eslint-plugin` and
`@typescript-eslint/parser` plugin to v6.

The full list of changes needed can be found in the
[Announcing typescript-eslint v6 blog post][1], but the ones that
affect us are:
- Dropped support for Node.JS v14.
  This isn't a big deal for us, since Mermaid uses a version of
  `eslint-plugin-jsdoc` that does not support Node.JS v14 either,
  see 120029913d
  (chore(deps): update dependency eslint-plugin-jsdoc to v46, 2023-06-27)
- Changes to the `plugin:@typescript-eslint/recommended` configuration.
  I've manually changed the following two rules to match their old
  `@typescript-eslint/parser` v5 settings, to avoid turning ESLint
  warnings into errors:
  - `@typescript-eslint/no-explicit-any` to `warn`
  - `@typescript-eslint/no-unused-vars` to `warn`

[1]: https://main--typescript-eslint.netlify.app/blog/announcing-typescript-eslint-v6
2023-09-19 15:51:51 +01:00
Sidharth Vinod 11b599d77c
chore: Fix type imports 2023-08-22 13:44:11 +05:30
Alois Klink 7c3a73d4a8 build(types): add script to generate Config types
Add script `packages/mermaid/scripts/create-types-from-json-schema.mts`
to automatically generate the TypeScript definition for `MermaidConfig`
from the `MermaidConfig` JSON Schema at
`packages/mermaid/src/schemas/config.schema.yaml`.

To do this, we are using this library
[`json-schema-to-typescript`][1], which is also used by Webpack to
generate their types from their JSON Schema.

In order to make sure that this isn't a breaking change, the script
makes all fields **optional**, as that is what the original typescript
file has.

Additionally, I've put in some custom logic into the script, so that
the exact same order is used for the TypeScript file, to make the
`git diff` easier to review. In the future, we can remove this custom
logic, once we no longer need to worry about `git merge` conflicts.

[1]: https://github.com/bcherny/json-schema-to-typescript
2023-07-06 03:53:40 +01:00
Alois Klink 79688a1dc1 build: forbid using TypeScript enums using eslint
[TypeScript enums][1] are an unusual TypeScript feature, because it's
one of the only features that is "not a type-level extension of
JavaScript".

This means TypeScript generates custom code for enums, which can cause a
bunch of issues, especially as this custom code can be built differently
depending on which bundler you use, and because of this, many people
discourage the use of enums:

- [The Dangers of TypeScript Enums][2]
- [Tidy TypeScript: Prefer union types over enums][3]
- [TypeScript: Handbook - Enums # Objects vs Enums][4]

I've added an ESLint rule that forbids TypeScript enums, as in most
cases, it's better to use string literals instead, e.g. like
`type a = "a" | "b" | "c";`.

[1]: https://www.typescriptlang.org/docs/handbook/enums.html#string-enums
[2]: https://dev.to/azure/the-dangers-of-typescript-enums-55pd
[3]: https://fettblog.eu/tidy-typescript-avoid-enums/
[4]: https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums
2023-07-03 00:04:16 +01:00
Sidharth Vinod afe3f593e1
fix(#4003): Remove unhandled promises
Add eslint rules to check for unhandled promises
Fix all existing unhandled promise issues
2023-01-18 00:47:49 +05:30