Skip to content

Commit

Permalink
feat: cannot use create-index for short folders (#51)
Browse files Browse the repository at this point in the history
* feat: file cannot be started from _ and be one symbol
* test: add children-directories-short-name for readDirectory
  • Loading branch information
Beraliv authored and gajus committed Oct 27, 2019
1 parent 6aac149 commit 1f87f9a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utilities/readDirectory.js
Expand Up @@ -17,7 +17,7 @@ const hasMultipleExtensions = (fileName) => {
};

const isSafeName = (fileName) => {
return /^[a-z][a-z0-9._]+$/i.test(fileName);
return /^[a-z_][a-z0-9._]*$/i.test(fileName);
};

const stripExtension = (fileName) => {
Expand Down
@@ -0,0 +1 @@
// @create-index
@@ -0,0 +1 @@
// @create-index
@@ -0,0 +1 @@
// @create-index
@@ -0,0 +1 @@
// @create-index
7 changes: 7 additions & 0 deletions test/readDirectory.js
Expand Up @@ -21,6 +21,13 @@ describe('readDirectory()', () => {
expect(names).to.deep.equal(['present.js']);
});
});
context('target directory contains child directories (short safe name)', () => {
it('gets names of the children directories', () => {
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-short-name'));

expect(names).to.deep.equal(['F', 'T', '__', 'o']);
});
});
context('target directory contains child directories (unsafe name)', () => {
it('gets names of the children directories', () => {
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-unsafe-name'));
Expand Down

0 comments on commit 1f87f9a

Please sign in to comment.