Skip to content

Commit e9ff8e2

Browse files
jeeyoNatchanon Nuntanirund
andauthored
add ruleId and type to codecoach output (#139)
* add problem and type to codecoach output * rename problem to ruleId * change scalastyle ruleId to source * fix provider mock data * remove unused imports --------- Co-authored-by: Natchanon Nuntanirund <[email protected]>
1 parent 1d18a9d commit e9ff8e2

17 files changed

+77
-7
lines changed

src/Parser/@types/log.type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { LogSeverity } from '..';
2+
import { ProjectType } from '../../Config/@enums';
23

34
export type LogType = {
5+
ruleId: string;
46
log: string;
57
msg: string;
68
severity: LogSeverity;
79
source: string;
810
line?: number;
911
lineOffset?: number;
1012
valid: boolean;
13+
type: ProjectType;
1114
};

src/Parser/AndroidLintStyleParser.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,39 @@ describe('AndroidLintStyleParser', () => {
99
expect(result).toHaveLength(3);
1010

1111
expect(result[0]).toEqual({
12+
ruleId: 'GradleDependency',
1213
source: 'app/build.gradle',
1314
severity: LogSeverity.warning,
1415
line: 42,
1516
lineOffset: 5,
1617
msg: `A newer version of org.jetbrains.kotlin:kotlin-stdlib than 1.3.72 is available: 1.4.20`,
1718
log: `implementation org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version`,
1819
valid: true,
20+
type: 'androidlint',
1921
});
2022

2123
expect(result[1]).toEqual({
24+
ruleId: 'MissingTranslation',
2225
source: `app/src/main/res/values/strings.xml`,
2326
severity: LogSeverity.error,
2427
line: 4,
2528
lineOffset: 13,
2629
msg: `esp is not translated in (Thai)`,
2730
log: `<string name=esp>My Application</string>`,
2831
valid: true,
32+
type: 'androidlint',
2933
});
3034

3135
expect(result[2]).toEqual({
36+
ruleId: 'SetJavaScriptEnabled',
3237
source: `app/src/main/java/com/example/app/MainActivity.kt`,
3338
severity: LogSeverity.warning,
3439
line: 16,
3540
lineOffset: 9,
3641
msg: `Using \`setJavaScriptEnabled\` can introduce XSS vulnerabilities into your application, review carefully`,
3742
log: `webView.settings.javaScriptEnabled = true`,
3843
valid: true,
44+
type: 'androidlint',
3945
});
4046
});
4147

src/Parser/AndroidLintStyleParser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { xml2js } from 'xml-js';
66
import { AndroidLintStyleIssue } from './@types/AndroidLintStyleIssue';
77
import { AndroidLintStyleLog } from './@types/AndroidLintStyleLog';
88
import { AndroidLintStyleLocation } from './@types/AndroidLintStyleLocation';
9+
import { ProjectType } from '../Config/@enums';
910

1011
export class AndroidLintStyleParser extends Parser {
1112
parse(content: string): LogType[] {
@@ -31,6 +32,7 @@ export class AndroidLintStyleParser extends Parser {
3132
cwd: string,
3233
): LogType {
3334
return {
35+
ruleId: issue._attributes.id,
3436
log: issue._attributes.errorLine1?.trim(),
3537
line: location._attributes.line,
3638
lineOffset: location._attributes.column,
@@ -40,6 +42,7 @@ export class AndroidLintStyleParser extends Parser {
4042
issue._attributes.severity.toLowerCase(),
4143
),
4244
valid: true,
45+
type: ProjectType.androidlint,
4346
};
4447
}
4548

src/Parser/DartLintParser.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,51 @@ describe('DartLintStyleParser', () => {
2727
expect(result).toHaveLength(4);
2828

2929
expect(result[0]).toEqual({
30+
ruleId: 'unused_import',
3031
source: 'api/modules/lib/auth/auth.dart',
3132
severity: LogSeverity.info,
3233
line: 1,
3334
lineOffset: 8,
3435
msg: `Unused import: 'dart:async'`,
3536
log: `unused_import`,
3637
valid: true,
38+
type: 'dartlint',
3739
});
3840

3941
expect(result[1]).toEqual({
42+
ruleId: 'await_only_futures',
4043
source: `lib/domain/providers/sharable_images_repo.dart`,
4144
severity: LogSeverity.info,
4245
line: 114,
4346
lineOffset: 5,
4447
msg: `'await' applied to 'void', which is not a 'Future'`,
4548
log: `await_only_futures`,
4649
valid: true,
50+
type: 'dartlint',
4751
});
4852

4953
expect(result[2]).toEqual({
54+
ruleId: 'sort_child_properties_last',
5055
source: `lib/presentation/widgets/platform_flat_button.dart`,
5156
severity: LogSeverity.error,
5257
line: 34,
5358
lineOffset: 9,
5459
msg: `Sort child properties last in widget instance creations`,
5560
log: `sort_child_properties_last`,
5661
valid: true,
62+
type: 'dartlint',
5763
});
5864

5965
expect(result[3]).toEqual({
66+
ruleId: 'invalid_annotation_target',
6067
source: `test_driver/tests/offline/offline_test.dart`,
6168
severity: LogSeverity.error,
6269
line: 13,
6370
lineOffset: 2,
6471
msg: `The annotation 'Timeout' can only be used on libraries`,
6572
log: `invalid_annotation_target`,
6673
valid: true,
74+
type: 'dartlint',
6775
});
6876
});
6977

src/Parser/DartLintParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Parser } from './@interfaces/parser.interface';
22
import { LogType } from './@types';
33
import { LogSeverity } from './@enums/log.severity.enum';
44
import { splitByLine } from './utils/lineBreak.util';
5+
import { ProjectType } from '../Config/@enums';
56

67
export class DartLintParser extends Parser {
78
parse(content: string): LogType[] {
@@ -18,13 +19,15 @@ export class DartLintParser extends Parser {
1819
private static lineMatchToLog(lineMatch: RegExpMatchArray): LogType {
1920
const [, severityText, message, source, line, offset, log] = lineMatch;
2021
return {
22+
ruleId: log,
2123
log: log,
2224
line: Number(line),
2325
lineOffset: Number(offset),
2426
msg: message,
2527
source: source,
2628
severity: DartLintParser.stringToSeverity(severityText),
2729
valid: true,
30+
type: ProjectType.dartlint,
2831
};
2932
}
3033

@@ -42,10 +45,12 @@ export class DartLintParser extends Parser {
4245
}
4346

4447
private static emptyLog: LogType = {
48+
ruleId: '',
4549
log: '',
4650
msg: '',
4751
severity: LogSeverity.unknown,
4852
source: '',
4953
valid: false,
54+
type: ProjectType.dartlint,
5055
};
5156
}

src/Parser/DotnetBuildParser.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,47 @@ describe('DotnetBuildParser tests', () => {
1616
const result = new DotnetBuildParser(cwdWin).parse(logWithSource);
1717
expect(result).toHaveLength(1);
1818
expect(result[0]).toEqual({
19+
ruleId: 'AG0030',
1920
source: `Broken.cs`,
2021
severity: LogSeverity.warning,
2122
line: 6,
2223
lineOffset: 8,
2324
msg: `AG0030: Prevent use of dynamic`,
2425
log: logWithSource,
2526
valid: true,
27+
type: 'dotnetbuild',
2628
} as LogType);
2729
});
2830

2931
it('Should parse log without source path correctly and flag as invalid and use csproj as source', () => {
3032
const result = new DotnetBuildParser(cwdWin).parse(logWithNoSource);
3133
expect(result).toHaveLength(1);
3234
expect(result[0]).toEqual({
35+
ruleId: 'CS5001',
3336
source: `Broken.csproj`,
3437
severity: LogSeverity.error,
3538
line: NaN,
3639
lineOffset: NaN,
3740
msg: `CS5001: Program does not contain a static 'Main' method suitable for an entry point`,
3841
log: logWithNoSource,
3942
valid: false,
43+
type: 'dotnetbuild',
4044
} as LogType);
4145
});
4246

4347
it('Should parse log unrelated source path correctly and flag as invalid and use csproj as source', () => {
4448
const result = new DotnetBuildParser(cwdUnix).parse(logWithUnrelatedSource);
4549
expect(result).toHaveLength(1);
4650
expect(result[0]).toEqual({
51+
ruleId: 'MSB3277',
4752
source: `project.csproj`,
4853
severity: LogSeverity.warning,
4954
line: 2084,
5055
lineOffset: 5,
5156
msg: `MSB3277: some message`,
5257
log: logWithUnrelatedSource,
5358
valid: false,
59+
type: 'dotnetbuild',
5460
} as LogType);
5561
});
5662

src/Parser/DotnetBuildParser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Parser } from './@interfaces/parser.interface';
77
import { LogType } from './@types';
88
import { mapSeverity } from './utils/dotnetSeverityMap';
99
import { splitByLine } from './utils/lineBreak.util';
10+
import { ProjectType } from '../Config/@enums';
1011

1112
export class DotnetBuildParser extends Parser {
1213
parse(content: string): LogType[] {
@@ -45,13 +46,15 @@ export class DotnetBuildParser extends Parser {
4546
}
4647

4748
return {
49+
ruleId: errorCode,
4850
log,
4951
line: Number(_line),
5052
lineOffset: Number(_lineOffset),
5153
msg: `${errorCode.trim()}: ${content.trim()}`,
5254
source: relativeSrcPath ?? basename(slash(_csproj)),
5355
severity: mapSeverity(severityText),
5456
valid: !!relativeSrcPath,
57+
type: ProjectType.dotnetbuild,
5558
};
5659
}
5760
}

src/Parser/ESLintParser.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,27 @@ describe('ESLintParser', () => {
5454
expect(result).toHaveLength(2);
5555

5656
expect(result[0]).toEqual({
57+
ruleId: '',
5758
source: '',
5859
severity: LogSeverity.error,
5960
line: 59,
6061
lineOffset: 8,
6162
msg: `Parsing error: ')' expected.`,
6263
log: JSON.stringify(mockedContent[0].messages[0]),
6364
valid: false,
65+
type: 'eslint',
6466
});
6567

6668
expect(result[1]).toEqual({
69+
ruleId: '@typescript-eslint/no-unused-vars',
6770
source: `src/app.ts`,
6871
severity: LogSeverity.warning,
6972
line: 24,
7073
lineOffset: 15,
7174
msg: `'content' is defined but never used.`,
7275
log: JSON.stringify(mockedContent[1].messages[0]),
7376
valid: true,
77+
type: 'eslint',
7478
});
7579
});
7680

src/Parser/ESLintParser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ProjectType } from '../Config/@enums';
12
import { Log } from '../Logger';
23
import { getRelativePath } from '../Provider/utils/path.util';
34
import { LogSeverity } from './@enums/log.severity.enum';
@@ -24,13 +25,15 @@ export class ESLintParser extends Parser {
2425

2526
private static toLog(log: ESLintIssue, source: string | null): LogType {
2627
return {
28+
ruleId: log.ruleId ?? '',
2729
log: JSON.stringify(log),
2830
line: log.line,
2931
lineOffset: log.column,
3032
msg: log.message,
3133
source: source ?? '',
3234
severity: ESLintParser.getSeverity(log.severity),
3335
valid: source !== null,
36+
type: ProjectType.eslint,
3437
};
3538
}
3639

src/Parser/MSBuildParser.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { LogSeverity } from './@enums/log.severity.enum';
22
import { MSBuildParser } from './MSBuildParser';
3-
import * as fs from 'fs/promises';
43

54
describe('MSBuildParser tests', () => {
65
const cwd = 'C:\\source';
@@ -12,13 +11,15 @@ describe('MSBuildParser tests', () => {
1211

1312
expect(result).toHaveLength(1);
1413
expect(result[0]).toEqual({
14+
ruleId: 'CS0414',
1515
source: `Project/Service/Provider.cs`,
1616
severity: LogSeverity.warning,
1717
line: 67,
1818
lineOffset: 29,
1919
msg: `CS0414: The field 'Data.field' is assigned but its value is never used`,
2020
log,
2121
valid: true,
22+
type: 'msbuild',
2223
});
2324
});
2425

0 commit comments

Comments
 (0)