Skip to content

Commit

Permalink
Makes prettier async in code quality file (#4026)
Browse files Browse the repository at this point in the history
  • Loading branch information
walmazacn authored Nov 22, 2024
1 parent 44ec648 commit 89e0fea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
26 changes: 17 additions & 9 deletions code_quality.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const gitChangedFiles = require('git-changed-files');
const prettier = require('@prettier/sync');
const prettier = require('prettier');
const prettierConfig = require('./prettier_config.json');
const codeQualityConfig = require('./package.json').codeQuality || {};
const path = require('path');
Expand Down Expand Up @@ -107,16 +107,23 @@ const groupFilesByExtension = (files) => {
* @param file: absolute class path
* @param config: configuration that will be used to prettier the file.
*/
const prettifyFile = (file, config) => {
const prettifyFile = async (file, config) => {
try {
const text = fs.readFileSync(file).toString();
if (prettier.check(text, config) || config?.excludedFiles?.includes(file)) {
if (config?.excludedFiles?.includes(file)) {
return;
}

console.log('Running prettier on the file: ' + file);
fs.writeFileSync(file, prettier.format(text, config));
return true;
const fileContent = fs.readFileSync(file).toString();
const isFormatted = await prettier.check(fileContent, config);

if (!isFormatted) {
console.log('Running prettier on the file: ' + file);
const format = await prettier.format(fileContent, config);
fs.writeFileSync(file, format);
return true;
}

return false;
} catch (error) {
console.log('Error in running prettier the file ' + file + ': \n' + error);
}
Expand All @@ -140,8 +147,9 @@ const prettifyFiles = (filesByExtension) => {
);
return;
}
files.forEach((file) => {
if (prettifyFile(file, config)) {
files.forEach(async (file) => {
const action = await prettifyFile(file, config);
if (action) {
filesChanged++;
}
});
Expand Down
27 changes: 0 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"full-code-quality-eslint-e2e-tests": "node code_quality.js -- mode=full_eslint sourcePaths=test/e2e-test-application/cypress/e2e/tests report=e2e-test_full_eslint_report.html"
},
"devDependencies": {
"@prettier/sync": "^0.5.2",
"@stylistic/eslint-plugin": "^2.10.1",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
Expand Down

0 comments on commit 89e0fea

Please sign in to comment.