From 1f87f9a8b34b5ad9d2780852ece3e84c3817274d Mon Sep 17 00:00:00 2001 From: beraliv Date: Sun, 27 Oct 2019 16:37:12 +0300 Subject: [PATCH] feat: cannot use create-index for short folders (#51) * feat: file cannot be started from _ and be one symbol * test: add children-directories-short-name for readDirectory --- src/utilities/readDirectory.js | 2 +- .../children-directories-short-name/F/index.js | 1 + .../children-directories-short-name/T/index.js | 1 + .../children-directories-short-name/__/index.js | 1 + .../children-directories-short-name/o/index.js | 1 + test/readDirectory.js | 7 +++++++ 6 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/read-directory/children-directories-short-name/F/index.js create mode 100644 test/fixtures/read-directory/children-directories-short-name/T/index.js create mode 100644 test/fixtures/read-directory/children-directories-short-name/__/index.js create mode 100644 test/fixtures/read-directory/children-directories-short-name/o/index.js diff --git a/src/utilities/readDirectory.js b/src/utilities/readDirectory.js index f7a7e09..1fa333d 100644 --- a/src/utilities/readDirectory.js +++ b/src/utilities/readDirectory.js @@ -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) => { diff --git a/test/fixtures/read-directory/children-directories-short-name/F/index.js b/test/fixtures/read-directory/children-directories-short-name/F/index.js new file mode 100644 index 0000000..b83b7f9 --- /dev/null +++ b/test/fixtures/read-directory/children-directories-short-name/F/index.js @@ -0,0 +1 @@ +// @create-index diff --git a/test/fixtures/read-directory/children-directories-short-name/T/index.js b/test/fixtures/read-directory/children-directories-short-name/T/index.js new file mode 100644 index 0000000..b83b7f9 --- /dev/null +++ b/test/fixtures/read-directory/children-directories-short-name/T/index.js @@ -0,0 +1 @@ +// @create-index diff --git a/test/fixtures/read-directory/children-directories-short-name/__/index.js b/test/fixtures/read-directory/children-directories-short-name/__/index.js new file mode 100644 index 0000000..b83b7f9 --- /dev/null +++ b/test/fixtures/read-directory/children-directories-short-name/__/index.js @@ -0,0 +1 @@ +// @create-index diff --git a/test/fixtures/read-directory/children-directories-short-name/o/index.js b/test/fixtures/read-directory/children-directories-short-name/o/index.js new file mode 100644 index 0000000..b83b7f9 --- /dev/null +++ b/test/fixtures/read-directory/children-directories-short-name/o/index.js @@ -0,0 +1 @@ +// @create-index diff --git a/test/readDirectory.js b/test/readDirectory.js index 31ea9be..90c1fd0 100644 --- a/test/readDirectory.js +++ b/test/readDirectory.js @@ -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'));