Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dicko2 committed Oct 23, 2024
1 parent d565a10 commit c762648
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 114 deletions.
156 changes: 79 additions & 77 deletions src/Parser/SarifParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,36 @@ describe('SarifParser tests', () => {
{
id: 'TEST001',
shortDescription: {
text: 'Test rule description'
}
}
]
}
text: 'Test rule description',
},
},
],
},
},
results: [
{
ruleId: 'TEST001',
level: 'warning',
message: {
text: 'This is a test warning'
text: 'This is a test warning',
},
locations: [
{
physicalLocation: {
artifactLocation: {
uri: 'C:\\source\\Test.cs'
uri: 'C:\\source\\Test.cs',
},
region: {
startLine: 42,
startColumn: 13
}
}
}
]
}
]
}
]
startColumn: 13,
},
},
},
],
},
],
},
],
};

const sarifLogNoLocation = {
Expand All @@ -55,20 +55,20 @@ describe('SarifParser tests', () => {
{
tool: {
driver: {
name: 'TestAnalyzer'
}
name: 'TestAnalyzer',
},
},
results: [
{
ruleId: 'TEST002',
level: 'error',
message: {
text: 'Error without location'
}
}
]
}
]
text: 'Error without location',
},
},
],
},
],
};

const sarifLogMultipleResults = {
Expand All @@ -77,53 +77,53 @@ describe('SarifParser tests', () => {
{
tool: {
driver: {
name: 'TestAnalyzer'
}
name: 'TestAnalyzer',
},
},
results: [
{
ruleId: 'TEST003',
level: 'warning',
message: {
text: 'First warning'
text: 'First warning',
},
locations: [
{
physicalLocation: {
artifactLocation: {
uri: 'C:\\source\\Test1.cs'
uri: 'C:\\source\\Test1.cs',
},
region: {
startLine: 10,
startColumn: 5
}
}
}
]
startColumn: 5,
},
},
},
],
},
{
ruleId: 'TEST004',
level: 'error',
message: {
text: 'Second error'
text: 'Second error',
},
locations: [
{
physicalLocation: {
artifactLocation: {
uri: 'C:\\source\\Test2.cs'
uri: 'C:\\source\\Test2.cs',
},
region: {
startLine: 20,
startColumn: 8
}
}
}
]
}
]
}
]
startColumn: 8,
},
},
},
],
},
],
},
],
};

const sarifLogUnrelatedPath = {
Expand All @@ -132,33 +132,33 @@ describe('SarifParser tests', () => {
{
tool: {
driver: {
name: 'TestAnalyzer'
}
name: 'TestAnalyzer',
},
},
results: [
{
ruleId: 'TEST005',
level: 'warning',
message: {
text: 'Warning with unrelated path'
text: 'Warning with unrelated path',
},
locations: [
{
physicalLocation: {
artifactLocation: {
uri: '/usr/share/test/Unrelated.cs'
uri: '/usr/share/test/Unrelated.cs',
},
region: {
startLine: 15,
startColumn: 3
}
}
}
]
}
]
}
]
startColumn: 3,
},
},
},
],
},
],
},
],
};

it('Should parse basic SARIF log correctly', () => {
Expand Down Expand Up @@ -214,12 +214,12 @@ describe('SarifParser tests', () => {
{
tool: {
driver: {
name: 'TestAnalyzer'
}
name: 'TestAnalyzer',
},
},
results: []
}
]
results: [],
},
],
};
const result = new SarifParser(cwdWin).parse(JSON.stringify(emptyLog));
expect(result).toHaveLength(0);
Expand All @@ -234,7 +234,9 @@ describe('SarifParser tests', () => {
version: '2.1.0',
// missing runs array
};
expect(() => new SarifParser(cwdWin).parse(JSON.stringify(invalidLog))).toThrowError();
expect(() =>
new SarifParser(cwdWin).parse(JSON.stringify(invalidLog)),
).toThrowError();
});

it('Should handle missing severity level and default to warning', () => {
Expand All @@ -244,35 +246,35 @@ describe('SarifParser tests', () => {
{
tool: {
driver: {
name: 'TestAnalyzer'
}
name: 'TestAnalyzer',
},
},
results: [
{
ruleId: 'TEST006',
message: {
text: 'Message with no severity level'
text: 'Message with no severity level',
},
locations: [
{
physicalLocation: {
artifactLocation: {
uri: 'C:\\source\\Test.cs'
uri: 'C:\\source\\Test.cs',
},
region: {
startLine: 1,
startColumn: 1
}
}
}
]
}
]
}
]
startColumn: 1,
},
},
},
],
},
],
},
],
};
const result = new SarifParser(cwdWin).parse(JSON.stringify(logWithNoLevel));
expect(result).toHaveLength(1);
expect(result[0].severity).toBe(LintSeverity.warning);
});
});
});
Loading

0 comments on commit c762648

Please sign in to comment.