AssertionError [ERR_ASSERTION]: 'newBasePath' should be an absolute path
See original GitHub issueWindows Node v12.13.0 npm v6.13.6 eslint 6.8.0 Parser: @typescript-eslint/parser Bash terminal
eslint config:
"use strict";
const allExtensions = [".ts", ".tsx", ".d.ts", ".js", ".jsx"];
module.exports = {
env: {
"browser": true,
"es6": true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
sourceType: "module",
},
plugins: [
"import",
"@typescript-eslint",
"@typescript-eslint/tslint",
],
settings: {
"import/extensions": allExtensions,
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
"node": {
"extensions": allExtensions,
},
},
},
rules: {
"import/no-deprecated": "warn",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/tslint/config": [
"warn",
{
"rules": {
"deprecation": true,
},
},
],
},
};
I’m currently using a globally installed npm package (call it foo cli) that wraps eslint. I have a workspace in c:\src\myproject. foo cli has an internal reference to eslint 6.8.0. When I run ap lint
from c:\src\myproject, foo cli invokes eslint with some default parameters, and I get the error from the bug title. Here’s the raw output:
/c/myproject (master)
$ ap lint
Running C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\.bin\eslint.cmd **/*.ts --ignore-path C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintignore -c C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintrc.json --resolve-plugins-relative-to C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint
AssertionError [ERR_ASSERTION]: 'newBasePath' should be an absolute path.
at IgnorePattern.getPatternsRelativeTo (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:210:9)
at C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:150:42
at Array.map (<anonymous>)
at Function.createIgnore (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:150:31)
at createConfig (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\config-array.js:282:40)
at ConfigArray.extractConfig (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\config-array.js:452:33)
at FileEnumerator._isIgnoredFile (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:479:24)
at FileEnumerator._iterateFilesRecursive (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:407:38)
at _iterateFilesRecursive.next (<anonymous>)
at FileEnumerator.iterateFiles (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:251:49)
I believe the problem exists in ignore-pattern.js and was introduced in this pull request: https://github.com/eslint/eslint/pull/12274/files
If I add some debug logging to IgnorePattern.getCommonAncestorPath:
function getCommonAncestorPath(sourcePaths) {
let result = sourcePaths[0];
for (let i = 1; i < sourcePaths.length; ++i) {
const a = result;
const b = sourcePaths[i];
// Set the shorter one (it's the common ancestor if one includes the other).
result = a.length < b.length ? a : b;
// Set the common ancestor.
for (let j = 0, lastSepPos = 0; j < a.length && j < b.length; ++j) {
if (a[j] !== b[j]) {
result = a.slice(0, lastSepPos);
break;
}
if (a[j] === path.sep) {
lastSepPos = j;
}
}
}
console.log("**: ", { result: result, sep: path.sep, sourcePaths: sourcePaths }); // new line here
return result || path.sep;
}
I see the following output:
/c/myproject (master)
$ ap lint
Running C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\.bin\eslint.cmd **/*.ts --ignore-path C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintignore -c C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintrc.json --resolve-plugins-relative-to C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint
**: {
result: 'C:\\src\\myproject',
sep: '\\',
sourcePaths: [ 'C:\\src\\myproject' ]
}
**: {
result: 'C:\\src\\myproject',
sep: '\\',
sourcePaths: [ 'C:\\src\\myproject' ]
}
**: {
result: 'C:',
sep: '\\',
sourcePaths: [
'C:\\src\\myproject',
'C:\\Users\\drkestel\\AppData\\Roaming\\npm\\node_modules\\@foocli\\lint'
]
}
AssertionError [ERR_ASSERTION]: 'newBasePath' should be an absolute path.
at IgnorePattern.getPatternsRelativeTo (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:210:9)
at C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:150:42
at Array.map (<anonymous>)
at Function.createIgnore (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:150:31)
at createConfig (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\config-array.js:282:40)
at ConfigArray.extractConfig (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\config-array.js:452:33)
at FileEnumerator._isIgnoredFile (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:479:24)
at FileEnumerator._iterateFilesRecursive (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:407:38)
at _iterateFilesRecursive.next (<anonymous>)
at FileEnumerator.iterateFiles (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:251:49)
/c/myproject (master)
$
Notice the result: 'C:',
- that is not considered a valid absolute path.
Interestingly enough, I can mitigate the problem by using windows cmd.exe and setting my current prompt to c:\
(lowercase, as opposed to C:\
). Because c:\ != C:\
, it works. See the output:
c:\src\myproject>ap lint
Running C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\.bin\eslint.cmd **/*.ts --ignore-path C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintignore -c C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintrc.json --resolve-plugins-relative-to C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint
**: {
result: 'c:\\src\\myproject',
sep: '\\',
sourcePaths: [ 'c:\\src\\myproject' ]
}
**: {
result: 'c:\\src\\myproject',
sep: '\\',
sourcePaths: [ 'c:\\src\\myproject' ]
}
**: {
result: '',
sep: '\\',
sourcePaths: [
'c:\\src\\myproject',
'C:\\Users\\drkestel\\AppData\\Roaming\\npm\\node_modules\\@foocli\\lint'
]
}
**: {
result: '',
sep: '\\',
sourcePaths: [
'c:\\src\\myproject',
'C:\\Users\\drkestel\\AppData\\Roaming\\npm\\node_modules\\@foocli\\lint'
]
}
c:\src\myproject\Client\Index.ts
66:5 warning Missing return type on function @typescript-eslint/explicit-function-return-type
67:17 error 'container' is assigned a value but never used @typescript-eslint/no-unused-vars
68:15 error 'id' is assigned a value but never used @typescript-eslint/no-unused-vars
... more valid linting
I can also mitigate the problem by making the following code change to ignore-pattern.js:
function getCommonAncestorPath(sourcePaths) {
let result = sourcePaths[0];
for (let i = 1; i < sourcePaths.length; ++i) {
const a = result;
const b = sourcePaths[i];
// Set the shorter one (it's the common ancestor if one includes the other).
result = a.length < b.length ? a : b;
// Set the common ancestor.
for (let j = 0, lastSepPos = 0; j < a.length && j < b.length; ++j) {
if (a[j] !== b[j]) {
result = a.slice(0, lastSepPos);
break;
}
if (a[j] === path.sep) {
lastSepPos = j;
}
}
}
// this was the previous return statement
// return result || path.sep;
// new return statement
let resolvedResult = result || path.sep;
if (resolvedResult && resolvedResult.endsWith(":")) {
resolvedResult = resolvedResult + path.sep;
}
return resolvedResult;
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:9 (9 by maintainers)
Top GitHub Comments
Thanks for the detailed bug report. This does seem like a bug to me. Looking at how paths work in WIndows in Microsoft’s documentation, it does look like we need to fix this algorithm to not remove the separator from
C:
, since"C:"
is considered relative while"C:\\"
is considered absolute.yup already using it 😃 thank you!