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

infra(unicorn): permanently disable no-object-as-default-parameter #3203

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

ST-DDT
Copy link
Member

@ST-DDT ST-DDT commented Oct 20, 2024

Ref: #2439


Permanently disables the [unicorn/disable no-object-as-default-parameter](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/disable no-object-as-default-parameter.md) lint rule.

We assume that our users use typescript so they would always pass all required parameters.
Even if they don't all our methods handle that with basic defaults.

Affected code:

~/faker/src/modules/lorem/index.ts
  135:5  error  Do not use an object literal as default for parameter `wordCount`      unicorn/no-object-as-default-parameter
  203:5  error  Do not use an object literal as default for parameter `sentenceCount`  unicorn/no-object-as-default-parameter
  361:5  error  Do not use an object literal as default for parameter `lineCount`      unicorn/no-object-as-default-parameter

~/faker/test/scripts/apidocs/method.example.ts
  270:5  error  Do not use an object literal as default for parameter `a`  unicorn/no-object-as-default-parameter
  305:5  error  Do not use an object literal as default for parameter `a`  unicorn/no-object-as-default-parameter
  325:5  error  Do not use an object literal as default for parameter `a`  unicorn/no-object-as-default-parameter

Alternative Solution

Change the implementation of the methods to not use signature level defaults.

sentence(
-    wordCount:
+    wordCount?:
      | number
      | {
          /**
           * The minimum number of words to generate.
           */
          min: number;
          /**
           * The maximum number of words to generate.
           */
          max: number;
-        } = { min: 3, max: 10 }
+        }
  ): string {
-    const sentence = this.words(wordCount);
+    const sentence = this.words(wordCount ?? { min: 3, max: 10 });
...

@ST-DDT ST-DDT added p: 1-normal Nothing urgent c: infra Changes to our infrastructure or project setup labels Oct 20, 2024
@ST-DDT ST-DDT added this to the vAnytime milestone Oct 20, 2024
@ST-DDT ST-DDT requested review from a team October 20, 2024 18:12
@ST-DDT ST-DDT self-assigned this Oct 20, 2024
@ST-DDT
Copy link
Member Author

ST-DDT commented Oct 20, 2024

I'm actually not sure which variant I prefer.

Copy link

netlify bot commented Oct 20, 2024

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit 582b017
🔍 Latest deploy log https://app.netlify.com/sites/fakerjs/deploys/671547f93ab72d00080a182a
😎 Deploy Preview https://deploy-preview-3203.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Oct 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.97%. Comparing base (3f3d628) to head (582b017).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3203   +/-   ##
=======================================
  Coverage   99.96%   99.97%           
=======================================
  Files        2798     2798           
  Lines      227335   227335           
  Branches      957      958    +1     
=======================================
+ Hits       227262   227272   +10     
+ Misses         73       63   -10     

see 2 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: infra Changes to our infrastructure or project setup p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant