mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Support tilde paths ("~" prefix) in readConfig/Sync APIs (for "file" parameter and "extends" keys).
This commit is contained in:
parent
5505deb1c9
commit
ffc4d56918
6 changed files with 132 additions and 31 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const test = require("ava").default;
|
||||
const helpers = require("../helpers");
|
||||
|
||||
|
|
@ -1303,3 +1305,33 @@ test("htmlElementRanges", (t) => {
|
|||
const actual = helpers.htmlElementRanges(params, lineMetadata);
|
||||
t.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test("expandTildePath", (t) => {
|
||||
t.plan(16);
|
||||
const homedir = os.homedir();
|
||||
t.is(helpers.expandTildePath("", os), "");
|
||||
t.is(helpers.expandTildePath("", null), "");
|
||||
t.is(
|
||||
path.resolve(helpers.expandTildePath("~", os)),
|
||||
homedir
|
||||
);
|
||||
t.is(helpers.expandTildePath("~", null), "~");
|
||||
t.is(helpers.expandTildePath("file", os), "file");
|
||||
t.is(helpers.expandTildePath("file", null), "file");
|
||||
t.is(helpers.expandTildePath("/file", os), "/file");
|
||||
t.is(helpers.expandTildePath("/file", null), "/file");
|
||||
t.is(
|
||||
path.resolve(helpers.expandTildePath("~/file", os)),
|
||||
path.join(homedir, "/file")
|
||||
);
|
||||
t.is(helpers.expandTildePath("~/file", null), "~/file");
|
||||
t.is(helpers.expandTildePath("dir/file", os), "dir/file");
|
||||
t.is(helpers.expandTildePath("dir/file", null), "dir/file");
|
||||
t.is(helpers.expandTildePath("/dir/file", os), "/dir/file");
|
||||
t.is(helpers.expandTildePath("/dir/file", null), "/dir/file");
|
||||
t.is(
|
||||
path.resolve(helpers.expandTildePath("~/dir/file", os)),
|
||||
path.join(homedir, "/dir/file")
|
||||
);
|
||||
t.is(helpers.expandTildePath("~/dir/file", null), "~/dir/file");
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue