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

(init-templates): Add linter/formatter to JavaScript/TypeScript templates #32136

Open
1 of 2 tasks
ren-yamanashi opened this issue Nov 14, 2024 · 2 comments
Open
1 of 2 tasks
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p3 package/tools Related to AWS CDK Tools or CLI

Comments

@ren-yamanashi
Copy link
Contributor

Describe the feature

Add linter and formatter configurations to the JavaScript and TypeScript templates generated by cdk init.

Use Case

JavaScript/TypeScript toolchain configuration, especially for linters and formatters, is often complex and time-consuming to set up correctly. This complexity can distract developers from focusing on their core CDK development work.

By providing these tools and configurations out of the box in the init templates, we can help developers focus more on their actual infrastructure code rather than spending time on tooling setup.

Proposed Solution

Add the following to the JavaScript and TypeScript init templates:

  1. Add linter/formatter dependencies to package.json:

    • Plan A: ESLint + Prettier
    • Plan B: Biome (all-in-one solution)
  2. Add appropriate configuration files:

    • For ESLint: eslint.config.mjs with CDK-specific rules
    • For Prettier: .prettierrc with standard configurations
    • For Biome: biome.json(or biome.jsonc)
  3. Add npm scripts to package.json:

    {
      "scripts": {
        "lint": "eslint . --ext .js,.ts",
        "format": "prettier --write .",
        // or for Biome:
        "lint": "biome lint .",
        "format": "biome format ."
      }
    }

Other Information

The choice between ESLint+Prettier vs Biome could be made based on:

  1. Community adoption
  2. Maintenance overhead
  3. Performance
  4. Integration with existing CDK tooling

Biome might be preferable as it's a single tool that handles both linting and formatting, which means less configuration and maintenance.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.166.0

Environment details (OS name and version, etc.)

macOS Sonoma v14.0

@ren-yamanashi ren-yamanashi added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 14, 2024
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Nov 14, 2024
@ashishdhingra ashishdhingra self-assigned this Nov 15, 2024
@ashishdhingra ashishdhingra added effort/medium Medium work item – several days of effort p3 and removed needs-triage This issue or PR still needs to be triaged. labels Nov 15, 2024
@ashishdhingra
Copy link
Contributor

The automatic configuration for linters/formatters makes sense based on general adoption for CDK templates. Unsure how to ensure if the appropriate extensions/plugins for a particular environment would be installed if we make these template changes (perhaps that's the reason, project generated from cdk init is minimal).

@ashishdhingra ashishdhingra removed their assignment Nov 15, 2024
@ren-yamanashi
Copy link
Contributor Author

The automatic configuration for linters/formatters makes sense based on general adoption for CDK templates. Unsure how to ensure if the appropriate extensions/plugins for a particular environment would be installed if we make these template changes (perhaps that's the reason, project generated from cdk init is minimal).

@ashishdhingra

Thank you for the thoughtful feedback. I completely understand the need to keep the cdk init templates minimal to serve a wide range of environments and use cases. I would like to address your valid concern regarding ensuring the appropriate extensions/plugins are installed.

To maintain the minimal design philosophy while still providing the benefits of linting and formatting tools, we could consider the following approach:

  1. Optional Installation: Include an additional prompt during cdk init (e.g., "Do you want to include recommended linters/formatters?") that allows users to opt-in. This way, users who prefer minimal setups can skip the additional configuration.

  2. Well-Documented Configuration: Instead of directly installing plugins, provide a README section or comments in the configuration files that guide users on how to set up their environment. For instance, we could include notes about installing ESLint/Prettier extensions for their editor.

  3. Community Adoption: Tools like ESLint and Prettier are widely adopted in the TypeScript ecosystem, including by a significant portion of CDK developers. Including pre-configured settings aligns with these norms and reduces onboarding friction for new users.

Would such an approach address the concern about environment-specific compatibility while still providing value for users looking for best practices? I'm happy to collaborate on refining this idea further. Thank you for considering this proposal!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p3 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

2 participants