Skip to content

Commit

Permalink
Fix compatibility problem with Windows (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
skarab42 authored Aug 31, 2022
1 parent bbf323b commit a608bf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import stringify from 'json-stable-stringify-without-jsonify';
import {Legacy} from '@eslint/eslintrc';
import createEsmUtils from 'esm-utils';
import MurmurHash3 from 'imurmurhash';
import slash from 'slash';
import {
DEFAULT_IGNORES,
DEFAULT_EXTENSION,
Expand Down Expand Up @@ -683,19 +684,19 @@ const tsConfigResolvePaths = (tsConfig, tsConfigPath) => {

if (Array.isArray(tsConfig.files)) {
tsConfig.files = tsConfig.files.map(
filePath => path.resolve(tsConfigDirectory, filePath),
filePath => slash(path.resolve(tsConfigDirectory, filePath)),
);
}

if (Array.isArray(tsConfig.include)) {
tsConfig.include = tsConfig.include.map(
globPath => path.resolve(tsConfigDirectory, globPath),
globPath => slash(path.resolve(tsConfigDirectory, globPath)),
);
}

if (Array.isArray(tsConfig.exclude)) {
tsConfig.exclude = tsConfig.exclude.map(
globPath => path.resolve(tsConfigDirectory, globPath),
globPath => slash(path.resolve(tsConfigDirectory, globPath)),
);
}

Expand Down
8 changes: 4 additions & 4 deletions test/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ test('mergeWithFileConfig: correctly resolves relative tsconfigs excluded file',
const excludedFilePath = path.resolve(cwd, 'excluded-file.ts');
const excludeTsConfigPath = new RegExp(`${slash(cwd)}/node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$`, 'u');
const {options} = await manager.mergeWithFileConfig({cwd, filePath: excludedFilePath});
t.regex(options.tsConfigPath, excludeTsConfigPath);
t.regex(slash(options.tsConfigPath), excludeTsConfigPath);
});

test('mergeWithFileConfig: correctly resolves relative tsconfigs included file', async t => {
Expand All @@ -619,15 +619,15 @@ test('mergeWithFileConfig: uses generated tsconfig if specified parserOptions.pr
const filePath = path.resolve(cwd, 'excluded-file.ts');
const expectedTsConfigPath = new RegExp(`${slash(cwd)}/node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$`, 'u');
const {options} = await manager.mergeWithFileConfig({cwd, filePath});
t.regex(options.tsConfigPath, expectedTsConfigPath);
t.regex(slash(options.tsConfigPath), expectedTsConfigPath);
});

test('mergeWithFileConfig: uses generated tsconfig if specified parserOptions.project misses file', async t => {
const cwd = path.resolve('fixtures', 'typescript', 'parseroptions-project');
const filePath = path.resolve(cwd, 'missed-by-options-file.ts');
const expectedTsConfigPath = new RegExp(`${slash(cwd)}/node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$`, 'u');
const {options} = await manager.mergeWithFileConfig({cwd, filePath});
t.regex(options.tsConfigPath, expectedTsConfigPath);
t.regex(slash(options.tsConfigPath), expectedTsConfigPath);
});

test('mergeWithFileConfig: auto generated ts config extends found ts config if file is not covered', async t => {
Expand All @@ -647,7 +647,7 @@ test('mergeWithFileConfig: used found ts config if file is covered', async t =>
const filePath = path.resolve(cwd, 'foo.ts');
const expectedConfigPath = path.resolve(cwd, 'tsconfig.json');
const {options} = await manager.mergeWithFileConfig({cwd, filePath});
t.is(slash(options.tsConfigPath), expectedConfigPath);
t.is(options.tsConfigPath, expectedConfigPath);
});

test('mergeWithFileConfig: auto generated ts config extends found ts config if file is explicitly excluded', async t => {
Expand Down

0 comments on commit a608bf1

Please sign in to comment.