ts-morph-react 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@ A powerful collection of **AST transformers for ts-morph** to automate React cod
11
11
  - 🔄 **Enforce Direct Exports** - Convert separate export statements to direct exports on function declarations
12
12
  - 🎯 **Function Components** - Automatically convert function declarations to arrow function components with proper typing
13
13
  - 📦 **Named Imports** - Transform default imports to named imports for consistency
14
- - 🎨 **Code Formatting** - Format code and organize imports according to your style guide
14
+ - 🎨 **Code Formatting** - Format code and organize imports according to your style guide (using ESLint, Prettier or Typescript Language Featues)
15
15
  - ⚡ **Composable** - Mix and match transformers to create your refactoring pipeline
16
16
  - 🛡️ **Type-Safe** - Built with TypeScript for a fully typed experience
17
17
  - 🎭 **AST-Powered** - Leverage ts-morph for precise, reliable code transformations
@@ -42,7 +42,10 @@ await transform(sourceFile, {
42
42
  enforceDirectExports: true,
43
43
  enforceFunctionComponent: true,
44
44
  enforceNamedImports: true,
45
- enforceFormat: true
45
+ enforceFormat: true,
46
+ enforcePrettier: true,
47
+ enforceEslint: true,
48
+ enforceLineSeparation: true
46
49
  })
47
50
 
48
51
  // Save changes
@@ -111,9 +114,9 @@ export const Button: FunctionComponent<ButtonProps> = ({ label }) => {
111
114
  }
112
115
  ```
113
116
 
114
- ### enforceFormat
117
+ ### enforceEslint / enforcePrettier / enforceFormat
115
118
 
116
- Formats code and organizes imports according to your style guide. Respects all standard TypeScript formatting options.
119
+ Formats code and organizes imports according to your style guide. Respects all standard TypeScript formatting options, eslint rules and prettier options.
117
120
 
118
121
  **Usage:**
119
122
  ```tsx
@@ -121,10 +124,20 @@ import { transform } from 'ts-morph-react'
121
124
 
122
125
  await transform(sourceFile, {
123
126
  enforceFormat: true,
127
+ enforcePrettier: true,
128
+ enforceEslint: true,
129
+ enforceLineSeparation: true,
124
130
  format: {
125
131
  indentSize: 2,
126
132
  convertTabsToSpaces: true,
127
133
  semicolons: ts.SemicolonPreference.Remove
134
+ },
135
+ eslint: {
136
+ '@stylistic/quotes': ['error', 'single']
137
+ },
138
+ prettier: {
139
+ semi: false,
140
+ singleQuote: true
128
141
  }
129
142
  })
130
143
  ```
@@ -133,10 +146,12 @@ await transform(sourceFile, {
133
146
  ```tsx
134
147
  import * as React from 'react';
135
148
 
136
- import { Text } from '@/components/Text'
149
+ import { Text } from '@/components/Text';
137
150
 
138
- export const Button: React.FunctionComponent<ButtonProps> = ({ label }) => {
139
- return <button><Text>{label}</Text></button>;
151
+ export const Button: React.FunctionComponent<ButtonProps> = ({
152
+ label
153
+ }) => {
154
+ return <button><Text>{label}</Text></button>;
140
155
  };
141
156
  ```
142
157
 
@@ -162,6 +177,9 @@ interface TransformerConfig {
162
177
  enforceFunctionComponent: boolean
163
178
  enforceNamedImports: boolean
164
179
  enforceFormat: boolean
180
+ enforceLineSeparation: boolean
181
+ enforceEslint: boolean
182
+ enforcePrettier: boolean
165
183
  format: {
166
184
  baseIndentSize: number
167
185
  convertTabsToSpaces: boolean
@@ -191,6 +209,19 @@ interface TransformerConfig {
191
209
  semicolons: SemicolonPreference
192
210
  tabSize: number
193
211
  trimTrailingWhitespace: boolean
212
+ },
213
+ eslint: {
214
+ '@stylistic/*': ['error'],
215
+ '@typescript-eslint/*': ['error']
216
+ },
217
+ prettier: {
218
+ semi: false,
219
+ singleQuote: true,
220
+ jsxSingleQuote: true,
221
+ arrowParens: 'always',
222
+ bracketSameLine: true,
223
+ objectWrap: 'collapse',
224
+ printWidth: 120
194
225
  }
195
226
  }
196
227
  ```
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ interface TransformerConfig {
8
8
  enforceFunctionComponent: boolean;
9
9
  enforceNamedImports: boolean;
10
10
  enforceFormat: boolean;
11
+ enforceLineSeparation: boolean;
11
12
  enforceEslint: boolean;
12
13
  enforcePrettier: boolean;
13
14
  format: FormatCodeSettings;
@@ -35,6 +36,8 @@ declare const enforceFormat: Transformer;
35
36
 
36
37
  declare const enforceFunctionComponent: Transformer;
37
38
 
39
+ declare const enforceLineSeparation: Transformer;
40
+
38
41
  declare const enforceNamedImports: Transformer;
39
42
 
40
43
  declare const enforcePrettier: Transformer;
@@ -60,4 +63,4 @@ interface SeparationEntry {
60
63
  }
61
64
  declare function enforeLineSeparation(sourceFile: SourceFile, predicate: (cur: Node<ts.Node>, prev: Node<ts.Node>, triviaWidth: number) => SeparationIntent): void;
62
65
 
63
- export { type MatchFn, REACT_APIS, REACT_HOOKS, REACT_TYPES, type SeparationEntry, SeparationIntent, type TransformFn, type Transformer, type TransformerConfig, type TransformerParams, enforceDirectExports, enforceEslint, enforceFormat, enforceFunctionComponent, enforceNamedImports, enforcePrettier, enforeLineSeparation, isForwardRefComponent, isFunctionComponent, isReactComponent, mergeConfig, transform, transformers };
66
+ export { type MatchFn, REACT_APIS, REACT_HOOKS, REACT_TYPES, type SeparationEntry, SeparationIntent, type TransformFn, type Transformer, type TransformerConfig, type TransformerParams, enforceDirectExports, enforceEslint, enforceFormat, enforceFunctionComponent, enforceLineSeparation, enforceNamedImports, enforcePrettier, enforeLineSeparation, isForwardRefComponent, isFunctionComponent, isReactComponent, mergeConfig, transform, transformers };
package/dist/index.js CHANGED
@@ -1,9 +1,5 @@
1
- import {SyntaxKind,Node,ImportDeclaration,StructureKind,VariableDeclarationKind,ts}from'ts-morph';import j from'@stylistic/eslint-plugin';import {ESLint}from'eslint';import {dirname}from'path';import J from'typescript-eslint';import {format}from'prettier';var y=["ComponentProps","ComponentPropsWithRef","ComponentPropsWithoutRef","FC","FunctionComponent","ReactNode","ReactElement","JSX","RefObject","MutableRefObject","CSSProperties","HTMLAttributes","SVGAttributes","DOMAttributes","PropsWithChildren","PropsWithRef"],N=["useState","useEffect","useCallback","useMemo","useRef","useContext","useReducer","useImperativeHandle","useLayoutEffect","useDebugValue","useTransition","useDeferredValue","useId","useSyncExternalStore"],b=["forwardRef","memo","lazy","createContext","createElement","cloneElement","isValidElement","Children","Fragment","StrictMode","Suspense"];function R(e){try{let t=e.getInitializer?.();if(!t)return !1;let r=t.getDescendantsOfKind?.(SyntaxKind.JsxElement)||[],o=t.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement)||[];if(r.length>0||o.length>0)return !0;if(Node.isArrowFunction(t)){let n=t.getBody?.();if(n){let i=n.getDescendantsOfKind?.(SyntaxKind.JsxElement)||[],s=n.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement)||[];return i.length>0||s.length>0}}return !1}catch{return false}}function P(e){try{let t=e.getInitializer?.();if(!t)return !1;let r=t.getText?.();return !!(r?.includes("forwardRef(")||r?.includes("React.forwardRef("))}catch{return false}}function T(e){try{let t=e.getDescendantsOfKind?.(SyntaxKind.JsxElement)||[],r=e.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement)||[];return t.length>0||r.length>0}catch{return false}}var I={match:({config:e})=>e.enforceDirectExports,transform:async({sourceFile:e})=>{e.getFunctions().forEach(t=>{if(!T(t)||t.isExported()&&t.hasExportKeyword())return;let r=t.getName(),o=false;e.getExportDeclarations().forEach(n=>{n.getNamedExports().some(s=>s.getName()===r)&&(o=true);}),o&&(t.setIsExported(true),e.getExportDeclarations().forEach(n=>{let s=n.getNamedExports().filter(a=>a.getName()===r);s.length>0&&(s.forEach(a=>{a.remove();}),n.getNamedExports().length===0&&n.remove());}));}),e.getVariableDeclarations().forEach(t=>{if(!R(t)||P(t))return;let r=t.getInitializer();if(!r||!Node.isArrowFunction(r))return;let o=t.getName(),n=t.getVariableStatement();if(!n)return;let i=n.hasExportKeyword(),s=false;e.getExportDeclarations().forEach(f=>{f.getNamedExports().some(E=>E.getName()===o)&&(s=true);});let a=i||s,p=r.getParameters().map(f=>f.getText()).join(", "),g=r.getBody();if(!g)return;let x=g.getText(),l,c=x.trim();c.startsWith("(")&&c.endsWith(")")?l=`{
2
- return ${c.slice(1,-1).trim()}
3
- }`:c.startsWith("{")?l=x:l=`{
4
- return ${x}
5
- }`;let u=`${a?"export ":""}function ${o}(${p}) ${l}`;n.replaceWithText(u),s&&e.getExportDeclarations().forEach(f=>{let E=f.getNamedExports().filter(S=>S.getName()===o);E.length>0&&(E.forEach(S=>{S.remove();}),f.getNamedExports().length===0&&f.remove());});});}};var A={match:({config:e})=>e.enforceEslint,transform:async({sourceFile:e,config:t})=>{let r=e.getFilePath(),o=dirname(r),n=new ESLint({fix:true,cwd:o,overrideConfigFile:true,overrideConfig:[{basePath:".",languageOptions:{parser:J.parser,ecmaVersion:2020,sourceType:"module",parserOptions:{ecmaFeatures:{jsx:true}}},files:["**/*.{ts,tsx,js,jsx}"],plugins:{"@stylistic":j},rules:t.eslint}]}),[i]=await n.lintText(e.getFullText(),{filePath:r});i?.output&&e.replaceWithText(i.output);}};var O=(o=>(o[o.IGNORE=0]="IGNORE",o[o.COMBINE=1]="COMBINE",o[o.SEPARATE=2]="SEPARATE",o))(O||{});function w(e,t){let r=[],o=e.getChildSyntaxListOrThrow();for(let n=o.getChildCount()-1;n>0;n-=1){let i=o.getChildAtIndex(n-1),s=o.getChildAtIndex(n),a=t(s,i,s.getLeadingTriviaWidth());r.push({range:[i.getEnd(),s.getStart()],intent:a});}r.forEach(({range:n,intent:i})=>{i===1?e.replaceText(n,`
6
- `):i===2&&e.replaceText(n,`
1
+ import {SyntaxKind,Node,StructureKind,VariableDeclarationKind,ImportDeclaration,ts}from'ts-morph';import V from'@stylistic/eslint-plugin';import {ESLint}from'eslint';import {dirname}from'path';import S from'typescript-eslint';import {format}from'prettier';var p=["ComponentProps","ComponentPropsWithRef","ComponentPropsWithoutRef","FC","FunctionComponent","ReactNode","ReactElement","JSX","RefObject","MutableRefObject","CSSProperties","HTMLAttributes","SVGAttributes","DOMAttributes","PropsWithChildren","PropsWithRef"],x=["useState","useEffect","useCallback","useMemo","useRef","useContext","useReducer","useImperativeHandle","useLayoutEffect","useDebugValue","useTransition","useDeferredValue","useId","useSyncExternalStore"],y=["forwardRef","memo","lazy","createContext","createElement","cloneElement","isValidElement","Children","Fragment","StrictMode","Suspense"];function q(e){try{let r=e.getInitializer?.();if(!r)return !1;let t=r.getDescendantsOfKind?.(SyntaxKind.JsxElement)||[],o=r.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement)||[];if(t.length>0||o.length>0)return !0;if(Node.isArrowFunction(r)){let n=r.getBody?.();if(n){let s=n.getDescendantsOfKind?.(SyntaxKind.JsxElement)||[],i=n.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement)||[];return s.length>0||i.length>0}}return !1}catch{return false}}function G(e){try{let r=e.getInitializer?.();if(!r)return !1;let t=r.getText?.();return !!(t?.includes("forwardRef(")||t?.includes("React.forwardRef("))}catch{return false}}function l(e){try{let r=e.getDescendantsOfKind?.(SyntaxKind.JsxElement)||[],t=e.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement)||[];return r.length>0||t.length>0}catch{return false}}var T={match:({config:e})=>e.enforceDirectExports,transform:async({sourceFile:e})=>{e.getFunctions().forEach(r=>{if(!l(r)||r.isExported()&&r.hasExportKeyword())return;let t=r.getName(),o=false;e.getExportDeclarations().forEach(n=>{n.getNamedExports().some(i=>i.getName()===t)&&(o=true);}),o&&(r.setIsExported(true),e.getExportDeclarations().forEach(n=>{let i=n.getNamedExports().filter(a=>a.getName()===t);i.length>0&&(i.forEach(a=>{a.remove();}),n.getNamedExports().length===0&&n.remove());}));});}};var C={match:({config:e})=>e.enforceEslint,transform:async({sourceFile:e,config:r})=>{let t=e.getFilePath(),o=dirname(t),n=new ESLint({fix:true,cwd:o,overrideConfigFile:true,overrideConfig:[{basePath:".",languageOptions:{parser:S.parser,ecmaVersion:2020,sourceType:"module",parserOptions:{ecmaFeatures:{jsx:true}}},files:["**/*.{ts,tsx,js,jsx}"],plugins:{"@stylistic":V,"@typescript-eslint":S.plugin},rules:r.eslint}]}),[s]=await n.lintText(e.getFullText(),{filePath:t});s?.output&&e.replaceWithText(s.output);}};var h={match:({config:e})=>e.enforceFormat,transform:async({sourceFile:e,config:r})=>{e.organizeImports(),e.formatText(r.format);}};var b={match:({config:e})=>e.enforceFunctionComponent,transform:async({sourceFile:e,config:{enforceDirectExports:r}})=>{e.getFunctions().forEach(t=>{if(!l(t))return;let o=t.getName();if(!o)return;let n=t.isExported(),s=false;e.getExportDeclarations().forEach(m=>{m.getNamedExports().some(g=>g.getName()===o)&&(s=true);});let i=r&&(n||s),c=t.getParameters()[0],E=(c.getTypeNode()??c.getType()).getText();c.removeType();let O=E==="any"?"React.FunctionComponent":`React.FunctionComponent<${E}>`,v=t.getChildIndex();e.insertVariableStatement(v,{declarations:[{name:o,type:O,initializer:m=>{m.write("(").write(t.getParameters().map(K=>K.getText()).join(", ")).write(")");let u=t.getReturnTypeNode()?.getText();u&&m.write(`: ${u}`),m.write(" => ");let g=t.getBody()?.getText()??"{}";m.block(()=>{m.write(g.replace(/^{|}$/g,"").trim());});}}],declarationKind:VariableDeclarationKind.Const,kind:StructureKind.VariableStatement,isExported:i}),t.remove();});}};var N=(o=>(o[o.IGNORE=0]="IGNORE",o[o.COMBINE=1]="COMBINE",o[o.SEPARATE=2]="SEPARATE",o))(N||{});function P(e,r){let t=[],o=e.getChildSyntaxListOrThrow();for(let n=o.getChildCount()-1;n>0;n-=1){let s=o.getChildAtIndex(n-1),i=o.getChildAtIndex(n),a=r(i,s,i.getLeadingTriviaWidth());t.push({range:[s.getEnd(),i.getStart()],intent:a});}t.forEach(({range:n,intent:s})=>{s===1?e.replaceText(n,`
2
+ `):s===2&&e.replaceText(n,`
7
3
 
8
- `);});}var F={match:({config:e})=>e.enforceFormat,transform:async({sourceFile:e,config:t})=>{w(e,(r,o)=>o instanceof ImportDeclaration&&r instanceof ImportDeclaration?1:2),e.organizeImports(),e.formatText(t.format);}};var v={match:({config:e})=>e.enforceFunctionComponent,transform:async({sourceFile:e,config:{enforceDirectExports:t}})=>{e.getFunctions().forEach(r=>{if(!T(r))return;let o=r.getName();if(!o)return;let n=r.isExported(),i=false;e.getExportDeclarations().forEach(c=>{c.getNamedExports().some(f=>f.getName()===o)&&(i=true);});let s=t&&(n||i),m=r.getParameters()[0],g=(m.getTypeNode()??m.getType()).getText();m.removeType();let x=g==="any"?"React.FunctionComponent":`React.FunctionComponent<${g}>`,l=r.getChildIndex();e.insertVariableStatement(l,{declarations:[{name:o,type:x,initializer:c=>{c.write("(").write(r.getParameters().map(C=>C.getText()).join(", ")).write(")");let u=r.getReturnTypeNode()?.getText();u&&c.write(`: ${u}`),c.write(" => ");let f=r.getBody()?.getText()??"{}";c.block(()=>{c.write(f.replace(/^{|}$/g,"").trim());});}}],declarationKind:VariableDeclarationKind.Const,kind:StructureKind.VariableStatement,isExported:s}),r.remove();});}};var K={match:({config:e})=>e.enforceNamedImports,transform:async({sourceFile:e})=>{let t=e.getImportDeclarations().find(i=>i.getModuleSpecifier().getLiteralValue()==="react");if(!t||!t.getNamespaceImport())return;let o=new Set,n=new Set;if(e.forEachDescendant(i=>{if(i.getKind()===SyntaxKind.TypeReference){let s=i.asKind(SyntaxKind.TypeReference);if(!s)return;let a=s.getTypeName();if(Node.isQualifiedName(a)){let m=a.getLeft().getText(),p=a.getRight().getText();m==="React"&&y.includes(p)&&(a.replaceWithText(p),o.add(p));}}if(i.getKind()===SyntaxKind.PropertyAccessExpression){let s=i.asKind(SyntaxKind.PropertyAccessExpression);if(!s)return;let a=s.getExpression(),m=s.getName();a.getText()==="React"&&(N.includes(m)||b.includes(m)||y.includes(m))&&(s.replaceWithText(m),y.includes(m)?o.add(m):(N.includes(m)||b.includes(m))&&n.add(m));}}),o.size>0||n.size>0){t.removeNamespaceImport();let i=Array.from(o).sort();for(let a of i)t.addNamedImport({name:a,isTypeOnly:true});let s=Array.from(n).sort();for(let a of s)t.addNamedImport(a);}}};var V={match:({config:e})=>e.enforcePrettier,transform:async({sourceFile:e,config:t})=>{let r=await format(e.getText(),{parser:"typescript",...t.prettier});e.replaceWithText(r);}};function z({eslint:e,format:t,prettier:r,...o}={}){return {enforceDirectExports:false,enforceFunctionComponent:false,enforceNamedImports:false,enforceFormat:false,enforceEslint:false,enforcePrettier:false,eslint:{"@stylistic/indent":["error",2],"@stylistic/quotes":["error","single"],"@stylistic/semi":["error","never"],"@stylistic/no-trailing-spaces":"error","@stylistic/no-multiple-empty-lines":["error",{max:1,maxEOF:0,maxBOF:0}],"@stylistic/function-paren-newline":["error","never"],"@stylistic/object-curly-newline":["error","never"],...e},format:{indentSize:2,convertTabsToSpaces:true,ensureNewLineAtEndOfFile:true,indentStyle:ts.IndentStyle.Block,semicolons:ts.SemicolonPreference.Remove,trimTrailingWhitespace:true,...t},prettier:{semi:false,singleQuote:true,jsxSingleQuote:true,arrowParens:"always",bracketSameLine:true,objectWrap:"collapse",printWidth:120,...r},...o}}var G=[I,v,K,F,A,V];async function we(e,t={}){let r={config:z(t),sourceFile:e};for(let o of G)o.match(r)&&await o.transform(r);}export{b as REACT_APIS,N as REACT_HOOKS,y as REACT_TYPES,O as SeparationIntent,I as enforceDirectExports,A as enforceEslint,F as enforceFormat,v as enforceFunctionComponent,K as enforceNamedImports,V as enforcePrettier,w as enforeLineSeparation,P as isForwardRefComponent,T as isFunctionComponent,R as isReactComponent,z as mergeConfig,we as transform,G as transformers};//# sourceMappingURL=index.js.map
4
+ `);});}var w={match:({config:e})=>e.enforceLineSeparation,transform:async({sourceFile:e})=>{P(e,(r,t)=>t instanceof ImportDeclaration&&r instanceof ImportDeclaration?1:2);}};var A={match:({config:e})=>e.enforceNamedImports,transform:async({sourceFile:e})=>{let r=e.getImportDeclarations().find(n=>n.getModuleSpecifier().getLiteralValue()==="react"),t=new Set,o=new Set;if(e.forEachDescendant(n=>{if(n.getKind()===SyntaxKind.TypeReference){let s=n.asKind(SyntaxKind.TypeReference);if(!s)return;let i=s.getTypeName();if(Node.isQualifiedName(i)){let a=i.getLeft().getText(),c=i.getRight().getText();a==="React"&&p.includes(c)&&(i.replaceWithText(c),t.add(c));}}if(n.getKind()===SyntaxKind.PropertyAccessExpression){let s=n.asKind(SyntaxKind.PropertyAccessExpression);if(!s)return;let i=s.getExpression(),a=s.getName();i.getText()==="React"&&(x.includes(a)||y.includes(a)||p.includes(a))&&(s.replaceWithText(a),p.includes(a)?t.add(a):(x.includes(a)||y.includes(a))&&o.add(a));}}),r&&(t.size>0||o.size>0)){r.removeNamespaceImport();let n=Array.from(t).sort();for(let i of n)r.addNamedImport({name:i,isTypeOnly:true});let s=Array.from(o).sort();for(let i of s)r.addNamedImport(i);}}};var I={match:({config:e})=>e.enforcePrettier,transform:async({sourceFile:e,config:r})=>{let t=await format(e.getText(),{parser:"babel-ts",...r.prettier,embeddedLanguageFormatting:"auto",quoteProps:"consistent",trailingComma:"none",singleQuote:true,jsxSingleQuote:true});e.replaceWithText(t);}};function F({eslint:e,format:r,prettier:t,...o}={}){return {enforceDirectExports:false,enforceFunctionComponent:false,enforceNamedImports:false,enforceFormat:false,enforceLineSeparation:false,enforceEslint:false,enforcePrettier:false,eslint:{"@stylistic/space-in-parens":["error"],"@stylistic/comma-spacing":["error"],"@stylistic/no-multi-spaces":["error"],"@stylistic/no-trailing-spaces":["error"],"@stylistic/no-whitespace-before-property":["error"],"@stylistic/array-bracket-newline":["error","consistent"],"@stylistic/array-bracket-spacing":["error"],"@stylistic/arrow-spacing":["error"],"@stylistic/arrow-parens":["error","always"],"@stylistic/block-spacing":["error","always"],"@stylistic/brace-style":["error","1tbs",{allowSingleLine:true}],"@stylistic/comma-dangle":["error","never"],"@stylistic/key-spacing":["error"],"@stylistic/keyword-spacing":["error"],"@stylistic/member-delimiter-style":["error",{multiline:{delimiter:"none"}}],"@stylistic/no-extra-semi":["error"],"@stylistic/indent":["error",2],"@stylistic/no-multiple-empty-lines":["error",{max:1,maxEOF:0,maxBOF:0}],"@stylistic/object-curly-spacing":["error","always"],"@stylistic/quotes":["error","single"],"@stylistic/semi":["error","never"],"@stylistic/space-before-blocks":["error","always"],"@stylistic/space-before-function-paren":["error",{anonymous:"always",named:"never",asyncArrow:"always"}],"@typescript-eslint/adjacent-overload-signatures":"error","@typescript-eslint/no-extra-non-null-assertion":"error","@typescript-eslint/no-misused-new":"error","@typescript-eslint/no-non-null-asserted-optional-chain":"error","@typescript-eslint/no-shadow":"error","@typescript-eslint/prefer-for-of":"error",...e},format:{indentSize:2,convertTabsToSpaces:true,ensureNewLineAtEndOfFile:true,indentStyle:ts.IndentStyle.Block,semicolons:ts.SemicolonPreference.Remove,trimTrailingWhitespace:true,...r},prettier:{semi:false,singleQuote:true,jsxSingleQuote:true,arrowParens:"always",bracketSameLine:true,objectWrap:"collapse",printWidth:120,...t},...o}}var J=[T,b,A,h,I,w,C];async function Ie(e,r={}){let t={config:F(r),sourceFile:e};for(let o of J)o.match(t)&&await o.transform(t);}export{y as REACT_APIS,x as REACT_HOOKS,p as REACT_TYPES,N as SeparationIntent,T as enforceDirectExports,C as enforceEslint,h as enforceFormat,b as enforceFunctionComponent,w as enforceLineSeparation,A as enforceNamedImports,I as enforcePrettier,P as enforeLineSeparation,G as isForwardRefComponent,l as isFunctionComponent,q as isReactComponent,F as mergeConfig,Ie as transform,J as transformers};//# sourceMappingURL=index.js.map
9
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/react.ts","../src/transformers/enforceDirectExports.ts","../src/transformers/enforceEslint.ts","../src/utils/trivia.ts","../src/transformers/enforceFormat.ts","../src/transformers/enforceFunctionComponent.ts","../src/transformers/enforceNamedImports.ts","../src/transformers/enforcePrettier.ts","../src/utils/config.ts","../src/utils/transform.ts"],"names":["REACT_TYPES","REACT_HOOKS","REACT_APIS","isReactComponent","varDecl","initializer","descendants","SyntaxKind","selfClosing","Node","body","bodyDescendants","bodySelfClosing","isForwardRefComponent","text","isFunctionComponent","func","enforceDirectExports","config","sourceFile","funcName","isExportedViaSeparateStatement","exportDecl","exp","matchingExports","namedExport","varName","varStatement","isExportedViaKeyword","isExported","paramsText","p","bodyText","functionBody","trimmedBody","funcText","enforceEslint","filePath","cwd","dirname","eslint","ESLint","tseslint","stylistic","result","SeparationIntent","enforeLineSeparation","predicate","instructions","syntaxList","index","prev","cur","intent","range","enforceFormat","ImportDeclaration","enforceFunctionComponent","param","typeText","typeAnnotation","writer","returnType","VariableDeclarationKind","StructureKind","enforceNamedImports","reactImport","importDeclaration","typeImportsNeeded","valueImportsNeeded","node","typeRef","typeName","left","right","propAccess","expr","name","typeImportsArray","valueImportsArray","valueName","enforcePrettier","formattedText","format","mergeConfig","prettier","ts","transformers","transform","params","transformer"],"mappings":"gQAEO,IAAMA,CAAAA,CAAc,CACzB,iBACA,uBAAA,CACA,0BAAA,CACA,IAAA,CACA,mBAAA,CACA,WAAA,CACA,cAAA,CACA,MACA,WAAA,CACA,kBAAA,CACA,eAAA,CACA,gBAAA,CACA,eAAA,CACA,eAAA,CACA,oBACA,cACF,CAAA,CAEaC,CAAAA,CAAc,CACzB,UAAA,CACA,WAAA,CACA,cACA,SAAA,CACA,QAAA,CACA,YAAA,CACA,YAAA,CACA,qBAAA,CACA,iBAAA,CACA,gBACA,eAAA,CACA,kBAAA,CACA,OAAA,CACA,sBACF,CAAA,CAEaC,CAAAA,CAAa,CACxB,YAAA,CACA,MAAA,CACA,MAAA,CACA,eAAA,CACA,eAAA,CACA,cAAA,CACA,iBACA,UAAA,CACA,UAAA,CACA,YAAA,CACA,UACF,EAEO,SAASC,EAAiBC,CAAAA,CAAuC,CACtE,GAAI,CACF,IAAMC,CAAAA,CAAcD,EAAQ,cAAA,IAAiB,CAC7C,GAAI,CAACC,CAAAA,CAAa,OAAO,GAGzB,IAAMC,CAAAA,CAAcD,CAAAA,CAAY,oBAAA,GAAuBE,UAAAA,CAAW,UAAU,GAAK,EAAC,CAC5EC,CAAAA,CAAcH,CAAAA,CAAY,oBAAA,GAAuBE,UAAAA,CAAW,qBAAqB,CAAA,EAAK,EAAC,CAE7F,GAAID,CAAAA,CAAY,MAAA,CAAS,GAAKE,CAAAA,CAAY,MAAA,CAAS,CAAA,CAAK,OAAO,CAAA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KAAA,CAC5B,WAAYA,EAAAA,CAAG,mBAAA,CAAoB,OACnC,sBAAA,CAAwB,IAAA,CACxB,GAAGH,CACL,EACA,QAAA,CAAU,CACR,KAAM,KAAA,CACN,WAAA,CAAa,KACb,cAAA,CAAgB,IAAA,CAChB,WAAA,CAAa,QAAA,CACb,gBAAiB,IAAA,CACjB,UAAA,CAAY,WACZ,UAAA,CAAY,GAAA,CACZ,GAAGE,CACL,CAAA,CACA,GAAGnE,CACL,CACF,CC7CO,IAAMqE,EAAe,CAC1BtE,CAAAA,CACAwC,EACAQ,CAAAA,CACAV,CAAAA,CACAnB,CAAAA,CACA6C,CACF,EAEA,eAAsBO,EAAAA,CACpBrE,EACAD,CAAAA,CAAyC,GAC1B,CACf,IAAMuE,CAAAA,CAA4B,CAAE,OAAQL,CAAAA,CAAYlE,CAAM,EAAG,UAAA,CAAAC,CAAW,EAC5E,IAAA,IAAWuE,CAAAA,IAAeH,CAAAA,CACpBG,CAAAA,CAAY,MAAMD,CAAM,CAAA,EAC1B,MAAMC,CAAAA,CAAY,SAAA,CAAUD,CAAM,EAGxC","file":"index.js","sourcesContent":["import { FunctionDeclaration, Node, SyntaxKind, VariableDeclaration } from 'ts-morph'\n\nexport const REACT_TYPES = [\n 'ComponentProps',\n 'ComponentPropsWithRef',\n 'ComponentPropsWithoutRef',\n 'FC',\n 'FunctionComponent',\n 'ReactNode',\n 'ReactElement',\n 'JSX',\n 'RefObject',\n 'MutableRefObject',\n 'CSSProperties',\n 'HTMLAttributes',\n 'SVGAttributes',\n 'DOMAttributes',\n 'PropsWithChildren',\n 'PropsWithRef'\n]\n\nexport const REACT_HOOKS = [\n 'useState',\n 'useEffect',\n 'useCallback',\n 'useMemo',\n 'useRef',\n 'useContext',\n 'useReducer',\n 'useImperativeHandle',\n 'useLayoutEffect',\n 'useDebugValue',\n 'useTransition',\n 'useDeferredValue',\n 'useId',\n 'useSyncExternalStore'\n]\n\nexport const REACT_APIS = [\n 'forwardRef',\n 'memo',\n 'lazy',\n 'createContext',\n 'createElement',\n 'cloneElement',\n 'isValidElement',\n 'Children',\n 'Fragment',\n 'StrictMode',\n 'Suspense'\n]\n\nexport function isReactComponent(varDecl: VariableDeclaration): boolean {\n try {\n const initializer = varDecl.getInitializer?.()\n if (!initializer) return false\n\n // Check if the initializer contains JSX\n const descendants = initializer.getDescendantsOfKind?.(SyntaxKind.JsxElement) || []\n const selfClosing = initializer.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement) || []\n\n if (descendants.length > 0 || selfClosing.length > 0) { return true }\n\n // Check if it's assigned to an arrow function that returns JSX\n if (Node.isArrowFunction(initializer)) {\n const body = initializer.getBody?.()\n if (body) {\n const bodyDescendants = body.getDescendantsOfKind?.(SyntaxKind.JsxElement) || []\n const bodySelfClosing = body.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement) || []\n return bodyDescendants.length > 0 || bodySelfClosing.length > 0\n }\n }\n\n return false\n } catch {\n return false\n }\n}\n\nexport function isForwardRefComponent(varDecl: VariableDeclaration): boolean {\n try {\n const initializer = varDecl.getInitializer?.()\n if (!initializer) return false\n\n const text = initializer.getText?.()\n return text?.includes('forwardRef(') || text?.includes('React.forwardRef(') ? true : false\n } catch {\n return false\n }\n}\n\nexport function isFunctionComponent(func: FunctionDeclaration): boolean {\n try {\n const descendants = func.getDescendantsOfKind?.(SyntaxKind.JsxElement) || []\n const selfClosing = func.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement) || []\n if (descendants.length > 0 || selfClosing.length > 0) { return true }\n return false\n } catch {\n return false\n }\n}\n","import { Node } from 'ts-morph'\nimport { isForwardRefComponent, isFunctionComponent, isReactComponent } from '../utils/react'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforceDirectExports: Transformer = {\n match: ({ config }) => config.enforceDirectExports,\n transform: async ({ sourceFile }) => {\n // Transform function declarations: add direct export if it's a component\n sourceFile.getFunctions().forEach((func) => {\n // Skip if not a component\n if (!isFunctionComponent(func)) { return }\n\n // Skip if already exported directly\n if (func.isExported() && func.hasExportKeyword()) { return }\n\n const funcName = func.getName()\n\n // Check if it's exported via separate export statement\n let isExportedViaSeparateStatement = false\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports()\n if (namedExports.some((exp) => exp.getName() === funcName)) {\n isExportedViaSeparateStatement = true\n }\n })\n\n // Only convert if it's a component that should be exported\n if (isExportedViaSeparateStatement) {\n // Add direct export modifier\n func.setIsExported(true)\n\n // Remove from separate export statements\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports()\n const matchingExports = namedExports.filter((namedExport) => namedExport.getName() === funcName)\n if (matchingExports.length > 0) {\n matchingExports.forEach((namedExport) => { namedExport.remove() })\n if (exportDecl.getNamedExports().length === 0) { exportDecl.remove() }\n }\n })\n }\n })\n\n // Transform const arrow functions to function declarations (if they're components and not forwardRef)\n sourceFile.getVariableDeclarations().forEach((varDecl) => {\n // Skip if not a component\n if (!isReactComponent(varDecl)) return\n\n // Skip forwardRef and memo patterns\n if (isForwardRefComponent(varDecl)) return\n\n const initializer = varDecl.getInitializer()\n if (!initializer || !Node.isArrowFunction(initializer)) return\n\n const varName = varDecl.getName()\n const varStatement = varDecl.getVariableStatement()\n if (!varStatement) return\n\n const isExportedViaKeyword = varStatement.hasExportKeyword()\n\n // Check if it's exported via separate export statement\n let isExportedViaSeparateStatement = false\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports()\n if (namedExports.some((exp) => exp.getName() === varName)) {\n isExportedViaSeparateStatement = true\n }\n })\n\n const isExported = isExportedViaKeyword || isExportedViaSeparateStatement\n\n // Get the parameters\n const params = initializer.getParameters()\n const paramsText = params.map((p) => p.getText()).join(', ')\n\n // Get the body\n const body = initializer.getBody()\n if (!body) return\n\n const bodyText = body.getText()\n\n // Build the function body\n let functionBody: string\n const trimmedBody = bodyText.trim()\n\n if (trimmedBody.startsWith('(') && trimmedBody.endsWith(')')) {\n // Parenthesized expression like: (\n // <button />\n // )\n const innerBody = trimmedBody.slice(1, -1).trim()\n functionBody = `{\\n return ${innerBody}\\n }`\n } else if (trimmedBody.startsWith('{')) {\n // Already a block statement\n functionBody = bodyText\n } else {\n // Simple JSX expression like: <button />\n functionBody = `{\\n return ${bodyText}\\n }`\n }\n\n const funcText = `${isExported ? 'export ' : ''}function ${varName}(${paramsText}) ${functionBody}`\n\n // Replace the variable statement with function declaration\n varStatement.replaceWithText(funcText)\n\n // Remove from separate export statements if it was exported that way\n if (isExportedViaSeparateStatement) {\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports()\n const matchingExports = namedExports.filter((namedExport) => namedExport.getName() === varName)\n\n if (matchingExports.length > 0) {\n matchingExports.forEach((namedExport) => {\n namedExport.remove()\n })\n\n // Remove the entire export declaration if no exports remain\n if (exportDecl.getNamedExports().length === 0) {\n exportDecl.remove()\n }\n }\n })\n }\n })\n }\n}\n","import stylistic from '@stylistic/eslint-plugin'\nimport { ESLint } from 'eslint'\nimport { dirname } from 'path'\nimport tseslint from 'typescript-eslint'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforceEslint: Transformer = {\n match: ({ config }) => config.enforceEslint,\n transform: async ({ sourceFile, config }) => {\n const filePath = sourceFile.getFilePath()\n const cwd = dirname(filePath)\n const eslint = new ESLint({\n fix: true,\n cwd,\n overrideConfigFile: true,\n overrideConfig: [{\n basePath: '.',\n languageOptions: {\n parser: tseslint.parser,\n ecmaVersion: 2020,\n sourceType: 'module',\n parserOptions: { ecmaFeatures: { jsx: true } }\n },\n files: ['**/*.{ts,tsx,js,jsx}'],\n plugins: { '@stylistic': stylistic },\n rules: config.eslint\n }]\n })\n\n const [result] = await eslint.lintText(sourceFile.getFullText(), { filePath })\n if (result?.output) { sourceFile.replaceWithText(result.output) }\n }\n}\n","import { Node, SourceFile, ts } from 'ts-morph'\n\nexport enum SeparationIntent { IGNORE, COMBINE, SEPARATE }\n\nexport interface SeparationEntry {\n range: [number, number]\n intent: SeparationIntent\n}\n\nexport function enforeLineSeparation(sourceFile: SourceFile, predicate: (cur: Node<ts.Node>, prev: Node<ts.Node>, triviaWidth: number) => SeparationIntent) {\n const instructions: SeparationEntry[] = []\n const syntaxList = sourceFile.getChildSyntaxListOrThrow()\n for (let index = syntaxList.getChildCount() - 1; index > 0; index -= 1) {\n const prev = syntaxList.getChildAtIndex(index - 1)\n const cur = syntaxList.getChildAtIndex(index)\n const intent = predicate(cur, prev, cur.getLeadingTriviaWidth())\n instructions.push({ range: [prev.getEnd(), cur.getStart()], intent })\n }\n instructions.forEach(({ range, intent }) => {\n if (intent === SeparationIntent.COMBINE) {\n sourceFile.replaceText(range, '\\n')\n } else if (intent === SeparationIntent.SEPARATE) {\n sourceFile.replaceText(range, '\\n\\n')\n }\n })\n}\n","import { ImportDeclaration } from 'ts-morph'\nimport { Transformer } from '../utils/transformer'\nimport { enforeLineSeparation, SeparationIntent } from '../utils/trivia'\n\nexport const enforceFormat: Transformer = {\n match: ({ config }) => config.enforceFormat,\n transform: async ({ sourceFile, config }) => {\n enforeLineSeparation(sourceFile, (cur, prev) => (prev instanceof ImportDeclaration && cur instanceof ImportDeclaration)\n ? SeparationIntent.COMBINE\n : SeparationIntent.SEPARATE\n )\n sourceFile.organizeImports()\n sourceFile.formatText(config.format)\n }\n}\n","import { StructureKind, VariableDeclarationKind } from 'ts-morph'\nimport { isFunctionComponent } from '../utils/react'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforceFunctionComponent: Transformer = {\n match: ({ config }) => config.enforceFunctionComponent,\n transform: async ({ sourceFile, config: { enforceDirectExports } }) => {\n sourceFile.getFunctions().forEach((func) => {\n if (!isFunctionComponent(func)) { return }\n\n const funcName = func.getName()\n if (!funcName) { return }\n\n const isExportedViaKeyword = func.isExported()\n let isExportedViaSeparateStatement = false\n\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports()\n if (namedExports.some((exp) => exp.getName() === funcName)) {\n isExportedViaSeparateStatement = true\n }\n })\n\n const isExported = enforceDirectExports && (isExportedViaKeyword || isExportedViaSeparateStatement)\n\n // Get the parameters with their type annotations\n const params = func.getParameters()\n const param = params[0]\n const type = param.getTypeNode() ?? param.getType()\n const typeText = type.getText()\n param.removeType()\n const typeAnnotation = typeText === 'any' ? 'React.FunctionComponent' : `React.FunctionComponent<${typeText}>`\n\n const index = func.getChildIndex()\n sourceFile.insertVariableStatement(index, {\n declarations: [{\n name: funcName,\n type: typeAnnotation,\n initializer: (writer) => {\n writer.write('(').write(func.getParameters().map((p) => p.getText()).join(', ')).write(')')\n const returnType = func.getReturnTypeNode()?.getText()\n if (returnType) { writer.write(`: ${returnType}`) }\n writer.write(' => ')\n const bodyText = func.getBody()?.getText() ?? '{}'\n writer.block(() => { writer.write(bodyText.replace(/^{|}$/g, '').trim()) })\n }\n }],\n declarationKind: VariableDeclarationKind.Const,\n kind: StructureKind.VariableStatement,\n isExported\n })\n func.remove()\n })\n }\n}\n","import { Node, SyntaxKind } from 'ts-morph'\nimport { REACT_APIS, REACT_HOOKS, REACT_TYPES } from '../utils/react'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforceNamedImports: Transformer = {\n match: ({ config }) => config.enforceNamedImports,\n transform: async ({ sourceFile }) => {\n // Find React import declaration\n const reactImport = sourceFile.getImportDeclarations().find((importDeclaration) => {\n return importDeclaration.getModuleSpecifier().getLiteralValue() === 'react'\n })\n\n // If no React import exists, no transformation needed\n if (!reactImport) { return }\n\n // Check if it's already using named imports only (early exit if enforceNamedImports is disabled)\n const namespaceImport = reactImport.getNamespaceImport()\n if (!namespaceImport) { return }\n\n // Initialize tracking sets\n const typeImportsNeeded = new Set<string>()\n const valueImportsNeeded = new Set<string>()\n\n // ============================================================\n // Phase 2 & 3: Transform Type References and Hook Calls\n // (Single-pass traversal for efficiency)\n // ============================================================\n\n sourceFile.forEachDescendant((node) => {\n // Handle TypeReference nodes (Phase 2)\n if (node.getKind() === SyntaxKind.TypeReference) {\n const typeRef = node.asKind(SyntaxKind.TypeReference)\n if (!typeRef) return\n\n const typeName = typeRef.getTypeName()\n\n // Check if it's a qualified name like React.ComponentProps or React.HTMLAttributes\n if (Node.isQualifiedName(typeName)) {\n const left = typeName.getLeft().getText()\n const right = typeName.getRight().getText()\n\n if (left === 'React') {\n // Check if it's a known React type\n if (REACT_TYPES.includes(right)) {\n typeName.replaceWithText(right)\n typeImportsNeeded.add(right)\n }\n }\n }\n }\n\n // Handle PropertyAccessExpression nodes (Phase 3)\n // This handles both React.Component and React.SomethingRef patterns\n if (node.getKind() === SyntaxKind.PropertyAccessExpression) {\n const propAccess = node.asKind(SyntaxKind.PropertyAccessExpression)\n if (!propAccess) return\n\n const expr = propAccess.getExpression()\n const name = propAccess.getName()\n\n if (expr.getText() === 'React') {\n // Check if it's a known hook or API\n if (REACT_HOOKS.includes(name) || REACT_APIS.includes(name) || REACT_TYPES.includes(name)) {\n propAccess.replaceWithText(name)\n\n // Determine if it's a type or value import\n if (REACT_TYPES.includes(name)) {\n typeImportsNeeded.add(name)\n } else if (REACT_HOOKS.includes(name) || REACT_APIS.includes(name)) {\n valueImportsNeeded.add(name)\n }\n }\n }\n }\n })\n\n // ============================================================\n // Phase 4: Import Management\n // ============================================================\n\n // Only add named imports and remove namespace if we have imports to add\n if (typeImportsNeeded.size > 0 || valueImportsNeeded.size > 0) {\n // Remove namespace import FIRST (before adding named imports)\n reactImport.removeNamespaceImport()\n\n // Add type imports (with 'type' keyword for type-only imports)\n const typeImportsArray = Array.from(typeImportsNeeded).sort()\n for (const typeName of typeImportsArray) {\n reactImport.addNamedImport({\n name: typeName,\n isTypeOnly: true\n })\n }\n\n // Add value imports\n const valueImportsArray = Array.from(valueImportsNeeded).sort()\n for (const valueName of valueImportsArray) {\n reactImport.addNamedImport(valueName)\n }\n }\n }\n}\n","import { format } from 'prettier'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforcePrettier: Transformer = {\n match: ({ config }) => config.enforcePrettier,\n transform: async ({ sourceFile, config }) => {\n const formattedText = await format(sourceFile.getText(), { parser: 'typescript', ...config.prettier })\n sourceFile.replaceWithText(formattedText)\n\n }\n}\n","import { RulesConfig } from '@eslint/core'\nimport { Options as PrettierOptions } from 'prettier'\nimport { FormatCodeSettings, ts } from 'ts-morph'\nimport { PartialDeep } from 'type-fest'\n\nexport interface TransformerConfig {\n enforceDirectExports: boolean\n enforceFunctionComponent: boolean\n enforceNamedImports: boolean\n enforceFormat: boolean\n enforceEslint: boolean\n enforcePrettier: boolean\n format: FormatCodeSettings\n prettier: PrettierOptions\n eslint: Partial<RulesConfig>\n}\n\nexport function mergeConfig({ eslint, format, prettier, ...config }: PartialDeep<TransformerConfig> = {}): TransformerConfig {\n return {\n enforceDirectExports: false,\n enforceFunctionComponent: false,\n enforceNamedImports: false,\n enforceFormat: false,\n enforceEslint: false,\n enforcePrettier: false,\n eslint: {\n '@stylistic/indent': ['error', 2],\n '@stylistic/quotes': ['error', 'single'],\n '@stylistic/semi': ['error', 'never'],\n '@stylistic/no-trailing-spaces': 'error',\n '@stylistic/no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0, 'maxBOF': 0 }],\n '@stylistic/function-paren-newline': ['error', 'never'],\n '@stylistic/object-curly-newline': ['error', 'never'],\n ...eslint\n },\n format: {\n indentSize: 2,\n convertTabsToSpaces: true,\n ensureNewLineAtEndOfFile: true,\n indentStyle: ts.IndentStyle.Block,\n semicolons: ts.SemicolonPreference.Remove,\n trimTrailingWhitespace: true,\n ...format\n },\n prettier: {\n semi: false,\n singleQuote: true,\n jsxSingleQuote: true,\n arrowParens: 'always',\n bracketSameLine: true,\n objectWrap: 'collapse',\n printWidth: 120,\n ...prettier\n },\n ...config\n }\n}\n","import { SourceFile } from 'ts-morph'\nimport { PartialDeep } from 'type-fest'\nimport { enforceDirectExports } from '../transformers/enforceDirectExports'\nimport { enforceEslint } from '../transformers/enforceEslint'\nimport { enforceFormat } from '../transformers/enforceFormat'\nimport { enforceFunctionComponent } from '../transformers/enforceFunctionComponent'\nimport { enforceNamedImports } from '../transformers/enforceNamedImports'\nimport { enforcePrettier } from '../transformers/enforcePrettier'\nimport { mergeConfig, TransformerConfig } from './config'\nimport { TransformerParams } from './transformer'\n\nexport const transformers = [\n enforceDirectExports,\n enforceFunctionComponent,\n enforceNamedImports,\n enforceFormat,\n enforceEslint,\n enforcePrettier\n]\n\nexport async function transform(\n sourceFile: SourceFile,\n config: PartialDeep<TransformerConfig> = {}\n): Promise<void> {\n const params: TransformerParams = { config: mergeConfig(config), sourceFile }\n for (const transformer of transformers) {\n if (transformer.match(params)) {\n await transformer.transform(params)\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/react.ts","../src/transformers/enforceDirectExports.ts","../src/transformers/enforceEslint.ts","../src/transformers/enforceFormat.ts","../src/transformers/enforceFunctionComponent.ts","../src/utils/trivia.ts","../src/transformers/enforceLineSeparation.ts","../src/transformers/enforceNamedImports.ts","../src/transformers/enforcePrettier.ts","../src/utils/config.ts","../src/utils/transform.ts"],"names":["REACT_TYPES","REACT_HOOKS","REACT_APIS","isReactComponent","varDecl","initializer","descendants","SyntaxKind","selfClosing","Node","body","bodyDescendants","bodySelfClosing","isForwardRefComponent","text","isFunctionComponent","func","enforceDirectExports","config","sourceFile","funcName","isExportedViaSeparateStatement","exportDecl","exp","matchingExports","namedExport","enforceEslint","filePath","cwd","dirname","eslint","ESLint","tseslint","stylistic","result","enforceFormat","enforceFunctionComponent","isExportedViaKeyword","isExported","param","typeText","typeAnnotation","index","writer","p","returnType","bodyText","VariableDeclarationKind","StructureKind","SeparationIntent","enforeLineSeparation","predicate","instructions","syntaxList","prev","cur","intent","range","enforceLineSeparation","ImportDeclaration","enforceNamedImports","reactImport","importDeclaration","typeImportsNeeded","valueImportsNeeded","node","typeRef","typeName","left","right","propAccess","expr","name","typeImportsArray","valueImportsArray","valueName","enforcePrettier","formattedText","format","mergeConfig","prettier","ts","transformers","transform","params","transformer"],"m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A,CAAiB,IAAA,CACjB,UAAA,CAAY,UAAA,CACZ,UAAA,CAAY,IACZ,GAAGE,CACL,CAAA,CACA,GAAG9D,CACL,CACF,CCpEO,IAAMgE,EAAe,CAC1BjE,CAAAA,CACAmB,CAAAA,CACAwB,CAAAA,CACAzB,CAAAA,CACAyC,CAAAA,CACAlB,CAAAA,CACAhC,CACF,EAEA,eAAsByD,EAAAA,CACpBhE,CAAAA,CACAD,CAAAA,CAAyC,EAAC,CAC3B,CACf,IAAMkE,EAA4B,CAAE,MAAA,CAAQL,CAAAA,CAAY7D,CAAM,CAAA,CAAG,UAAA,CAAAC,CAAW,CAAA,CAC5E,QAAWkE,CAAAA,IAAeH,CAAAA,CACpBG,CAAAA,CAAY,KAAA,CAAMD,CAAM,CAAA,EAC1B,MAAMC,CAAAA,CAAY,SAAA,CAAUD,CAAM,EAGxC","file":"index.js","sourcesContent":["import { FunctionDeclaration, Node, SyntaxKind, VariableDeclaration } from 'ts-morph'\n\nexport const REACT_TYPES = [\n 'ComponentProps',\n 'ComponentPropsWithRef',\n 'ComponentPropsWithoutRef',\n 'FC',\n 'FunctionComponent',\n 'ReactNode',\n 'ReactElement',\n 'JSX',\n 'RefObject',\n 'MutableRefObject',\n 'CSSProperties',\n 'HTMLAttributes',\n 'SVGAttributes',\n 'DOMAttributes',\n 'PropsWithChildren',\n 'PropsWithRef'\n]\n\nexport const REACT_HOOKS = [\n 'useState',\n 'useEffect',\n 'useCallback',\n 'useMemo',\n 'useRef',\n 'useContext',\n 'useReducer',\n 'useImperativeHandle',\n 'useLayoutEffect',\n 'useDebugValue',\n 'useTransition',\n 'useDeferredValue',\n 'useId',\n 'useSyncExternalStore'\n]\n\nexport const REACT_APIS = [\n 'forwardRef',\n 'memo',\n 'lazy',\n 'createContext',\n 'createElement',\n 'cloneElement',\n 'isValidElement',\n 'Children',\n 'Fragment',\n 'StrictMode',\n 'Suspense'\n]\n\nexport function isReactComponent(varDecl: VariableDeclaration): boolean {\n try {\n const initializer = varDecl.getInitializer?.()\n if (!initializer) return false\n\n // Check if the initializer contains JSX\n const descendants = initializer.getDescendantsOfKind?.(SyntaxKind.JsxElement) || []\n const selfClosing = initializer.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement) || []\n\n if (descendants.length > 0 || selfClosing.length > 0) { return true }\n\n // Check if it's assigned to an arrow function that returns JSX\n if (Node.isArrowFunction(initializer)) {\n const body = initializer.getBody?.()\n if (body) {\n const bodyDescendants = body.getDescendantsOfKind?.(SyntaxKind.JsxElement) || []\n const bodySelfClosing = body.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement) || []\n return bodyDescendants.length > 0 || bodySelfClosing.length > 0\n }\n }\n\n return false\n } catch {\n return false\n }\n}\n\nexport function isForwardRefComponent(varDecl: VariableDeclaration): boolean {\n try {\n const initializer = varDecl.getInitializer?.()\n if (!initializer) return false\n\n const text = initializer.getText?.()\n return text?.includes('forwardRef(') || text?.includes('React.forwardRef(') ? true : false\n } catch {\n return false\n }\n}\n\nexport function isFunctionComponent(func: FunctionDeclaration): boolean {\n try {\n const descendants = func.getDescendantsOfKind?.(SyntaxKind.JsxElement) || []\n const selfClosing = func.getDescendantsOfKind?.(SyntaxKind.JsxSelfClosingElement) || []\n if (descendants.length > 0 || selfClosing.length > 0) { return true }\n return false\n } catch {\n return false\n }\n}\n","import { isFunctionComponent } from '../utils/react'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforceDirectExports: Transformer = {\n match: ({ config }) => config.enforceDirectExports,\n transform: async ({ sourceFile }) => {\n // Transform function declarations: add direct export if it's a component\n sourceFile.getFunctions().forEach((func) => {\n // Skip if not a component\n if (!isFunctionComponent(func)) { return }\n\n // Skip if already exported directly\n if (func.isExported() && func.hasExportKeyword()) { return }\n\n const funcName = func.getName()\n\n // Check if it's exported via separate export statement\n let isExportedViaSeparateStatement = false\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports()\n if (namedExports.some((exp) => exp.getName() === funcName)) {\n isExportedViaSeparateStatement = true\n }\n })\n\n // Only convert if it's a component that should be exported\n if (isExportedViaSeparateStatement) {\n // Add direct export modifier\n func.setIsExported(true)\n\n // Remove from separate export statements\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports()\n const matchingExports = namedExports.filter((namedExport) => namedExport.getName() === funcName)\n if (matchingExports.length > 0) {\n matchingExports.forEach((namedExport) => { namedExport.remove() })\n if (exportDecl.getNamedExports().length === 0) { exportDecl.remove() }\n }\n })\n }\n })\n }\n}\n","import stylistic from '@stylistic/eslint-plugin'\nimport { ESLint } from 'eslint'\nimport { dirname } from 'path'\nimport tseslint from 'typescript-eslint'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforceEslint: Transformer = {\n match: ({ config }) => config.enforceEslint,\n transform: async ({ sourceFile, config }) => {\n const filePath = sourceFile.getFilePath()\n const cwd = dirname(filePath)\n const eslint = new ESLint({\n fix: true,\n cwd,\n overrideConfigFile: true,\n overrideConfig: [{\n basePath: '.',\n languageOptions: {\n parser: tseslint.parser,\n ecmaVersion: 2020,\n sourceType: 'module',\n parserOptions: { ecmaFeatures: { jsx: true } }\n },\n files: ['**/*.{ts,tsx,js,jsx}'],\n plugins: {\n '@stylistic': stylistic,\n '@typescript-eslint': tseslint.plugin\n },\n rules: config.eslint\n }]\n })\n\n const [result] = await eslint.lintText(sourceFile.getFullText(), { filePath })\n if (result?.output) { sourceFile.replaceWithText(result.output) }\n }\n}\n","import { Transformer } from '../utils/transformer'\n\nexport const enforceFormat: Transformer = {\n match: ({ config }) => config.enforceFormat,\n transform: async ({ sourceFile, config }) => {\n sourceFile.organizeImports()\n sourceFile.formatText(config.format)\n }\n}\n","import { StructureKind, VariableDeclarationKind } from 'ts-morph'\nimport { isFunctionComponent } from '../utils/react'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforceFunctionComponent: Transformer = {\n match: ({ config }) => config.enforceFunctionComponent,\n transform: async ({ sourceFile, config: { enforceDirectExports } }) => {\n sourceFile.getFunctions().forEach((func) => {\n if (!isFunctionComponent(func)) { return }\n\n const funcName = func.getName()\n if (!funcName) { return }\n\n const isExportedViaKeyword = func.isExported()\n let isExportedViaSeparateStatement = false\n\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports()\n if (namedExports.some((exp) => exp.getName() === funcName)) {\n isExportedViaSeparateStatement = true\n }\n })\n\n const isExported = enforceDirectExports && (isExportedViaKeyword || isExportedViaSeparateStatement)\n\n // Get the parameters with their type annotations\n const params = func.getParameters()\n const param = params[0]\n const type = param.getTypeNode() ?? param.getType()\n const typeText = type.getText()\n param.removeType()\n const typeAnnotation = typeText === 'any' ? 'React.FunctionComponent' : `React.FunctionComponent<${typeText}>`\n\n const index = func.getChildIndex()\n sourceFile.insertVariableStatement(index, {\n declarations: [{\n name: funcName,\n type: typeAnnotation,\n initializer: (writer) => {\n writer.write('(').write(func.getParameters().map((p) => p.getText()).join(', ')).write(')')\n const returnType = func.getReturnTypeNode()?.getText()\n if (returnType) { writer.write(`: ${returnType}`) }\n writer.write(' => ')\n const bodyText = func.getBody()?.getText() ?? '{}'\n writer.block(() => { writer.write(bodyText.replace(/^{|}$/g, '').trim()) })\n }\n }],\n declarationKind: VariableDeclarationKind.Const,\n kind: StructureKind.VariableStatement,\n isExported\n })\n func.remove()\n })\n }\n}\n","import { Node, SourceFile, ts } from 'ts-morph'\n\nexport enum SeparationIntent { IGNORE, COMBINE, SEPARATE }\n\nexport interface SeparationEntry {\n range: [number, number]\n intent: SeparationIntent\n}\n\nexport function enforeLineSeparation(sourceFile: SourceFile, predicate: (cur: Node<ts.Node>, prev: Node<ts.Node>, triviaWidth: number) => SeparationIntent) {\n const instructions: SeparationEntry[] = []\n const syntaxList = sourceFile.getChildSyntaxListOrThrow()\n for (let index = syntaxList.getChildCount() - 1; index > 0; index -= 1) {\n const prev = syntaxList.getChildAtIndex(index - 1)\n const cur = syntaxList.getChildAtIndex(index)\n const intent = predicate(cur, prev, cur.getLeadingTriviaWidth())\n instructions.push({ range: [prev.getEnd(), cur.getStart()], intent })\n }\n instructions.forEach(({ range, intent }) => {\n if (intent === SeparationIntent.COMBINE) {\n sourceFile.replaceText(range, '\\n')\n } else if (intent === SeparationIntent.SEPARATE) {\n sourceFile.replaceText(range, '\\n\\n')\n }\n })\n}\n","import { ImportDeclaration } from 'ts-morph'\nimport { Transformer } from '../utils/transformer'\nimport { enforeLineSeparation, SeparationIntent } from '../utils/trivia'\n\nexport const enforceLineSeparation: Transformer = {\n match: ({ config }) => config.enforceLineSeparation,\n transform: async ({ sourceFile }) => {\n enforeLineSeparation(sourceFile, (cur, prev) => (prev instanceof ImportDeclaration && cur instanceof ImportDeclaration)\n ? SeparationIntent.COMBINE\n : SeparationIntent.SEPARATE\n )\n }\n}\n","import { Node, SyntaxKind } from 'ts-morph'\nimport { REACT_APIS, REACT_HOOKS, REACT_TYPES } from '../utils/react'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforceNamedImports: Transformer = {\n match: ({ config }) => config.enforceNamedImports,\n transform: async ({ sourceFile }) => {\n // Find React import declaration\n const reactImport = sourceFile.getImportDeclarations().find((importDeclaration) => {\n return importDeclaration.getModuleSpecifier().getLiteralValue() === 'react'\n })\n\n // Initialize tracking sets\n const typeImportsNeeded = new Set<string>()\n const valueImportsNeeded = new Set<string>()\n\n // ============================================================\n // Phase 2 & 3: Transform Type References and Hook Calls\n // (Single-pass traversal for efficiency)\n // ============================================================\n\n sourceFile.forEachDescendant((node) => {\n // Handle TypeReference nodes (Phase 2)\n if (node.getKind() === SyntaxKind.TypeReference) {\n const typeRef = node.asKind(SyntaxKind.TypeReference)\n if (!typeRef) return\n\n const typeName = typeRef.getTypeName()\n\n // Check if it's a qualified name like React.ComponentProps or React.HTMLAttributes\n if (Node.isQualifiedName(typeName)) {\n const left = typeName.getLeft().getText()\n const right = typeName.getRight().getText()\n\n if (left === 'React') {\n // Check if it's a known React type\n if (REACT_TYPES.includes(right)) {\n typeName.replaceWithText(right)\n typeImportsNeeded.add(right)\n }\n }\n }\n }\n\n // Handle PropertyAccessExpression nodes (Phase 3)\n // This handles both React.Component and React.SomethingRef patterns\n if (node.getKind() === SyntaxKind.PropertyAccessExpression) {\n const propAccess = node.asKind(SyntaxKind.PropertyAccessExpression)\n if (!propAccess) return\n\n const expr = propAccess.getExpression()\n const name = propAccess.getName()\n\n if (expr.getText() === 'React') {\n // Check if it's a known hook or API\n if (REACT_HOOKS.includes(name) || REACT_APIS.includes(name) || REACT_TYPES.includes(name)) {\n propAccess.replaceWithText(name)\n\n // Determine if it's a type or value import\n if (REACT_TYPES.includes(name)) {\n typeImportsNeeded.add(name)\n } else if (REACT_HOOKS.includes(name) || REACT_APIS.includes(name)) {\n valueImportsNeeded.add(name)\n }\n }\n }\n }\n })\n\n // ============================================================\n // Phase 4: Import Management\n // ============================================================\n\n // Only add named imports and remove namespace if we have imports to add\n if (reactImport && (typeImportsNeeded.size > 0 || valueImportsNeeded.size > 0)) {\n // Remove namespace import FIRST (before adding named imports)\n reactImport.removeNamespaceImport()\n\n // Add type imports (with 'type' keyword for type-only imports)\n const typeImportsArray = Array.from(typeImportsNeeded).sort()\n for (const typeName of typeImportsArray) {\n reactImport.addNamedImport({ name: typeName, isTypeOnly: true })\n }\n\n // Add value imports\n const valueImportsArray = Array.from(valueImportsNeeded).sort()\n for (const valueName of valueImportsArray) {\n reactImport.addNamedImport(valueName)\n }\n }\n }\n}\n","import { format } from 'prettier'\nimport { Transformer } from '../utils/transformer'\n\nexport const enforcePrettier: Transformer = {\n match: ({ config }) => config.enforcePrettier,\n transform: async ({ sourceFile, config }) => {\n const formattedText = await format(sourceFile.getText(), {\n parser: 'babel-ts',\n ...config.prettier,\n embeddedLanguageFormatting: 'auto',\n quoteProps: 'consistent',\n trailingComma: 'none',\n singleQuote: true,\n jsxSingleQuote: true\n })\n sourceFile.replaceWithText(formattedText)\n }\n}\n","import { RulesConfig } from '@eslint/core'\nimport { Options as PrettierOptions } from 'prettier'\nimport { FormatCodeSettings, ts } from 'ts-morph'\nimport { PartialDeep } from 'type-fest'\n\nexport interface TransformerConfig {\n enforceDirectExports: boolean\n enforceFunctionComponent: boolean\n enforceNamedImports: boolean\n enforceFormat: boolean\n enforceLineSeparation: boolean\n enforceEslint: boolean\n enforcePrettier: boolean\n format: FormatCodeSettings\n prettier: PrettierOptions\n eslint: Partial<RulesConfig>\n}\n\nexport function mergeConfig({ eslint, format, prettier, ...config }: PartialDeep<TransformerConfig> = {}): TransformerConfig {\n return {\n enforceDirectExports: false,\n enforceFunctionComponent: false,\n enforceNamedImports: false,\n enforceFormat: false,\n enforceLineSeparation: false,\n enforceEslint: false,\n enforcePrettier: false,\n eslint: {\n '@stylistic/space-in-parens': ['error'],\n '@stylistic/comma-spacing': ['error'],\n '@stylistic/no-multi-spaces': ['error'],\n '@stylistic/no-trailing-spaces': ['error'],\n '@stylistic/no-whitespace-before-property': ['error'],\n '@stylistic/array-bracket-newline': ['error', 'consistent'],\n '@stylistic/array-bracket-spacing': ['error'],\n '@stylistic/arrow-spacing': ['error'],\n '@stylistic/arrow-parens': ['error', 'always'],\n '@stylistic/block-spacing': ['error', 'always'],\n '@stylistic/brace-style': ['error', '1tbs', { 'allowSingleLine': true }],\n '@stylistic/comma-dangle': ['error', 'never'],\n '@stylistic/key-spacing': ['error'],\n '@stylistic/keyword-spacing': ['error'],\n '@stylistic/member-delimiter-style': ['error', { 'multiline': { 'delimiter': 'none' } }],\n '@stylistic/no-extra-semi': ['error'],\n '@stylistic/indent': ['error', 2],\n '@stylistic/no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0, 'maxBOF': 0 }],\n '@stylistic/object-curly-spacing': ['error', 'always'],\n '@stylistic/quotes': ['error', 'single'],\n '@stylistic/semi': ['error', 'never'],\n '@stylistic/space-before-blocks': ['error', 'always'],\n '@stylistic/space-before-function-paren': ['error', { 'anonymous': 'always', 'named': 'never', 'asyncArrow': 'always' }],\n '@typescript-eslint/adjacent-overload-signatures': 'error',\n '@typescript-eslint/no-extra-non-null-assertion': 'error',\n '@typescript-eslint/no-misused-new': 'error',\n '@typescript-eslint/no-non-null-asserted-optional-chain': 'error',\n '@typescript-eslint/no-shadow': 'error',\n '@typescript-eslint/prefer-for-of': 'error',\n ...eslint\n },\n format: {\n indentSize: 2,\n convertTabsToSpaces: true,\n ensureNewLineAtEndOfFile: true,\n indentStyle: ts.IndentStyle.Block,\n semicolons: ts.SemicolonPreference.Remove,\n trimTrailingWhitespace: true,\n ...format\n },\n prettier: {\n semi: false,\n singleQuote: true,\n jsxSingleQuote: true,\n arrowParens: 'always',\n bracketSameLine: true,\n objectWrap: 'collapse',\n printWidth: 120,\n ...prettier\n },\n ...config\n }\n}\n","import { SourceFile } from 'ts-morph'\nimport { PartialDeep } from 'type-fest'\nimport { enforceDirectExports } from '../transformers/enforceDirectExports'\nimport { enforceEslint } from '../transformers/enforceEslint'\nimport { enforceFormat } from '../transformers/enforceFormat'\nimport { enforceFunctionComponent } from '../transformers/enforceFunctionComponent'\nimport { enforceLineSeparation } from '../transformers/enforceLineSeparation'\nimport { enforceNamedImports } from '../transformers/enforceNamedImports'\nimport { enforcePrettier } from '../transformers/enforcePrettier'\nimport { mergeConfig, TransformerConfig } from './config'\nimport { TransformerParams } from './transformer'\n\nexport const transformers = [\n enforceDirectExports,\n enforceFunctionComponent,\n enforceNamedImports,\n enforceFormat,\n enforcePrettier,\n enforceLineSeparation,\n enforceEslint\n]\n\nexport async function transform(\n sourceFile: SourceFile,\n config: PartialDeep<TransformerConfig> = {}\n): Promise<void> {\n const params: TransformerParams = { config: mergeConfig(config), sourceFile }\n for (const transformer of transformers) {\n if (transformer.match(params)) {\n await transformer.transform(params)\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-morph-react",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A collection of transformers for ts-morph to refactor react code",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -41,6 +41,7 @@
41
41
  "devDependencies": {
42
42
  "@base-ui/react": "^1.0.0",
43
43
  "@types/node": "^25.0.3",
44
+ "class-variance-authority": "^0.7.1",
44
45
  "cli-highlight": "^2.1.11",
45
46
  "react": "^19.2.3",
46
47
  "rimraf": "^6.0.1",