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

Add the supplyDefaultsInJsDoc setting #442

Merged
merged 3 commits into from
Mar 15, 2024

Conversation

cmaster11
Copy link
Collaborator

@cmaster11 cmaster11 commented Mar 15, 2024

Add the supplyDefaultsInJsDoc setting

If a field has a default value, add its stringified representation to the JsDoc using the @default annotation.

If a field has a default value, add its stringified representation to the JsDoc using the @default annotation.
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.50%. Comparing base (2cb6f45) to head (7d1f986).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #442      +/-   ##
==========================================
+ Coverage   98.48%   98.50%   +0.02%     
==========================================
  Files           9        9              
  Lines         661      670       +9     
  Branches      266      262       -4     
==========================================
+ Hits          651      660       +9     
  Misses         10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cmaster11 cmaster11 marked this pull request as draft March 15, 2024 05:00
@mrjono1 mrjono1 marked this pull request as ready for review March 15, 2024 05:00
@cmaster11
Copy link
Collaborator Author

I'm wondering whether this should use util.inspect 🤔 For prettier docs

@cmaster11
Copy link
Collaborator Author

cmaster11 commented Mar 15, 2024

Difference

JSON

export interface Test {
  /**
   * @default "Test"
   */
  alt?: string | number;
  /**
   * @default {"val":false}
   */
  alt2?: string | number | {
      /**
       * @default true
       */
      val?: boolean;
    };
  /**
   * @default [1,2,3]
   */
  arr?: number[];
  /**
   * @default ["X","Y","Z"]
   */
  arr2?: string[];
  /**
   * @default true
   */
  bool?: boolean;
  /**
   * @default true
   */
  boolOptional?: boolean;
  /**
   * @default null
   */
  fieldWithAnyNull?: any;
  /**
   * A field with a
   * multiline doc
   *
   * @default "My string!"
   */
  fieldWithDoc?: string;
  /**
   * @default 1
   */
  num?: number;
  /**
   * @default 1
   */
  numOptional?: number;
  /**
   * @default {"val":"Test"}
   */
  obj?: {
    val?: string;
  };
  /**
   * @default "Test"
   */
  str?: string;
  /**
   * @default "Test"
   */
  strOptional?: string;
  /**
   * @default "Test\\\\World$Hello🚀Hey\\nYay"
   */
  strWithSpecialChars?: string;
}

util.inspect

export interface Test {
  /**
   * @default 'Test'
   */
  alt?: string | number;
  /**
   * @default { val: false }
   */
  alt2?: string | number | {
      /**
       * @default true
       */
      val?: boolean;
    };
  /**
   * @default [ 1, 2, 3 ]
   */
  arr?: number[];
  /**
   * @default [ 'X', 'Y', 'Z' ]
   */
  arr2?: string[];
  /**
   * @default true
   */
  bool?: boolean;
  /**
   * @default true
   */
  boolOptional?: boolean;
  /**
   * @default null
   */
  fieldWithAnyNull?: any;
  /**
   * A field with a
   * multiline doc
   *
   * @default 'My string!'
   */
  fieldWithDoc?: string;
  /**
   * @default 1
   */
  num?: number;
  /**
   * @default 1
   */
  numOptional?: number;
  /**
   * @default { val: 'Test' }
   */
  obj?: {
    val?: string;
  };
  /**
   * @default 'Test'
   */
  str?: string;
  /**
   * @default 'Test'
   */
  strOptional?: string;
  /**
   * @default 'Test\\World$Hello🚀Hey\nYay'
   */
  strWithSpecialChars?: string;
}

@mrjono1
Copy link
Owner

mrjono1 commented Mar 15, 2024

I had to google it, but it sounds interesting, it would be easier than calculating indentations

@mrjono1
Copy link
Owner

mrjono1 commented Mar 15, 2024

@cmaster11 would you like to be a collaborator on this repo?

@cmaster11
Copy link
Collaborator Author

@mrjono1 I can be interested for sure, given how much I've been loving it :D

@mrjono1
Copy link
Owner

mrjono1 commented Mar 15, 2024

invite sent!

@cmaster11
Copy link
Collaborator Author

Getting back to the feat, there are multiple options.

  • JSON.stringify
  • util.inspect (still doesn't handle nicely multiline strings: @default 'A multiline\nstring with\nsome lines')
  • Could be also worth using a yaml dump?

Thing is, JSON.stringify and util.inspect produce JS-valid code, yaml would not 🤔

@cmaster11
Copy link
Collaborator Author

Maybe the tradeoff can be the util.inspect, where it's a tad cleaner than JSON but still compatible. The more I look at it, the more it seems friendly.

@cmaster11
Copy link
Collaborator Author

Still LGTM?

@cmaster11 cmaster11 requested a review from mrjono1 March 15, 2024 05:28
@cmaster11 cmaster11 merged commit 73dad18 into mrjono1:master Mar 15, 2024
4 checks passed
@cmaster11 cmaster11 deleted the default-in-jsdoc branch March 15, 2024 06:22
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.

2 participants