Use relative paths with CLI (#2969)
* always get relative paths * Add test * update snapshotsmaster
parent
a7223d8262
commit
2fed6c873b
|
@ -251,12 +251,8 @@ function eachFilename(argv, patterns, callback) {
|
||||||
try {
|
try {
|
||||||
const filePaths = globby
|
const filePaths = globby
|
||||||
.sync(patterns, { dot: true })
|
.sync(patterns, { dot: true })
|
||||||
.map(
|
.map(filePath => path.relative(process.cwd(), filePath));
|
||||||
filePath =>
|
|
||||||
path.isAbsolute(filePath)
|
|
||||||
? path.relative(process.cwd(), filePath)
|
|
||||||
: filePath
|
|
||||||
);
|
|
||||||
if (filePaths.length === 0) {
|
if (filePaths.length === 0) {
|
||||||
console.error(`No matching files. Patterns tried: ${patterns.join(" ")}`);
|
console.error(`No matching files. Patterns tried: ${patterns.join(" ")}`);
|
||||||
process.exitCode = 2;
|
process.exitCode = 2;
|
||||||
|
|
|
@ -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 []`;
|
|
@ -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 (stderr) 1`] = `""`;
|
||||||
|
|
||||||
exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js (stdout) 1`] = `
|
exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js (stdout) 1`] = `
|
||||||
"./other-directory/file.js
|
"other-directory/file.js
|
||||||
./other-directory/nested-directory/nested-directory-file.js
|
other-directory/nested-directory/nested-directory-file.js
|
||||||
./other-regular-modules.js
|
other-regular-modules.js
|
||||||
./regular-module.js
|
regular-module.js
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -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 (stderr) 1`] = `""`;
|
||||||
|
|
||||||
exports[`ignores node_modules by with ./**/*.js (stdout) 1`] = `
|
exports[`ignores node_modules by with ./**/*.js (stdout) 1`] = `
|
||||||
"./not_node_modules/file.js
|
"not_node_modules/file.js
|
||||||
./regular-module.js
|
regular-module.js
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,2 @@
|
||||||
|
level1/level2/
|
||||||
|
level1-glob/**/level3-glob/*.js
|
|
@ -0,0 +1 @@
|
||||||
|
var x = 'this should not be formatterd';
|
|
@ -0,0 +1 @@
|
||||||
|
body { color: green }
|
|
@ -0,0 +1,2 @@
|
||||||
|
var x = 'this should be formatterd';
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
var x = 'this should not be formatterd';
|
|
@ -0,0 +1,2 @@
|
||||||
|
var x = 'this should be formatterd';
|
||||||
|
|
Loading…
Reference in New Issue