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

Adding rule id to a VCS message #156

Merged
merged 2 commits into from
Oct 30, 2023
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
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})` : '');
}
}