feat(shadcn): Customize code style for components (ESLint / Prettier / TS) #9194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds support for configurable code style adjustment using ESLint, Prettier and TypeScript Language Service.
Changes
ts-morph-reactdependency to package.json (I maintain this library separately to avoid bloating the codebase)transformsetting to config schema (see details below)transform-react.tsto run the code style adjustmentsConfiguration
Documentation available on ts-morph-react github page
{ "transform": { // Avoid export assignment `export =`, and instead enfore specific exports `export const Button` "enforceDirectExports": true, // Transform functions to react function components / arrow functions `export const Button: FunctionComponent = ` "enforceFunctionComponent": true, // Use named imports for react, e.g. `import { type FunctionComponent } from 'react'` "enforceNamedImports": true, // Ensure newline separation on root level (imports group, components) "enforceLineSeparation": true, // Enfore TypeScript Language Service code style adjustments "enforceFormat": true, // Enfore ESLint code style adjustments "enforceEslint": true, // Enfore Prettier code style adjustments "enforcePrettier": true, // TypeScript Language Service format options "format": { ... }, // ESLint rules (@typescript-eslint/*, @stylistic/* supported) "eslint": { ... }, // Prettier options "prettier": { ... } } }Testing
npx shadcn@latest addcommand to ensure code style adjustments applytransform-reactand different configuration optionsRelated
diffcommand gives false positives due to code style #1202