Skip to content

Commit

Permalink
Add a codemod for transforming configs to the new format
Browse files Browse the repository at this point in the history
  • Loading branch information
illright committed Aug 19, 2024
1 parent 3682e0d commit 162b0c5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/steiger/migrations/transform-config.js
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',
]

0 comments on commit 162b0c5

Please sign in to comment.