Skip to content

Commit

Permalink
fix: fixes eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
guatedude2 committed Jun 1, 2022
1 parent c24d411 commit 4900675
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 406 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
npm-debug.log
yarn-error.log
lib/
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "echo 'Not a runnable module' && exit 1",
"test": "jest",
"build": "tsc",
"lint": "eslint lib test",
"lint": "eslint src test",
"preversion": "npm run lint && npm test"
},
"keywords": [
Expand All @@ -30,7 +30,8 @@
"@types/jest": "^27.5.1",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"eslint": "^6.7.2",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.1.0",
"prettier": "^2.6.2",
Expand Down
25 changes: 12 additions & 13 deletions src/build-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ export const buildFilter = (filtersParam: string | string[]) => {
while (filters.length > 0) {
const filter = filters.shift();
filterArray.push(
'\\/?' +
filter
.replace(/\./g, '\\.')
.replace(/(\*?)(\*)(?!\*)/g, function (match, prefix) {
if (prefix == '*') {
return match;
}
return '[^\\/]*';
})
.replace(/\?/g, '[^\\/]?')
.replace(/\*\*/g, '.*')
.replace(/([\-\+\|])/g, '\\$1'),
`\\/?${filter
.replace(/\./g, '\\.')
.replace(/(\*?)(\*)(?!\*)/g, (match, prefix) => {
if (prefix === '*') {
return match;
}
return '[^\\/]*';
})
.replace(/\?/g, '[^\\/]?')
.replace(/\*\*/g, '.*')
.replace(/([\-\+\|])/g, '\\$1')}`,
);
}
return new RegExp('^' + filterArray.join('|') + '$', 'i');
return new RegExp(`^${filterArray.join('|')}$`, 'i');
};
4 changes: 2 additions & 2 deletions src/readfiles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('readfiles', () => {
});

it("callback returns the relative path of the files when 'filenameFormat' is 'readfiles.RELATIVE'", done => {
let count = 0;
const count = 0;
const expectFiles = [
'abc.txt',
'abc123.txt',
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('readfiles', () => {
});

it("callback returns only the filename of the file when 'filenameFormat' is 'readfiles.FILENAME'", done => {
let count = 0;
const count = 0;
const expectFiles = [
'abc.txt',
'abc123.txt',
Expand Down
10 changes: 7 additions & 3 deletions src/readfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export interface ReadfilesOptions {
encoding?: BufferEncoding;
}

type AsyncFunction = (done: () => void) => void;

export type ReadfilesCallback = (
err: Error | null,
relativeFilename: string,
content: string | null,
stat: fs.Stats,
) => void | Function;
) => void | AsyncFunction;

export function readfiles(dir: string): Promise<string[]>;
export function readfiles(dir: string, callback?: ReadfilesCallback): Promise<string[]>;
Expand All @@ -37,6 +39,7 @@ export function readfiles(
options = {};
}
options = options || {};
// eslint-disable-next-line @typescript-eslint/no-empty-function
callback = typeof callback === 'function' ? callback : () => {};

return new Promise((resolve, reject) => {
Expand All @@ -45,7 +48,8 @@ export function readfiles(
const filterRegExp = options.filter && buildFilter(options.filter);

const traverseDir = (dirPath, done) => {
fs.readdir(dirPath, (err, fileList) => {
fs.readdir(dirPath, (err, fileListProp) => {
let fileList = fileListProp;
if (err) {
// if rejectOnError is not false, reject the promise
if (options.rejectOnError !== false) {
Expand Down Expand Up @@ -108,7 +112,7 @@ export function readfiles(
});
} else if (stat.isFile()) {
// test filters, if it does not match move to next file
if (filterRegExp && !filterRegExp.test('/' + relFilename)) {
if (filterRegExp && !filterRegExp.test(`/${relFilename}`)) {
return next();
}

Expand Down
1 change: 1 addition & 0 deletions test/fs-helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as fs from 'fs';

const fattenFixtures = (fixtureMap: Record<string, any>, rootPath = '') => {
Expand Down
Loading

0 comments on commit 4900675

Please sign in to comment.