Skip to content

Commit 3c45f79

Browse files
committed
fix: @putout/operator-filesystem: findFile: exclude fn: drop, no place where it can be used
1 parent 55a774c commit 3c45f79

File tree

3 files changed

+3
-45
lines changed

3 files changed

+3
-45
lines changed

packages/operator-filesystem/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const [dirPath] = findFile(ast, 'hello');
3737
const newDirectoryPath = createDirectory(dirPath, 'world');
3838
```
3939

40-
### `findFile(directoryPath: DirectoryPath, name: string | string[], exclude?: string[] | (FilePath) => boolean): (FilePath | DirectoryPath)[]`
40+
### `findFile(directoryPath: DirectoryPath, name: string | string[], exclude?: string[]): (FilePath | DirectoryPath)[]`
4141

4242
```js
4343
const {operator} = require('putout');
@@ -63,11 +63,6 @@ import {operator} from 'putout';
6363
const {findFile, getFilename} = operator;
6464

6565
const coupleFilesWithExcludeArray = findFile(ast, '*.ts', ['*.d.ts']);
66-
67-
const coupleFilesWithExcludeFn = findFile(ast, '*.ts', (filePath) => {
68-
const name = getFilename(filePath);
69-
return !name.endsWith('*.d.ts');
70-
});
7166
```
7267

7368
And even search for a directory:

packages/operator-filesystem/lib/filesystem.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111
} = require('@putout/operate');
1212

1313
const maybeFS = require('./maybe-fs');
14-
const isFn = (a) => typeof a === 'function';
14+
1515
const isString = (a) => typeof a === 'string';
1616
const {isArray} = Array;
1717
const maybeArray = (a) => isArray(a) ? a : [a];
@@ -65,10 +65,7 @@ module.exports.getParentDirectory = (filePath) => {
6565

6666
module.exports.findFile = findFile;
6767

68-
function isExcluded({path, name, base, exclude}) {
69-
if (isFn(exclude))
70-
return exclude(path);
71-
68+
function isExcluded({name, base, exclude}) {
7269
for (const currentExclude of exclude) {
7370
if (name === currentExclude || getRegExp(currentExclude).test(base))
7471
return true;
@@ -91,7 +88,6 @@ function findFile(node, name, exclude = []) {
9188
if (value === name || getRegExp(name).test(base)) {
9289
const path = filenamePath.parentPath;
9390
const excluded = isExcluded({
94-
path,
9591
name,
9692
base,
9793
exclude,

packages/operator-filesystem/lib/filesystem.spec.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -179,39 +179,6 @@ test('putout: operator: filesystem: findFile: exclude', (t) => {
179179
t.end();
180180
});
181181

182-
test('putout: operator: filesystem: findFile: exclude: function', (t) => {
183-
const ast = parseFilesystem([
184-
'/',
185-
'/hello/',
186-
['/hello/world.js', 'const a = 5'],
187-
['/hello/hello.js', 'const a = <A></A>'],
188-
]);
189-
190-
const exclude = (path) => {
191-
const source = readFileContent(path);
192-
return source.includes('<');
193-
};
194-
195-
findFile(ast, '*.js', exclude).map(removeFile);
196-
197-
const expected = {
198-
type: 'directory',
199-
filename: '/',
200-
files: [{
201-
type: 'directory',
202-
filename: '/hello',
203-
files: [{
204-
type: 'file',
205-
filename: '/hello/hello.js',
206-
content: 'const a = <A></A>',
207-
}],
208-
}],
209-
};
210-
211-
t.equalFilesystems(ast, expected);
212-
t.end();
213-
});
214-
215182
test('putout: operator: filesystem: findFile: no names', (t) => {
216183
const ast = parse(montag`
217184
${FS}({

0 commit comments

Comments
 (0)