Use relative paths with CLI (#2969)

* always get relative paths

* Add test

* update snapshots
master
Ahmed El Gabri 2017-10-04 09:56:01 +02:00 committed by Lucas Azzola
parent a7223d8262
commit 2fed6c873b
11 changed files with 45 additions and 12 deletions

View File

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

View File

@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`support relative paths (stderr) 1`] = `""`;
exports[`support relative paths (stdout) 1`] = `
"shouldNotBeIgnored.js
level1-glob/level2-glob/level3-glob/shouldNotBeIgnored.scss
level1-glob/shouldNotBeIgnored.js
"
`;
exports[`support relative paths (write) 1`] = `Array []`;

View File

@ -40,10 +40,10 @@ exports[`multiple patterns by with ignore pattern, ignores node_modules by defau
exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js (stderr) 1`] = `""`;
exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js (stdout) 1`] = `
"./other-directory/file.js
./other-directory/nested-directory/nested-directory-file.js
./other-regular-modules.js
./regular-module.js
"other-directory/file.js
other-directory/nested-directory/nested-directory-file.js
other-regular-modules.js
regular-module.js
"
`;

View File

@ -45,8 +45,8 @@ exports[`ignores node_modules by default for file list (write) 1`] = `Array []`;
exports[`ignores node_modules by with ./**/*.js (stderr) 1`] = `""`;
exports[`ignores node_modules by with ./**/*.js (stdout) 1`] = `
"./not_node_modules/file.js
./regular-module.js
"not_node_modules/file.js
regular-module.js
"
`;

View File

@ -0,0 +1,16 @@
"use strict";
const runPrettier = require("../runPrettier");
describe("support relative paths", () => {
runPrettier("cli/ignore-relative-path", [
"./shouldNotBeIgnored.js",
"./level1/level2/level3/shouldNotBeFormat.js",
"level1-glob/level2-glob/level3-glob/shouldNotBeFormat.js",
"./level1-glob/level2-glob/level3-glob/shouldNotBeIgnored.scss",
"level1-glob/shouldNotBeIgnored.js",
"-l"
]).test({
status: 1
});
});

View File

@ -0,0 +1,2 @@
level1/level2/
level1-glob/**/level3-glob/*.js

View File

@ -0,0 +1 @@
var x = 'this should not be formatterd';

View File

@ -0,0 +1,2 @@
var x = 'this should be formatterd';

View File

@ -0,0 +1 @@
var x = 'this should not be formatterd';

View File

@ -0,0 +1,2 @@
var x = 'this should be formatterd';