mrjono1 / joi-to-typescript

Convert Joi Schemas to TypeScript interfaces
MIT License
124 stars 39 forks source link

Add `unionNewLine` and `tupleNewLine` settings to force newline styling for unions and tuples. #413

Closed cmaster11 closed 7 months ago

cmaster11 commented 7 months ago

Note: this is based/dependent on https://github.com/mrjono1/joi-to-typescript/pull/412

Add:

  /**
   * If defined, place every member of a union on a new line
   */
  unionNewLine?: boolean;
  /**
   * If defined, place every member of a tuple on a new line
   */
  tupleNewLine?: boolean;

When used, these settings can help formatting the generated code to improve its readability.

More context

This PR was born because I was investigating a prettier bug that would cause JsDocs of union types to be "squashed", e.g. this code:

  /**
   * The items to iterate over.
   */
  items:
    /**
     * An array to iterate over.
     */
    | any[]
    /**
     * An object to iterate over.
     */
    | object;
  /**
   * Another comment
   */

becomes:

  /**
   * The items to iterate over.
   */
  items: /** <----------------- This is a bug
   * An array to iterate over. <---- The indentation is broken
   */
  | any[]

    /**
     * An object to iterate over.
     */
    | object;

  /**
   * Another comment
   */

So, I went on the way of "let's disable prettier" and explored around, and I realized that having such two settings can by default improve the readability of types.

codecov[bot] commented 7 months ago

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (43d58ee) 98.80% compared to head (49a5e37) 98.74%.

Files Patch % Lines
src/parse.ts 97.40% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #413 +/- ## ========================================== - Coverage 98.80% 98.74% -0.06% ========================================== Files 9 9 Lines 585 639 +54 Branches 226 255 +29 ========================================== + Hits 578 631 +53 - Misses 7 8 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.