summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2018-10-19 10:42:35 -0500
committerMike Greiling <mike@pixelcog.com>2018-10-19 10:42:35 -0500
commit748b3b92b979bbd66f809c6b5139e9799cb51a1a (patch)
tree3c0b1741db797b17b90b26b25c42c18f5959c091
parent85bc76ac79c5462baa9f55e75a2830c02a52376e (diff)
downloadgitlab-ce-mg-update-prettier-script.tar.gz
Separate prettier check into smaller utility functionsmg-update-prettier-script
-rw-r--r--scripts/frontend/prettier.js69
1 files changed, 35 insertions, 34 deletions
diff --git a/scripts/frontend/prettier.js b/scripts/frontend/prettier.js
index 5ec697bb251..ce86a9f4601 100644
--- a/scripts/frontend/prettier.js
+++ b/scripts/frontend/prettier.js
@@ -51,8 +51,6 @@ let passedCount = 0;
let failedCount = 0;
let ignoredCount = 0;
-const getFileInfoOptions = { ignorePath: '.prettierignore' };
-
console.log(`${shouldSave ? 'Updating' : 'Checking'} ${matchedCount} file(s)`);
const fixCommand = `yarn prettier-${allFiles ? 'all' : 'staged'}-save`;
@@ -63,44 +61,47 @@ Please format each file listed below or run "${fixCommand}"
===============================
`;
-Promise.all(
- matchedFiles.map(filePath =>
- prettier.getFileInfo(filePath, getFileInfoOptions).then(({ ignored, inferredParser }) => {
+const checkFileWithOptions = (filePath, options) =>
+ readFileAsync(filePath, 'utf8').then(input => {
+ if (shouldSave) {
+ const output = prettier.format(input, options);
+ if (input === output) {
+ passedCount += 1;
+ } else {
+ return writeFileAsync(filePath, output, 'utf8').then(() => {
+ console.log(`Prettified : ${filePath}`);
+ failedCount += 1;
+ });
+ }
+ } else {
+ if (prettier.check(input, options)) {
+ passedCount += 1;
+ } else {
+ if (!didWarn) {
+ console.log(warningMessage);
+ didWarn = true;
+ }
+ console.log(`Prettify Manually : ${filePath}`);
+ failedCount += 1;
+ }
+ }
+ });
+
+const checkFileWithPrettierConfig = filePath =>
+ prettier
+ .getFileInfo(filePath, { ignorePath: '.prettierignore' })
+ .then(({ ignored, inferredParser }) => {
if (ignored || !inferredParser) {
ignoredCount += 1;
return;
}
return prettier.resolveConfig(filePath).then(fileOptions => {
- return readFileAsync(filePath, 'utf8').then(input => {
- const options = { ...fileOptions, parser: inferredParser };
-
- if (shouldSave) {
- const output = prettier.format(input, options);
- if (input === output) {
- passedCount += 1;
- } else {
- return writeFileAsync(filePath, output, 'utf8').then(() => {
- console.log(`Prettified : ${filePath}`);
- failedCount += 1;
- });
- }
- } else {
- if (prettier.check(input, options)) {
- passedCount += 1;
- } else {
- if (!didWarn) {
- console.log(warningMessage);
- didWarn = true;
- }
- console.log(`Prettify Manually : ${filePath}`);
- failedCount += 1;
- }
- }
- });
+ const options = { ...fileOptions, parser: inferredParser };
+ return checkFileWithOptions(filePath, options);
});
- })
- )
-)
+ });
+
+Promise.all(matchedFiles.map(checkFileWithPrettierConfig))
.then(() => {
const failAction = shouldSave ? 'fixed' : 'failed';
console.log(