mirror of
https://github.com/facebook/react.git
synced 2026-02-27 03:07:57 +00:00
I sincerely appreciate the effort to get test262 up and running. This was my idea, it seemed like a really good way to test our correctness on edge cases of JS. Unfortunately test262 relies heavily on a few specific features that we don't support, like classes and `var`, which has meant that we never actually use this as a test suite. In the meantime we've created a pretty extensive test suite and have tools like Sprout to test actual memoization behavior at runtime, which is the right place to invest our energy. Let's remove?
86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
// Based on similar script in React
|
|
// https://github.com/facebook/react/blob/main/scripts/prettier/index.js
|
|
|
|
const chalk = require("chalk");
|
|
const glob = require("glob");
|
|
const prettier = require("prettier");
|
|
const fs = require("fs");
|
|
const listChangedFiles = require("./shared/list-changed-files");
|
|
const prettierConfigPath = require.resolve("../.prettierrc");
|
|
|
|
const mode = process.argv[2] || "check";
|
|
const shouldWrite = mode === "write" || mode === "write-changed";
|
|
const onlyChanged = mode === "check-changed" || mode === "write-changed";
|
|
|
|
const changedFiles = onlyChanged ? listChangedFiles() : null;
|
|
let didWarn = false;
|
|
let didError = false;
|
|
|
|
const files = glob
|
|
.sync("**/*.{js,ts,tsx,jsx}", {
|
|
ignore: [
|
|
"**/node_modules/**",
|
|
"packages/demo-2021Q3/**",
|
|
"packages/demo-todolist-live/**",
|
|
"packages/demo-todolist-next/**",
|
|
"packages/demo-todolist-playground/**",
|
|
"packages/eslint-browser/**",
|
|
"**/__tests__/fixtures/**/*.flow.js",
|
|
],
|
|
})
|
|
.filter((f) => !onlyChanged || changedFiles.has(f));
|
|
if (!files.length) {
|
|
return;
|
|
}
|
|
|
|
files.forEach((file) => {
|
|
const options = prettier.resolveConfig.sync(file, {
|
|
config: prettierConfigPath,
|
|
});
|
|
try {
|
|
const input = fs.readFileSync(file, "utf8");
|
|
if (shouldWrite) {
|
|
const output = prettier.format(input, options);
|
|
if (output !== input) {
|
|
fs.writeFileSync(file, output, "utf8");
|
|
}
|
|
} else {
|
|
if (!prettier.check(input, options)) {
|
|
if (!didWarn) {
|
|
console.log(
|
|
"\n" +
|
|
chalk.red(
|
|
` This project uses prettier to format all JavaScript code.\n`
|
|
) +
|
|
chalk.dim(` Please run `) +
|
|
chalk.reset("yarn prettier:all") +
|
|
chalk.dim(
|
|
` and add changes to files listed below to your commit:`
|
|
) +
|
|
`\n\n`
|
|
);
|
|
didWarn = true;
|
|
}
|
|
console.log(file);
|
|
}
|
|
}
|
|
} catch (error) {
|
|
didError = true;
|
|
console.log("\n\n" + error.message);
|
|
console.log(file);
|
|
}
|
|
});
|
|
|
|
if (didWarn || didError) {
|
|
process.exitCode = 1;
|
|
}
|