Skip to content

Commit

Permalink
Improve external file detection on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Jun 8, 2024
1 parent 5f7ffaf commit 185e664
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ jobs:
test:

name: test (Node.js ${{ matrix.node-version }})
name: Test (Node.js ${{ matrix.node-version }} on ${{ matrix.runs-on }})

runs-on: ubuntu-latest
runs-on: ${{ matrix.runs-on }}

strategy:
matrix:
runs-on: [ubuntu-latest]
node-version: ['18', '20', '22']
include:
- runs-on: windows-latest
node-version: lts/*
- runs-on: macOS-latest
node-version: lts/*

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* @returns {string | Promise<string>}
*/

const { normalize, relative } = require('path');
const { Transform } = require('stream');
const { normalize, relative, toNamespacedPath } = require('path');
const { Transform } = require('stream');

const ESLINT_PKG = Symbol('ESLint package name');
const GULP_DEST_KEY = Symbol('require("vinyl-fs").dest');
Expand Down Expand Up @@ -122,7 +122,7 @@ exports.createIgnoreResult =
{
const { ltr } = require('semver');
let message;
const relativePath = relative(baseDir, filePath);
const relativePath = relative(toNamespacedPath(baseDir), toNamespacedPath(filePath));
if (isEslintrcESLintConstructor(eslintConstructor))
{
if (isHiddenRegExp.test(relativePath))
Expand Down
65 changes: 65 additions & 0 deletions test/linting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ async function testIgnoreByPath(options, dataList)
}
}

async function testIgnoreExternal(eslintPkg, baseDir, filePath)
{
const file = createVinylFile(filePath, '');
const stream =
gulpESLintNew
(
{
[ESLINT_PKG]: eslintPkg,
configType: 'flat',
cwd: baseDir,
overrideConfigFile: true,
warnIgnored: true,
},
)
.end(file);
await finishStream(stream);
assert.equal(file.eslint.filePath, filePath);
assert(Array.isArray(file.eslint.messages));
assert.equal(file.eslint.messages.length, 1);
assert.equal(file.eslint.messages[0].message, 'File ignored because outside of base path.');
assert.equal(file.eslint.errorCount, 0);
assert.equal(file.eslint.warningCount, 1);
assert.equal(file.eslint.fixableErrorCount, 0);
assert.equal(file.eslint.fixableWarningCount, 0);
assert.equal(file.eslint.fatalErrorCount, 0);
}

describe
(
'gulp-eslint-new plugin',
Expand Down Expand Up @@ -672,6 +699,44 @@ describe
},
);

describe
(
'should ignore a file on a different drive',
() =>
{
if (process.platform !== 'win32')
return;

it
(
'local base path, local file',
() => testIgnoreExternal(eslintPkg, 'C:\\Project', 'D:\\Project\\file.js'),
);

it
(
'local base path, network file',
() =>
testIgnoreExternal(eslintPkg, 'C:\\Project', '\\\\NAS\\Share\\file.js'),
);

it
(
'network base path, local file',
() =>
testIgnoreExternal(eslintPkg, '\\\\NAS\\Share', 'C:\\Project\\file.js'),
);

it
(
'network base path, network file',
() =>
testIgnoreExternal
(eslintPkg, '\\\\server1\\dir', '\\\\server2\\dir\\file.js'),
);
},
);

it
(
'should unignore a file',
Expand Down

0 comments on commit 185e664

Please sign in to comment.