Skip to content

Commit 9a654d2

Browse files
committedMar 12, 2020
Merge branch 'noelmace-fix-absolute-path'.
2 parents 8a3a64e + 9478e8e commit 9a654d2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎markdownlint.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function prepareFileList(files, fileExtensions, previousResults) {
110110
return flatten(files).map(function (file) {
111111
return {
112112
original: file,
113+
relative: path.relative(process.cwd(), file),
113114
absolute: path.resolve(file)
114115
};
115116
});
@@ -231,7 +232,7 @@ let ignoreFilter = () => true;
231232
if (existsSync(ignorePath)) {
232233
const ignoreText = fs.readFileSync(ignorePath, fsOptions);
233234
const ignoreInstance = ignore().add(ignoreText);
234-
ignoreFilter = fileInfo => !ignoreInstance.ignores(fileInfo.original);
235+
ignoreFilter = fileInfo => !ignoreInstance.ignores(fileInfo.relative);
235236
}
236237

237238
const files = prepareFileList(program.args, ['md', 'markdown'])

‎test/test.js

+18
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,24 @@ test('.markdownlintignore is applied correctly', async t => {
646646
}
647647
});
648648

649+
test('.markdownlintignore works with semi-absolute paths', async t => {
650+
try {
651+
await execa(
652+
path.resolve('..', 'markdownlint.js'), ['./incorrect.md'], {
653+
cwd: path.join(__dirname, 'markdownlintignore'),
654+
stripFinalNewline: false
655+
});
656+
t.fail();
657+
} catch (error) {
658+
const expected = [
659+
'./incorrect.md:1:8 MD047/single-trailing-newline Files should end with a single newline character',
660+
''
661+
].join('\n');
662+
t.deepEqual(error.stdout, '');
663+
t.deepEqual(error.stderr, expected);
664+
}
665+
});
666+
649667
test('--ignore-path works with .markdownlintignore', async t => {
650668
try {
651669
await execa(

0 commit comments

Comments
 (0)
Please sign in to comment.