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

Remove typechain regex fixes #1292

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions dev/scripts/src/contract/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
// eslint-disable-next-line no-useless-escape
const regex = /(import(?:(?!from).)+from\s+)(['"]\.[./\w-]+['"])(\s+assert\s+\{[^}]*\})?/gs
const fileContents = fs.readFileSync(filePath, 'utf8')
let replaced = fileContents.replace(regex, (match, p1, p2, p3) => {

Check failure on line 70 in dev/scripts/src/contract/import.ts

View workflow job for this annotation

GitHub Actions / check

'replaced' is never reassigned. Use 'const' instead
const start = p1.toString()
const srcQuoted = p2.toString()
const src = getPath(srcQuoted)
Expand All @@ -93,33 +93,6 @@
if (verbose) console.log(`Replacing \n\t${match}\nwith\n\t${result}\nin ${filePath}`)
return `${result}`
})
// eslint-disable-next-line no-useless-escape
replaced = replaced.replace(/\n(.*)\n(\s*)\/\/\s*@ts-ignore/g, (match, p1, p2) => {
// don't replace if already ignored by eslint
if (p1.includes('eslint-disable-next-line')) return match
const result = `\n${p1}\n${p2}// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n${p2}// @ts-ignore`
if (verbose) console.log(`Replacing \n\t${match}\nwith\n\t${result}\nin ${filePath}`)
return result
})

// replace EventRecord with EventRecord[]
// eslint-disable-next-line no-useless-escape
replaced = replaced.replace(/: EventRecord\)/g, (match) => {
const result = `: EventRecord[])`
if (verbose) console.log(`Replacing \n\t${match}\nwith\n\t${result}\nin ${filePath}`)
return result
})

// replace EventRecord incorrect imports
// eslint-disable-next-line no-useless-escape
replaced = replaced.replace(
/import\s+type\s+\{\s*EventRecord\s*\}\s+from\s+['"]@polkadot\/api\/submittable["']/g,
(match) => {
const result = `import type { EventRecord } from '@polkadot/types/interfaces'`
if (verbose) console.log(`Replacing \n\t${match}\nwith\n\t${result}\nin ${filePath}`)
return result
}
)

fs.writeFileSync(filePath, replaced)
}
Expand All @@ -131,7 +104,7 @@

const writeIndexJsFiles = (src: string) => {
// loop through all dirs
const typeChainDirs = fs.readdirSync(src).filter((file) => {

Check warning on line 107 in dev/scripts/src/contract/import.ts

View workflow job for this annotation

GitHub Actions / check

'typeChainDirs' is assigned a value but never used
return fs.lstatSync(`${src}/${file}`).isDirectory()
})
const rootExports: string[] = []
Expand Down
Loading