Skip to content

Commit

Permalink
Adding rule id to a VCS message (#156)
Browse files Browse the repository at this point in the history
* adding rule id to a VCS message

* message linting fix

---------

Co-authored-by: mvedernikov <[email protected]>
  • Loading branch information
Vedmax and mvedernikov authored Oct 30, 2023
1 parent ccb5cd6 commit 0057082
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"homepage": "https://github.com/codeleague/codecoach",
"license": "MIT",
"scripts": {
"lint": "eslint 'src/**/*.{js,ts}' --quiet --fix",
"lint-ci": "eslint 'src/**/*.{js,ts}'",
"format": "prettier --write 'src/**/*.{js,ts}'",
"lint": "eslint \"src/**/*.{js,ts}\" --quiet --fix",
"lint-ci": "eslint \"src/**/*.{js,ts}\"",
"format": "prettier --write \"src/**/*.{js,ts}\"",
"test": "jest",
"build": "tsc --project tsconfig.build.json",
"dev": "nodemon --inspect=5858 --config ./nodemon.json -- --config=\"config-test.json\"",
Expand Down
4 changes: 2 additions & 2 deletions src/AnalyzerBot/utils/commentUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('groupComments', () => {
text:
':rotating_light: msg1' +
' \n' +
':warning: (SUPPRESSED) additional warning' +
':warning: (SUPPRESSED) additional warning (rule: UNIMPORTANT_RULE2)' +
' \n',
},
{
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('groupComments', () => {
text:
':rotating_light: msg1' +
' \n' +
':warning: (SUPPRESSED) additional warning' +
':warning: (SUPPRESSED) additional warning (rule: UNIMPORTANT_RULE/RULE2)' +
' \n',
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/AnalyzerBot/utils/commentUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function buildText(
const { severity, msg } = item;
const { text: currentText } = currentComment;
const msgWithSuppression = isSuppressed ? `(SUPPRESSED) ${msg}` : msg;
const text = MessageUtil.createMessageWithEmoji(msgWithSuppression, severity);
const msgWithRuleId = MessageUtil.addRuleIdToMessage(msgWithSuppression, item.ruleId);
const text = MessageUtil.createMessageWithEmoji(msgWithRuleId, severity);
return `${currentText}${text} \n`;
}

Expand Down
15 changes: 15 additions & 0 deletions src/AnalyzerBot/utils/message.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ describe('generateCommitDescription', () => {
expect(MessageUtil.generateCommitDescription(99)).toBe('CodeCoach report 99 errors');
});
});

describe('addRuleIdToMessage', () => {
it('should add ruleId to message', () => {
const msg = 'test';
const ruleId = 'id';

expect(MessageUtil.addRuleIdToMessage(msg, ruleId)).toBe(`${msg} (rule: ${ruleId})`);
});
it('should not add ruleId to message if ruleId is empty', () => {
const msg = 'test';
const ruleId = '';

expect(MessageUtil.addRuleIdToMessage(msg, ruleId)).toBe(msg);
});
});
4 changes: 4 additions & 0 deletions src/AnalyzerBot/utils/message.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ ${warningMsg}`;
? `CodeCoach report ${nOfErrors} errors`
: 'CodeCoach report no critical issue, good job!';
}

static addRuleIdToMessage(msg: string, ruleId: string): string {
return `${msg}` + (ruleId ? ` (rule: ${ruleId})` : '');
}
}

0 comments on commit 0057082

Please sign in to comment.