Skip to content

Commit

Permalink
Merge pull request #1961 from Accenture/task/1960-hide-pretter-error-…
Browse files Browse the repository at this point in the history
…log-files-behind-config-option

task/1960 hide pretter error log behind config option formatErrorLog
  • Loading branch information
JoernBerkefeld authored Jan 7, 2025
2 parents 6a6db1b + 2036e78 commit 705279f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion @types/lib/util/file.d.ts.map

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

1 change: 1 addition & 0 deletions boilerplate/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"options": {
"formatOnSave": true,
"formatErrorLog": false,
"deployment": {
"commitHistory": 10,
"sourceTargetMapping": {
Expand Down
31 changes: 17 additions & 14 deletions lib/util/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ const File = {
* @returns {Promise.<string>} original string on error; formatted string on success
*/
_beautify_prettier: async function (directory, filename, filetype, content) {
const properties = await config.getProperties();
let formatted = '';
try {
if (!FileFs.prettierConfig) {
Expand Down Expand Up @@ -337,20 +338,22 @@ const File = {

formatted = await prettier.format(content, FileFs.prettierConfig);
} catch (ex) {
// save prettier errror into log file
// Note: we have to filter color codes from prettier's error message before saving it to file
/* eslint-disable no-control-regex */
this.writeToFile(
directory,
filename + '.error',
'log',
`Error Log\nParser: ${FileFs.prettierConfig.parser}\n${ex.message.replaceAll(
/[\u001B\u009B][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
''
)}`
);
/* eslint-enable no-control-regex */
if (properties.options.formatErrorLog) {
// save prettier errror into log file
// Note: we have to filter color codes from prettier's error message before saving it to file
/* eslint-disable no-control-regex */
this.writeToFile(
directory,
filename + '.error',
'log',
`Error Log\nParser: ${FileFs.prettierConfig.parser}\n${ex.message.replaceAll(
/[\u001B\u009B][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
''
)}`
);
/* eslint-enable no-control-regex */
}

formatted = content;
}
Expand Down
1 change: 1 addition & 0 deletions test/mockRoot/.mcdevrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"options": {
"formatOnSave": true,
"formatErrorLog": false,
"deployment": {
"commitHistory": 10,
"sourceTargetMapping": {
Expand Down

0 comments on commit 705279f

Please sign in to comment.