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

[code-infra] New lint rule: mandate production switch for certain function calls #207

Open
oliviertassinari opened this issue Sep 30, 2024 · 0 comments
Labels
performance scope: code-infra Specific to the core-infra product status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 30, 2024

Some helpers should always be wrapped with a process.env.NODE_ENV !== 'production' conditional to prevent them from ending up in user's production bundles. See mui/mui-x#14748 (comment)

To Do: Craft an eslint rule that mandates the wrapper for certain function calls:

Should pass:

if (process.env.NODE_ENV !== 'production') {
  checkSlot(key, overrides[k] as any);
}

if (process.env.NODE_ENV !== 'production') {
  for (key in slots) {
    checkSlot(key, overrides[k] as any);
  }
}

otherFunction('hello');

Should fail:

checkSlot(key, overrides[k] as any);

if (process.env.NODE_ENV === 'production') {
  checkSlot(key, overrides[k] as any);
}

List of calls

  • warnOnce
  • checkSlot
@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 30, 2024
@oliviertassinari oliviertassinari added the scope: code-infra Specific to the core-infra product label Sep 30, 2024
@oliviertassinari oliviertassinari changed the title New lint rule: mandate production switch for certain function calls [code-infra] New lint rule: mandate production switch for certain function calls Sep 30, 2024
@oliviertassinari oliviertassinari added dx Related to developers' experience performance and removed dx Related to developers' experience labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance scope: code-infra Specific to the core-infra product status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

1 participant