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

feat(devkit): prefer strings over Linter enum #27209

Merged
merged 4 commits into from
Aug 19, 2024

Conversation

isaacplmann
Copy link
Collaborator

We should be consistent about how options are defined in our plugins. Currently, there are some options that use enums and some that use typed strings. I think typed strings are preferable because someone extending a generator only needs to import the main generator that they're extending, not all the transitive dependencies of that generator.

Current extending code:

// ...
import { applicationGenerator as reactApplicationGenerator } from '@nx/react';
import { Linter } from '@nx/eslint';

export async function applicationGenerator(
  tree: Tree,
  options: ApplicationGeneratorSchema
) {
  reactApplicationGenerator(tree, {
    ...options,
    linter: Linter.EsLint,
  });
}

Desired extending code:

// ...
import { applicationGenerator as reactApplicationGenerator } from '@nx/react';

export async function applicationGenerator(
  tree: Tree,
  options: ApplicationGeneratorSchema
) {
  reactApplicationGenerator(tree, {
    ...options,
    linter: 'eslint',
  });
}

The problem is not just an extra line of code, the person extending the reactApplicationGenerator has to dig into the implementation details of the generator itself in order to know where to find the Linter enum. The e2eTestRunner is already a typed string and is easily extended.

The solution I'm proposing in this PR would define a typed string in the same file as the existing enum. None of the implementations need to change. No community plugin code will be broken.

@isaacplmann isaacplmann requested review from a team as code owners July 30, 2024 14:30
Copy link

vercel bot commented Jul 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Aug 16, 2024 4:36pm

Copy link
Member

@leosvelperez leosvelperez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. It makes the generators more straightforward to extend.

We'll need to make a similar change in many other generators from other plugins, and we probably want to deprecate the Linter enum. Could you expand this PR with those changes? Let me know if you're busy with other things and I can help.

@isaacplmann isaacplmann force-pushed the plugins/prefer-strings branch from a01f75f to b47c47d Compare August 15, 2024 16:42
@isaacplmann isaacplmann requested review from a team as code owners August 15, 2024 16:42

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@isaacplmann isaacplmann force-pushed the plugins/prefer-strings branch from 8334476 to a13bf49 Compare August 16, 2024 12:00

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@isaacplmann isaacplmann merged commit 839dc15 into master Aug 19, 2024
6 checks passed
@isaacplmann isaacplmann deleted the plugins/prefer-strings branch August 19, 2024 21:07
FrozenPandaz pushed a commit that referenced this pull request Aug 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
We should be consistent about how options are defined in our plugins.
Currently, there are some options that use `enum`s and some that use
typed strings. I think typed strings are preferable because someone
extending a generator only needs to import the main generator that
they're extending, not all the transitive dependencies of that
generator.

Current extending code:
```
// ...
import { applicationGenerator as reactApplicationGenerator } from '@nx/react';
import { Linter } from '@nx/eslint';

export async function applicationGenerator(
  tree: Tree,
  options: ApplicationGeneratorSchema
) {
  reactApplicationGenerator(tree, {
    ...options,
    linter: Linter.EsLint,
  });
}
```

Desired extending code:
```
// ...
import { applicationGenerator as reactApplicationGenerator } from '@nx/react';

export async function applicationGenerator(
  tree: Tree,
  options: ApplicationGeneratorSchema
) {
  reactApplicationGenerator(tree, {
    ...options,
    linter: 'eslint',
  });
}
```

The problem is not just an extra line of code, the person extending the
`reactApplicationGenerator` has to dig into the implementation details
of the generator itself in order to know where to find the `Linter`
enum. The `e2eTestRunner` is already a typed string and is easily
extended.

The solution I'm proposing in this PR would define a typed string in the
same file as the existing enum. None of the implementations need to
change. No community plugin code will be broken.

(cherry picked from commit 839dc15)
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants