Skip to content

Commit

Permalink
revert: --only-changed argument (#6594)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and duailibe committed Oct 3, 2019
1 parent 3f13d2e commit 6d4d6a7
Show file tree
Hide file tree
Showing 17 changed files with 9 additions and 426 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,6 @@ useEffect(

This version updates the TypeScript parser to correctly handle JSX text with double slashes (`//`). In previous versions, this would cause Prettier to crash.

#### CLI: Add `--only-changed` flag ([#5910] by [@g-harel])

Flag used with `--write` to avoid re-checking files that were not changed since they were last written (with the same formatting configuration).

#### HTML, Vue: Don't break the template element included in a line shorter than print-width([#6284] by [@sosukesuzuki])
Previously, even if the line length is shorter than print-width is Prettier breaks the line with a template element.
Expand Down
2 changes: 0 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ Prettier CLI will ignore files located in `node_modules` directory. To opt-out f

This rewrites all processed files in place. This is comparable to the `eslint --fix` workflow.

To avoid re-checking unchanged files, use the `--only-changed` flag.

## `--loglevel`

Change the level of logging for the CLI. Valid options are:
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"editorconfig-to-prettier": "0.1.1",
"escape-string-regexp": "1.0.5",
"esutils": "2.0.3",
"find-cache-dir": "1.0.0",
"find-parent-dir": "0.3.0",
"find-project-root": "1.1.1",
"flow-parser": "0.89.0",
Expand Down Expand Up @@ -72,7 +71,6 @@
"unicode-regex": "3.0.0",
"unified": "6.1.6",
"vnopts": "1.0.2",
"write-file-atomic": "2.3.0",
"yaml": "1.1.0",
"yaml-unist-parser": "1.0.0"
},
Expand Down
79 changes: 0 additions & 79 deletions src/cli/changed-cache.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/cli/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ const options = {
default: "log",
choices: ["silent", "error", "warn", "log", "debug"]
},
"only-changed": {
type: "boolean",
description: "Only format files changed since last '--write'."
},
stdin: {
type: "boolean",
description: "Force reading input from stdin."
Expand Down
5 changes: 0 additions & 5 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ function run(args) {
process.exit(1);
}

if (context.argv["only-changed"] && !context.argv["write"]) {
context.logger.error("Cannot use --only-changed without --write.");
process.exit(1);
}

if (context.argv["find-config-path"] && context.filePatterns.length) {
context.logger.error("Cannot use --find-config-path with multiple files");
process.exit(1);
Expand Down
58 changes: 7 additions & 51 deletions src/cli/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const globby = require("globby");
const chalk = require("chalk");
const readline = require("readline");
const stringify = require("json-stable-stringify");
const findCacheDir = require("find-cache-dir");
const os = require("os");

const minimist = require("./minimist");
const prettier = require("../../index");
Expand All @@ -22,7 +20,6 @@ const optionsNormalizer = require("../main/options-normalizer");
const thirdParty = require("../common/third-party");
const arrayify = require("../utils/arrayify");
const isTTY = require("../utils/is-tty");
const ChangedCache = require("./changed-cache");

const OPTION_USAGE_THRESHOLD = 25;
const CHOICE_USAGE_MARGIN = 3;
Expand Down Expand Up @@ -444,20 +441,6 @@ function formatFiles(context) {
context.logger.log("Checking formatting...");
}

let changedCache = null;
if (context.argv["only-changed"]) {
const cacheDir =
findCacheDir({ name: "prettier", create: true }) || os.tmpdir();

changedCache = new ChangedCache({
location: path.join(cacheDir, "changed"),
readFile: fs.readFileSync,
writeFile: thirdParty.writeFileAtomic,
context: context,
supportInfo: prettier.getSupportInfo()
});
}

eachFilename(context, context.filePatterns, filename => {
const fileIgnored = ignorer.filter([filename]).length === 0;
if (
Expand All @@ -474,15 +457,9 @@ function formatFiles(context) {
filepath: filename
});

let removeFilename = () => {};
if (isTTY()) {
// Don't use `console.log` here since we need to replace this line.
context.logger.log(filename, { newline: false });
removeFilename = () => {
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0, null);
removeFilename = () => {};
};
}

let input;
Expand All @@ -500,19 +477,6 @@ function formatFiles(context) {
return;
}

if (changedCache) {
if (changedCache.notChanged(filename, options, input)) {
// Remove previously printed filename to log it with "unchanged".
removeFilename();

if (!context.argv["check"] && !context.argv["list-different"]) {
context.logger.log(chalk.grey(`${filename} unchanged`));
}

return;
}
}

if (fileIgnored) {
writeOutput(context, { formatted: input }, options);
return;
Expand All @@ -537,8 +501,11 @@ function formatFiles(context) {

const isDifferent = output !== input;

// Remove previously printed filename to log it with duration.
removeFilename();
if (isTTY()) {
// Remove previously printed filename to log it with duration.
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0, null);
}

if (context.argv["write"]) {
// Don't write the file if it won't change in order not to invalidate
Expand All @@ -557,15 +524,8 @@ function formatFiles(context) {
// Don't exit the process if one file failed
process.exitCode = 2;
}
} else {
if (!context.argv["check"] && !context.argv["list-different"]) {
context.logger.log(`${chalk.grey(filename)} ${Date.now() - start}ms`);
}
}

// Cache is updated to record pretty content.
if (changedCache) {
changedCache.update(filename, options, output);
} else if (!context.argv["check"] && !context.argv["list-different"]) {
context.logger.log(`${chalk.grey(filename)} ${Date.now() - start}ms`);
}
} else if (context.argv["debug-check"]) {
if (result.filepath) {
Expand All @@ -586,10 +546,6 @@ function formatFiles(context) {
}
});

if (changedCache) {
changedCache.close();
}

// Print check summary based on expected exit code
if (context.argv["check"]) {
context.logger.log(
Expand Down
3 changes: 1 addition & 2 deletions src/common/third-party.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ module.exports = {
cosmiconfig: require("cosmiconfig"),
findParentDir: require("find-parent-dir").sync,
getStream: require("get-stream"),
isCI: () => require("is-ci"),
writeFileAtomic: require("write-file-atomic").sync
isCI: () => require("is-ci")
};
11 changes: 0 additions & 11 deletions tests_integration/__tests__/__snapshots__/early-exit.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ Other options:
--loglevel <silent|error|warn|log|debug>
What level of logs to report.
Defaults to log.
--only-changed Only format files changed since last '--write'.
--require-pragma Require either '@prettier' or '@format' to be present in the file's first docblock comment
in order for it to be formatted.
Defaults to false.
Expand Down Expand Up @@ -301,7 +300,6 @@ Other options:
--loglevel <silent|error|warn|log|debug>
What level of logs to report.
Defaults to log.
--only-changed Only format files changed since last '--write'.
--require-pragma Require either '@prettier' or '@format' to be present in the file's first docblock comment
in order for it to be formatted.
Defaults to false.
Expand Down Expand Up @@ -352,15 +350,6 @@ exports[`throw error with --help not-found (stdout) 1`] = `""`;
exports[`throw error with --help not-found (write) 1`] = `Array []`;
exports[`throw error with --only-changed without --write (stderr) 1`] = `
"[error] Cannot use --only-changed without --write.
"
`;
exports[`throw error with --only-changed without --write (stdout) 1`] = `""`;
exports[`throw error with --only-changed without --write (write) 1`] = `Array []`;
exports[`throw error with --write + --debug-check (stderr) 1`] = `
"[error] Cannot use --write and --debug-check together.
"
Expand Down
11 changes: 0 additions & 11 deletions tests_integration/__tests__/__snapshots__/help-options.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,6 @@ exports[`show detailed usage with --help no-semi (stdout) 1`] = `
exports[`show detailed usage with --help no-semi (write) 1`] = `Array []`;
exports[`show detailed usage with --help only-changed (stderr) 1`] = `""`;
exports[`show detailed usage with --help only-changed (stdout) 1`] = `
"--only-changed
Only format files changed since last '--write'.
"
`;
exports[`show detailed usage with --help only-changed (write) 1`] = `Array []`;
exports[`show detailed usage with --help parser (stderr) 1`] = `""`;
exports[`show detailed usage with --help parser (stdout) 1`] = `
Expand Down
43 changes: 0 additions & 43 deletions tests_integration/__tests__/__snapshots__/only-changed.js.snap

This file was deleted.

6 changes: 0 additions & 6 deletions tests_integration/__tests__/early-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ describe("throw error with --write + --debug-check", () => {
});
});

describe("throw error with --only-changed without --write", () => {
runPrettier("cli", ["--only-changed"]).test({
status: 1
});
});

describe("throw error with --find-config-path + multiple files", () => {
runPrettier("cli", ["--find-config-path", "abc.js", "def.js"]).test({
status: 1
Expand Down

0 comments on commit 6d4d6a7

Please sign in to comment.