fix(prettierignore): support absolute filename (#2783)

master
长天之云 2017-09-11 00:21:56 +08:00 committed by Simon Lydell
parent 8b02f702d5
commit df5482008e
7 changed files with 35 additions and 1 deletions

View File

@ -292,7 +292,14 @@ function eachFilename(argv, patterns, callback) {
}
try {
const filePaths = globby.sync(patterns, { dot: true });
const filePaths = globby
.sync(patterns, { dot: true })
.map(
filePath =>
path.isAbsolute(filePath)
? path.relative(process.cwd(), filePath)
: filePath
);
if (filePaths.length === 0) {
console.error(`No matching files. Patterns tried: ${patterns.join(" ")}`);
process.exitCode = 2;

View File

@ -0,0 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`support absolute filename 1`] = `
"regular-module.js
"
`;

View File

@ -0,0 +1,16 @@
"use strict";
const path = require("path");
const runPrettier = require("../runPrettier");
test("support absolute filename", () => {
const result = runPrettier("cli/ignore-absolute-path", [
path.resolve(__dirname, "../cli/ignore-absolute-path/ignored/module.js"),
path.resolve(__dirname, "../cli/ignore-absolute-path/depth1/ignored/*.js"),
path.resolve(__dirname, "../cli/ignore-absolute-path/regular-module.js"),
"-l"
]);
expect(result.stdout).toMatchSnapshot();
expect(result.status).toEqual(1);
});

View File

@ -0,0 +1,2 @@
/ignored/
depth1/ignored/

View File

@ -0,0 +1 @@
'use strict';

View File

@ -0,0 +1 @@
'use strict';

View File

@ -0,0 +1 @@
'use strict';