1 parent
34b0709bf0
commit
469059dc20
8 files changed
+69
-3
No files matched your search
+29
-3
@@ -10,6 +10,7 @@ const globby = require("globby");
|
|||||||
const minimist = require("minimist");
|
const minimist = require("minimist");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const readline = require("readline");
|
const readline = require("readline");
|
||||||
|
const ignore = require("ignore");
|
||||||
|
|
||||||
const prettier = eval("require")("../index");
|
const prettier = eval("require")("../index");
|
||||||
const cleanAST = require("../src/clean-ast").cleanAST;
|
const cleanAST = require("../src/clean-ast").cleanAST;
|
||||||
@@ -55,10 +56,12 @@ const argv = minimist(args, {
|
|||||||
"range-end",
|
"range-end",
|
||||||
"stdin-filepath",
|
"stdin-filepath",
|
||||||
"config",
|
"config",
|
||||||
"resolve-config"
|
"resolve-config",
|
||||||
|
"ignore-path"
|
||||||
],
|
],
|
||||||
default: {
|
default: {
|
||||||
color: true
|
color: true,
|
||||||
|
"ignore-path": ".prettierignore"
|
||||||
},
|
},
|
||||||
alias: {
|
alias: {
|
||||||
help: "h",
|
help: "h",
|
||||||
@@ -89,6 +92,7 @@ const write = argv["write"];
|
|||||||
const stdin = argv["stdin"] || (!filepatterns.length && !process.stdin.isTTY);
|
const stdin = argv["stdin"] || (!filepatterns.length && !process.stdin.isTTY);
|
||||||
const ignoreNodeModules = argv["with-node-modules"] === false;
|
const ignoreNodeModules = argv["with-node-modules"] === false;
|
||||||
const ignoreNodeModulesGlobs = ["!**/node_modules/**", "!./node_modules/**"];
|
const ignoreNodeModulesGlobs = ["!**/node_modules/**", "!./node_modules/**"];
|
||||||
|
const ignorePath = argv["ignore-path"];
|
||||||
const globOptions = {
|
const globOptions = {
|
||||||
dot: true
|
dot: true
|
||||||
};
|
};
|
||||||
@@ -283,6 +287,8 @@ if (
|
|||||||
" --list-different or -l Print filenames of files that are different from Prettier formatting.\n" +
|
" --list-different or -l Print filenames of files that are different from Prettier formatting.\n" +
|
||||||
" --config Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js).\n" +
|
" --config Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js).\n" +
|
||||||
" --resolve-config <path> Resolve the path to a configuration file for a given input file.\n" +
|
" --resolve-config <path> Resolve the path to a configuration file for a given input file.\n" +
|
||||||
|
" --ignore-path <path> Path to a file containing patterns that describe files to ignore.\n" +
|
||||||
|
" Defaults to ./.prettierignore.\n" +
|
||||||
" --stdin Read input from stdin.\n" +
|
" --stdin Read input from stdin.\n" +
|
||||||
" --stdin-filepath Path to the file used to read from stdin.\n" +
|
" --stdin-filepath Path to the file used to read from stdin.\n" +
|
||||||
" --print-width <int> Specify the length of line that the printer will wrap on. Defaults to 80.\n" +
|
" --print-width <int> Specify the length of line that the printer will wrap on. Defaults to 80.\n" +
|
||||||
@@ -446,6 +452,26 @@ function writeOutput(result, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function eachFilename(patterns, callback) {
|
function eachFilename(patterns, callback) {
|
||||||
|
// The ignorer will be used to filter file paths after the glob is checked,
|
||||||
|
// before any files are actually read
|
||||||
|
const ignoreFilePath = path.resolve(ignorePath);
|
||||||
|
let ignoreText = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
ignoreText = fs.readFileSync(ignoreFilePath, "utf8");
|
||||||
|
} catch (readError) {
|
||||||
|
if (readError.code !== "ENOENT") {
|
||||||
|
console.error(`Unable to read ${ignoreFilePath}:`, readError);
|
||||||
|
process.exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ignorer = ignore();
|
||||||
|
|
||||||
|
if (ignoreText.trim()) {
|
||||||
|
ignorer.add(ignoreText.split(/\r?\n/));
|
||||||
|
}
|
||||||
|
|
||||||
if (ignoreNodeModules) {
|
if (ignoreNodeModules) {
|
||||||
patterns = patterns.concat(ignoreNodeModulesGlobs);
|
patterns = patterns.concat(ignoreNodeModulesGlobs);
|
||||||
}
|
}
|
||||||
@@ -460,7 +486,7 @@ function eachFilename(patterns, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Use map series to ensure idempotency
|
// Use map series to ensure idempotency
|
||||||
mapSeries(filePaths, filePath => {
|
mapSeries(ignorer.filter(filePaths), filePath => {
|
||||||
return getOptionsForFile(filePath).then(options =>
|
return getOptionsForFile(filePath).then(options =>
|
||||||
callback(filePath, options)
|
callback(filePath, options)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
"get-stream": "3.0.0",
|
"get-stream": "3.0.0",
|
||||||
"globby": "^6.1.0",
|
"globby": "^6.1.0",
|
||||||
"graphql": "0.10.1",
|
"graphql": "0.10.1",
|
||||||
|
"ignore": "^3.3.3",
|
||||||
"jest-validate": "20.0.3",
|
"jest-validate": "20.0.3",
|
||||||
"json-to-ast": "2.0.0-alpha1.2",
|
"json-to-ast": "2.0.0-alpha1.2",
|
||||||
"minimatch": "3.0.4",
|
"minimatch": "3.0.4",
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`ignore path 1`] = `
|
||||||
|
"regular-module.js
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`support .prettierignore 1`] = `
|
||||||
|
"other-regular-modules.js
|
||||||
|
"
|
||||||
|
`;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const runPrettier = require("../runPrettier");
|
||||||
|
|
||||||
|
test("ignore path", () => {
|
||||||
|
const result = runPrettier("cli/ignore-path", [
|
||||||
|
"**/*.js",
|
||||||
|
"--ignore-path",
|
||||||
|
".gitignore",
|
||||||
|
"-l"
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(result.stdout).toMatchSnapshot();
|
||||||
|
expect(result.status).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("support .prettierignore", () => {
|
||||||
|
const result = runPrettier("cli/ignore-path", ["**/*.js", "-l"]);
|
||||||
|
|
||||||
|
expect(result.stdout).toMatchSnapshot();
|
||||||
|
expect(result.status).toEqual(1);
|
||||||
|
});
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
other-regular-modules.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
regular-module.js
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
'use strict';
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
'use strict';
|
||||||
Reference in new issue
Block a user