Skip to content

Commit 0057082

Browse files
Vedmaxmvedernikov
and
mvedernikov
authored
Adding rule id to a VCS message (#156)
* adding rule id to a VCS message * message linting fix --------- Co-authored-by: mvedernikov <[email protected]>
1 parent ccb5cd6 commit 0057082

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"homepage": "https://github.com/codeleague/codecoach",
99
"license": "MIT",
1010
"scripts": {
11-
"lint": "eslint 'src/**/*.{js,ts}' --quiet --fix",
12-
"lint-ci": "eslint 'src/**/*.{js,ts}'",
13-
"format": "prettier --write 'src/**/*.{js,ts}'",
11+
"lint": "eslint \"src/**/*.{js,ts}\" --quiet --fix",
12+
"lint-ci": "eslint \"src/**/*.{js,ts}\"",
13+
"format": "prettier --write \"src/**/*.{js,ts}\"",
1414
"test": "jest",
1515
"build": "tsc --project tsconfig.build.json",
1616
"dev": "nodemon --inspect=5858 --config ./nodemon.json -- --config=\"config-test.json\"",

src/AnalyzerBot/utils/commentUtil.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('groupComments', () => {
9797
text:
9898
':rotating_light: msg1' +
9999
' \n' +
100-
':warning: (SUPPRESSED) additional warning' +
100+
':warning: (SUPPRESSED) additional warning (rule: UNIMPORTANT_RULE2)' +
101101
' \n',
102102
},
103103
{
@@ -138,7 +138,7 @@ describe('groupComments', () => {
138138
text:
139139
':rotating_light: msg1' +
140140
' \n' +
141-
':warning: (SUPPRESSED) additional warning' +
141+
':warning: (SUPPRESSED) additional warning (rule: UNIMPORTANT_RULE/RULE2)' +
142142
' \n',
143143
},
144144
{

src/AnalyzerBot/utils/commentUtil.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function buildText(
4646
const { severity, msg } = item;
4747
const { text: currentText } = currentComment;
4848
const msgWithSuppression = isSuppressed ? `(SUPPRESSED) ${msg}` : msg;
49-
const text = MessageUtil.createMessageWithEmoji(msgWithSuppression, severity);
49+
const msgWithRuleId = MessageUtil.addRuleIdToMessage(msgWithSuppression, item.ruleId);
50+
const text = MessageUtil.createMessageWithEmoji(msgWithRuleId, severity);
5051
return `${currentText}${text} \n`;
5152
}
5253

src/AnalyzerBot/utils/message.util.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,18 @@ describe('generateCommitDescription', () => {
2626
expect(MessageUtil.generateCommitDescription(99)).toBe('CodeCoach report 99 errors');
2727
});
2828
});
29+
30+
describe('addRuleIdToMessage', () => {
31+
it('should add ruleId to message', () => {
32+
const msg = 'test';
33+
const ruleId = 'id';
34+
35+
expect(MessageUtil.addRuleIdToMessage(msg, ruleId)).toBe(`${msg} (rule: ${ruleId})`);
36+
});
37+
it('should not add ruleId to message if ruleId is empty', () => {
38+
const msg = 'test';
39+
const ruleId = '';
40+
41+
expect(MessageUtil.addRuleIdToMessage(msg, ruleId)).toBe(msg);
42+
});
43+
});

src/AnalyzerBot/utils/message.util.ts

+4
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ ${warningMsg}`;
4646
? `CodeCoach report ${nOfErrors} errors`
4747
: 'CodeCoach report no critical issue, good job!';
4848
}
49+
50+
static addRuleIdToMessage(msg: string, ruleId: string): string {
51+
return `${msg}` + (ruleId ? ` (rule: ${ruleId})` : '');
52+
}
4953
}

0 commit comments

Comments
 (0)