Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes prettier async in code quality file #4026

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading