Skip to content

Commit 6f7ae44

Browse files
committed
Upgrade globby
Resolve #551
1 parent 47af93e commit 6f7ae44

File tree

5 files changed

+47
-31
lines changed

5 files changed

+47
-31
lines changed

index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import pMap from 'p-map';
99
import {cosmiconfig, defaultLoaders} from 'cosmiconfig';
1010
import defineLazyProperty from 'define-lazy-prop';
1111
import pFilter from 'p-filter';
12+
import slash from 'slash';
1213
import {CONFIG_FILES, MODULE_NAME, DEFAULT_IGNORES} from './lib/constants.js';
1314
import {
1415
normalizeOptions,
@@ -94,9 +95,9 @@ const runEslint = async (paths, options, processorOptions) => {
9495

9596
const globFiles = async (patterns, {ignores, extensions, cwd}) => (
9697
await globby(
97-
patterns.length === 0 ? [`**/*.{${extensions.join(',')}}`] : arrify(patterns),
98-
{ignore: ignores, gitignore: true, cwd},
99-
)).filter(file => extensions.includes(path.extname(file).slice(1))).map(file => path.resolve(cwd, file));
98+
patterns.length === 0 ? [`**/*.{${extensions.join(',')}}`] : arrify(patterns).map(pattern => slash(pattern)),
99+
{ignore: ignores, gitignore: true, absolute: true, cwd},
100+
)).filter(file => extensions.includes(path.extname(file).slice(1)));
100101

101102
const getConfig = async options => {
102103
const {options: foundOptions, prettierOptions} = mergeWithFileConfig(normalizeOptions(options));
@@ -149,8 +150,8 @@ const lintFiles = async (patterns, inputOptions = {}) => {
149150
const configFiles = (await Promise.all(
150151
(await globby(
151152
CONFIG_FILES.map(configFile => `**/${configFile}`),
152-
{ignore: DEFAULT_IGNORES, gitignore: true, cwd: inputOptions.cwd},
153-
)).map(async configFile => configExplorer.load(path.resolve(inputOptions.cwd, configFile))),
153+
{ignore: DEFAULT_IGNORES, gitignore: true, absolute: true, cwd: inputOptions.cwd},
154+
)).map(configFile => configExplorer.load(configFile)),
154155
)).filter(Boolean);
155156

156157
const paths = configFiles.length > 0

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"find-up": "^5.0.0",
7979
"fs-extra": "^10.0.0",
8080
"get-stdin": "^9.0.0",
81-
"globby": "^9.2.0",
81+
"globby": "^11.0.4",
8282
"imurmurhash": "^0.1.4",
8383
"is-path-inside": "^4.0.0",
8484
"json-stable-stringify-without-jsonify": "^1.0.1",
@@ -117,7 +117,8 @@
117117
},
118118
"eslintIgnore": [
119119
"test/fixtures",
120-
"coverage"
120+
"coverage",
121+
"temp"
121122
],
122123
"ava": {
123124
"timeout": "1m"
@@ -127,5 +128,8 @@
127128
"text",
128129
"lcov"
129130
]
131+
},
132+
"xo": {
133+
"semicolon": true
130134
}
131135
}

temp/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*/

test/cli.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from 'node:path';
33
import test from 'ava';
44
import execa from 'execa';
55
import slash from 'slash';
6-
import tempWrite from 'temp-write';
76
import createEsmUtils from 'esm-utils';
87

98
const {__dirname} = createEsmUtils(import.meta);
@@ -12,8 +11,10 @@ process.chdir(__dirname);
1211
const main = (arguments_, options) => execa(path.join(__dirname, '../cli.js'), arguments_, options);
1312

1413
test('fix option', async t => {
15-
const filepath = await tempWrite('console.log()\n', 'x.js');
16-
await main(['--fix', filepath]);
14+
const cwd = await fs.promises.mkdtemp(path.join(__dirname, '../temp/'));
15+
const filepath = path.join(cwd, 'x.js');
16+
await fs.promises.writeFile(filepath, 'console.log()\n');
17+
await main(['--fix', filepath], {cwd});
1718
t.is(fs.readFileSync(filepath, 'utf8').trim(), 'console.log();');
1819
});
1920

@@ -33,10 +34,12 @@ test('stdin-filename option with stdin', async t => {
3334
});
3435

3536
test('reporter option', async t => {
36-
const filepath = await tempWrite('console.log()\n', 'x.js');
37+
const cwd = await fs.promises.mkdtemp(path.join(__dirname, '../temp/'));
38+
const filepath = path.join(cwd, 'x.js');
39+
await fs.promises.writeFile(filepath, 'console.log()\n');
3740

3841
const error = await t.throwsAsync(() =>
39-
main(['--reporter=compact', filepath]),
42+
main(['--reporter=compact', filepath], {cwd}),
4043
);
4144
t.true(error.stdout.includes('Error - '));
4245
});
@@ -98,15 +101,19 @@ test('supports being extended with a shareable config', async t => {
98101
});
99102

100103
test('quiet option', async t => {
101-
const filepath = await tempWrite('// TODO: quiet\nconsole.log()\n', 'x.js');
102-
const error = await t.throwsAsync(main(['--quiet', '--reporter=json', filepath]));
104+
const cwd = await fs.promises.mkdtemp(path.join(__dirname, '../temp/'));
105+
const filepath = path.join(cwd, 'x.js');
106+
await fs.promises.writeFile(filepath, '// TODO: quiet\nconsole.log()\n');
107+
const error = await t.throwsAsync(main(['--quiet', '--reporter=json', filepath], {cwd}));
103108
const [report] = JSON.parse(error.stdout);
104109
t.is(report.warningCount, 0);
105110
});
106111

107112
test('invalid node-engine option', async t => {
108-
const filepath = await tempWrite('console.log()\n', 'x.js');
109-
const error = await t.throwsAsync(main(['--node-version', 'v', filepath]));
113+
const cwd = await fs.promises.mkdtemp(path.join(__dirname, '../temp/'));
114+
const filepath = path.join(cwd, 'x.js');
115+
await fs.promises.writeFile(filepath, 'console.log()\n');
116+
const error = await t.throwsAsync(main(['--node-version', 'v', filepath], {cwd}));
110117
t.is(error.exitCode, 1);
111118
});
112119

test/lint-files.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@ const hasRule = (results, filePath, ruleId) => {
1313

1414
test('only accepts allowed extensions', async t => {
1515
// Markdown files will always produce linter errors and will not be going away
16-
const mdGlob = path.join(__dirname, '..', '*.md');
16+
const cwd = path.join(__dirname, '..');
17+
const mdGlob = '*.md';
1718

1819
// No files should be linted = no errors
19-
const noOptionsResults = await xo.lintFiles(mdGlob, {});
20+
const noOptionsResults = await xo.lintFiles(mdGlob, {cwd});
2021
t.is(noOptionsResults.errorCount, 0);
2122

2223
// Markdown files linted (with no plugin for it) = errors
23-
const moreExtensionsResults = await xo.lintFiles(mdGlob, {extensions: ['md']});
24+
const moreExtensionsResults = await xo.lintFiles(mdGlob, {extensions: ['md'], cwd});
2425
t.true(moreExtensionsResults.errorCount > 0);
2526
});
2627

2728
test('ignores dirs for empty extensions', async t => {
2829
{
29-
const glob = path.join(__dirname, 'fixtures/nodir/*');
30-
const results = await xo.lintFiles(glob, {extensions: ['', 'js']});
30+
const cwd = path.join(__dirname, 'fixtures/nodir');
31+
const glob = '*';
32+
const results = await xo.lintFiles(glob, {extensions: ['', 'js'], cwd});
3133
const {results: [fileResult]} = results;
3234

3335
// Only `fixtures/nodir/noextension` should be linted
@@ -38,8 +40,9 @@ test('ignores dirs for empty extensions', async t => {
3840
}
3941

4042
{
41-
const glob = path.join(__dirname, 'fixtures/nodir/nested/*');
42-
const results = await xo.lintFiles(glob);
43+
const cwd = path.join(__dirname, 'fixtures/nodir');
44+
const glob = 'nested/*';
45+
const results = await xo.lintFiles(glob, {cwd});
4346
const {results: [fileResult]} = results;
4447

4548
// Ensure `nodir/nested` **would** report if globbed
@@ -59,7 +62,7 @@ test.serial('cwd option', async t => {
5962

6063
test('do not lint gitignored files', async t => {
6164
const cwd = path.join(__dirname, 'fixtures/gitignore');
62-
const glob = path.posix.join(cwd, '**/*');
65+
const glob = '**/*';
6366
const ignored = path.resolve('fixtures/gitignore/test/foo.js');
6467
const {results} = await xo.lintFiles(glob, {cwd});
6568

@@ -68,7 +71,7 @@ test('do not lint gitignored files', async t => {
6871

6972
test('do not lint gitignored files in file with negative gitignores', async t => {
7073
const cwd = path.join(__dirname, 'fixtures/negative-gitignore');
71-
const glob = path.posix.join(cwd, '*');
74+
const glob = '*';
7275
const ignored = path.resolve('fixtures/negative-gitignore/bar.js');
7376
const {results} = await xo.lintFiles(glob, {cwd});
7477

@@ -77,7 +80,7 @@ test('do not lint gitignored files in file with negative gitignores', async t =>
7780

7881
test('lint negatively gitignored files', async t => {
7982
const cwd = path.join(__dirname, 'fixtures/negative-gitignore');
80-
const glob = path.posix.join(cwd, '*');
83+
const glob = '*';
8184
const negative = path.resolve('fixtures/negative-gitignore/foo.js');
8285
const {results} = await xo.lintFiles(glob, {cwd});
8386

@@ -86,7 +89,7 @@ test('lint negatively gitignored files', async t => {
8689

8790
test('do not lint inapplicable negatively gitignored files', async t => {
8891
const cwd = path.join(__dirname, 'fixtures/negative-gitignore');
89-
const glob = path.posix.join(cwd, 'bar.js');
92+
const glob = 'bar.js';
9093
const negative = path.resolve('fixtures/negative-gitignore/foo.js');
9194
const {results} = await xo.lintFiles(glob, {cwd});
9295

@@ -125,7 +128,7 @@ test('enable rules based on nodeVersion', async t => {
125128

126129
test('do not lint eslintignored files', async t => {
127130
const cwd = path.join(__dirname, 'fixtures/eslintignore');
128-
const glob = path.posix.join(cwd, '*');
131+
const glob = '*';
129132
const positive = path.resolve('fixtures/eslintignore/foo.js');
130133
const negative = path.resolve('fixtures/eslintignore/bar.js');
131134
const {results} = await xo.lintFiles(glob, {cwd});
@@ -216,7 +219,7 @@ test('typescript no semicolon option', async t => {
216219

217220
test('webpack import resolver is used if webpack.config.js is found', async t => {
218221
const cwd = 'fixtures/webpack/with-config/';
219-
const {results} = await xo.lintFiles(path.resolve(cwd, 'file1.js'), {
222+
const {results} = await xo.lintFiles('file1.js', {
220223
cwd,
221224
rules: {
222225
'import/no-unresolved': 2,
@@ -233,7 +236,7 @@ test('webpack import resolver is used if webpack.config.js is found', async t =>
233236
test('webpack import resolver config can be passed through webpack option', async t => {
234237
const cwd = 'fixtures/webpack/no-config/';
235238

236-
const {results} = await xo.lintFiles(path.resolve(cwd, 'file1.js'), {
239+
const {results} = await xo.lintFiles('file1.js', {
237240
cwd,
238241
webpack: {
239242
config: {
@@ -256,7 +259,7 @@ test('webpack import resolver config can be passed through webpack option', asyn
256259
test('webpack import resolver is used if {webpack: true}', async t => {
257260
const cwd = 'fixtures/webpack/no-config/';
258261

259-
const {results} = await xo.lintFiles(path.resolve(cwd, 'file3.js'), {
262+
const {results} = await xo.lintFiles('file3.js', {
260263
cwd,
261264
webpack: true,
262265
rules: {

0 commit comments

Comments
 (0)