mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update helpers.expandTildePath to handle receiving an os object without homedir, address minor @ts-check confusion in same file.
This commit is contained in:
parent
95466e29be
commit
5b0588f378
3 changed files with 6 additions and 5 deletions
|
|
@ -1077,7 +1077,7 @@ module.exports.getNextChildToken = getNextChildToken;
|
||||||
* @returns {string} Absolute path (or original path).
|
* @returns {string} Absolute path (or original path).
|
||||||
*/
|
*/
|
||||||
function expandTildePath(file, os) {
|
function expandTildePath(file, os) {
|
||||||
const homedir = os && os.homedir();
|
const homedir = os && os.homedir && os.homedir();
|
||||||
return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
|
return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
|
||||||
}
|
}
|
||||||
module.exports.expandTildePath = expandTildePath;
|
module.exports.expandTildePath = expandTildePath;
|
||||||
|
|
|
||||||
|
|
@ -1126,7 +1126,7 @@ module.exports.getNextChildToken = getNextChildToken;
|
||||||
* @returns {string} Absolute path (or original path).
|
* @returns {string} Absolute path (or original path).
|
||||||
*/
|
*/
|
||||||
function expandTildePath(file, os) {
|
function expandTildePath(file, os) {
|
||||||
const homedir = os && os.homedir();
|
const homedir = os && os.homedir && os.homedir();
|
||||||
return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
|
return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
|
||||||
}
|
}
|
||||||
module.exports.expandTildePath = expandTildePath;
|
module.exports.expandTildePath = expandTildePath;
|
||||||
|
|
|
||||||
|
|
@ -471,7 +471,7 @@ test("applyFix", (t) => {
|
||||||
const [ line, fixInfo, lineEnding, expected ] = testCase;
|
const [ line, fixInfo, lineEnding, expected ] = testCase;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const actual = helpers.applyFix(line, fixInfo, lineEnding);
|
const actual = helpers.applyFix(line, fixInfo, lineEnding);
|
||||||
t.is(actual, expected, "Incorrect fix applied.");
|
t.is(actual, String(expected), "Incorrect fix applied.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -949,7 +949,7 @@ test("applyFixes", (t) => {
|
||||||
const [ input, errors, expected ] = testCase;
|
const [ input, errors, expected ] = testCase;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const actual = helpers.applyFixes(input, errors);
|
const actual = helpers.applyFixes(input, errors);
|
||||||
t.is(actual, expected, "Incorrect fix applied.");
|
t.is(actual, String(expected), "Incorrect fix applied.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1277,9 +1277,10 @@ test("htmlElementRanges", (t) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("expandTildePath", (t) => {
|
test("expandTildePath", (t) => {
|
||||||
t.plan(16);
|
t.plan(17);
|
||||||
const homedir = os.homedir();
|
const homedir = os.homedir();
|
||||||
t.is(helpers.expandTildePath("", os), "");
|
t.is(helpers.expandTildePath("", os), "");
|
||||||
|
t.is(helpers.expandTildePath("", {}), "");
|
||||||
t.is(helpers.expandTildePath("", null), "");
|
t.is(helpers.expandTildePath("", null), "");
|
||||||
t.is(
|
t.is(
|
||||||
path.resolve(helpers.expandTildePath("~", os)),
|
path.resolve(helpers.expandTildePath("~", os)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue