Skip to content

Commit

Permalink
Merge pull request #244 from mrmlnc/update_lint_rules
Browse files Browse the repository at this point in the history
Fix linter issues after config updation
  • Loading branch information
mrmlnc committed Dec 26, 2019
2 parents 0f7cdcf + b53fd72 commit ce1bff9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"compute-stdev": "^1.0.0",
"easy-table": "^1.1.1",
"eslint": "^6.5.1",
"eslint-config-mrmlnc": "^1.0.1",
"eslint-config-mrmlnc": "^1.1.0",
"execa": "^2.0.4",
"fast-glob": "^3.0.4",
"glob": "^7.1.4",
Expand Down
1 change: 0 additions & 1 deletion src/benchmark/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default class Runner {
BENCHMARK_OPTIONS: JSON.stringify(this._options.options)
};

// eslint-disable-next-line unicorn/prevent-abbreviations
const execaOptions: execa.SyncOptions = { env: environment, extendEnv: true };

const stdout = this.execNodeProcess([suitePath], execaOptions);
Expand Down
32 changes: 16 additions & 16 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as assert from 'assert';

import * as tests from './tests';
import { EntryItem, ErrnoException } from './types';
import * as pkg from '.';
import * as fg from '.';

describe('Package', () => {
describe('.sync', () => {
it('should throw an error when input values can not pass validation', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assert.throws(() => pkg.sync(null as any), /TypeError: Patterns must be a string or an array of strings/);
assert.throws(() => fg.sync(null as any), /TypeError: Patterns must be a string or an array of strings/);
});

it('should returns entries', () => {
Expand All @@ -22,7 +22,7 @@ describe('Package', () => {
'fixtures/second/nested/file.md'
];

const actual = pkg.sync(['fixtures/**/*.md']);
const actual = fg.sync(['fixtures/**/*.md']);

actual.sort((a, b) => a.localeCompare(b));

Expand All @@ -39,7 +39,7 @@ describe('Package', () => {
'fixtures/second/nested/file.md'
];

const actual = pkg.sync(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);
const actual = fg.sync(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);

actual.sort((a, b) => a.localeCompare(b));

Expand All @@ -51,7 +51,7 @@ describe('Package', () => {
it('should throw an error when input values can not pass validation', async () => {
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await pkg(null as any);
await fg(null as any);
throw new Error('An unexpected error was found.');
} catch (error) {
assert.strictEqual((error as Error).toString(), 'TypeError: Patterns must be a string or an array of strings');
Expand All @@ -69,7 +69,7 @@ describe('Package', () => {
'fixtures/second/nested/file.md'
];

const actual = await pkg(['fixtures/**/*.md']);
const actual = await fg(['fixtures/**/*.md']);

actual.sort((a, b) => a.localeCompare(b));

Expand All @@ -86,7 +86,7 @@ describe('Package', () => {
'fixtures/second/nested/file.md'
];

const actual = await pkg(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);
const actual = await fg(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);

actual.sort((a, b) => a.localeCompare(b));

Expand All @@ -97,7 +97,7 @@ describe('Package', () => {
describe('.stream', () => {
it('should throw an error when input values can not pass validation', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assert.throws(() => pkg.stream(null as any), /TypeError: Patterns must be a string or an array of strings/);
assert.throws(() => fg.stream(null as any), /TypeError: Patterns must be a string or an array of strings/);
});

it('should returns entries', (done) => {
Expand All @@ -113,7 +113,7 @@ describe('Package', () => {

const actual: string[] = [];

const stream = pkg.stream(['fixtures/**/*.md']);
const stream = fg.stream(['fixtures/**/*.md']);

stream.on('data', (entry: string) => actual.push(entry));
stream.once('error', (error: ErrnoException) => assert.fail(error));
Expand All @@ -137,7 +137,7 @@ describe('Package', () => {

const actual: string[] = [];

const stream = pkg.stream(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);
const stream = fg.stream(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);

stream.on('data', (entry: string) => actual.push(entry));
stream.once('error', (error: ErrnoException) => assert.fail(error));
Expand All @@ -153,15 +153,15 @@ describe('Package', () => {
describe('.generateTasks', () => {
it('should throw an error when input values can not pass validation', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assert.throws(() => pkg.generateTasks(null as any), /TypeError: Patterns must be a string or an array of strings/);
assert.throws(() => fg.generateTasks(null as any), /TypeError: Patterns must be a string or an array of strings/);
});

it('should return tasks', () => {
const expected = [
tests.task.builder().base('.').positive('*').build()
];

const actual = pkg.generateTasks(['*']);
const actual = fg.generateTasks(['*']);

assert.deepStrictEqual(actual, expected);
});
Expand All @@ -171,27 +171,27 @@ describe('Package', () => {
tests.task.builder().base('.').positive('*').negative('*.txt').negative('*.md').build()
];

const actual = pkg.generateTasks(['*', '!*.txt'], { ignore: ['*.md'] });
const actual = fg.generateTasks(['*', '!*.txt'], { ignore: ['*.md'] });

assert.deepStrictEqual(actual, expected);
});
});

describe('.isDynamicPattern', () => {
it('should return true for dynamic pattern', () => {
assert.ok(pkg.isDynamicPattern('*'));
assert.ok(fg.isDynamicPattern('*'));
});

it('should return false for static pattern', () => {
assert.ok(!pkg.isDynamicPattern('abc'));
assert.ok(!fg.isDynamicPattern('abc'));
});
});

describe('.escapePath', () => {
it('should return escaped path', () => {
const expected = 'C:/Program Files \\(x86\\)';

const actual = pkg.escapePath('C:/Program Files (x86)');
const actual = fg.escapePath('C:/Program Files (x86)');

assert.strictEqual(actual, expected);
});
Expand Down
12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ type EntryObjectPredicate = EntryObjectModePredicate | EntryStatsPredicate;

function FastGlob(source: PatternInternal | PatternInternal[], options: OptionsInternal & EntryObjectPredicate): Promise<EntryInternal[]>;
function FastGlob(source: PatternInternal | PatternInternal[], options?: OptionsInternal): Promise<string[]>;
function FastGlob(source: PatternInternal | PatternInternal[], options?: OptionsInternal): Promise<EntryItem[]> {
try {
assertPatternsInput(source);
} catch (error) {
return Promise.reject(error);
}
async function FastGlob(source: PatternInternal | PatternInternal[], options?: OptionsInternal): Promise<EntryItem[]> {
assertPatternsInput(source);

const works = getWorks(source, ProviderAsync, options);

return Promise.all(works).then(utils.array.flatten);
const result = await Promise.all(works);

return utils.array.flatten(result);
}

// https://github.com/typescript-eslint/typescript-eslint/issues/60
Expand Down
2 changes: 1 addition & 1 deletion src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path';

import { Pattern } from '../types';

const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([*?|(){}[\]]|^!|[@+!](?=\())/g;
const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;

/**
* Designed to work only with simple paths: `dir\\file`.
Expand Down
6 changes: 3 additions & 3 deletions src/utils/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const ESCAPE_SYMBOL = '\\';

const COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/;
const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[.*]/;
const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^@!*?+])\(.*\|.*\)/;
const GLOB_EXTENSION_SYMBOLS_RE = /[@!*?+]\(.*\)/;
const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\(.*\|.*\)/;
const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\(.*\)/;
const BRACE_EXPANSIONS_SYMBOLS_RE = /{.*(?:,|\.\.).*}/;

type PatternTypeOptions = {
Expand Down Expand Up @@ -125,7 +125,7 @@ export function convertPatternsToRe(patterns: Pattern[], options: MicromatchOpti
}

export function matchAny(entry: string, patternsRe: PatternRe[]): boolean {
const filepath = entry.replace(/^\.[\\/]/, '');
const filepath = entry.replace(/^\.[/\\]/, '');

return patternsRe.some((patternRe) => patternRe.test(filepath));
}

0 comments on commit ce1bff9

Please sign in to comment.