-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a codemod for transforming configs to the new format
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** @type {import('jscodeshift').Transform} */ | ||
export default function transformer(file, api) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
// Add "fsd/" prefix to FSD rule names | ||
root | ||
.find(j.Literal) | ||
.filter((path) => ruleNames.includes(path.node.value)) | ||
.replaceWith((path) => j.stringLiteral(`fsd/${path.node.value}`)) | ||
|
||
// Make the default export or the argument of `defineConfig` an array | ||
const defineConfigCalls = root.find(j.CallExpression).filter((path) => path.node.callee.name === 'defineConfig') | ||
|
||
if (defineConfigCalls.length > 0) { | ||
defineConfigCalls | ||
.find(j.ObjectExpression) | ||
.at(0) | ||
.replaceWith((path) => j.arrayExpression([path.value])) | ||
} else { | ||
root.find(j.ExportDefaultDeclaration).forEach((path) => { | ||
path.value.declaration = j.arrayExpression([path.value.declaration]) | ||
}) | ||
} | ||
|
||
return root.toSource() | ||
} | ||
|
||
const ruleNames = [ | ||
'ambiguous-slice-names', | ||
'excessive-slicing', | ||
'forbidden-imports', | ||
'inconsistent-naming', | ||
'insignificant-slice', | ||
'no-layer-public-api', | ||
'no-public-api-sidestep', | ||
'no-reserved-folder-names', | ||
'no-segmentless-slices', | ||
'no-segments-on-sliced-layers', | ||
'public-api', | ||
'repetitive-naming', | ||
'segments-by-purpose', | ||
'shared-lib-grouping', | ||
'no-processes', | ||
'import-locality', | ||
] |