-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for directories and files with digit prefix (#10667)
* Test for directories and files with digit prefix * lint (cherry picked from commit 5f540a7)
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
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
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,31 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { expect } from 'chai' | ||
|
||
// Directories that start with a number do not currently work with typechain (https://github.com/dethcrypto/TypeChain/issues/794) | ||
describe('Directory', () => { | ||
it('Should not have a file or directory starting with a number in contracts/src', () => { | ||
const srcPath = path.join(__dirname, '..', '..', 'src') | ||
|
||
const noNumbersAsFirstChar = (dirPath: string): boolean => { | ||
const entries = fs.readdirSync(dirPath, { withFileTypes: true }) | ||
|
||
for (const entry of entries) { | ||
if (/^\d/.test(entry.name)) { | ||
throw new Error( | ||
`${path.join(dirPath, entry.name)} starts with a number`, | ||
) | ||
} | ||
|
||
if (entry.isDirectory()) { | ||
const newPath = path.join(dirPath, entry.name) | ||
noNumbersAsFirstChar(newPath) | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
expect(noNumbersAsFirstChar(srcPath)).to.be.true | ||
}) | ||
}) |