Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
xShteff committed Feb 27, 2024
1 parent 424a553 commit 7fba574
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
18 changes: 11 additions & 7 deletions src/annotations/createCoverageAnnotations.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { relative } from 'path';

import { Annotation } from './Annotation';
import { CoverageAnnotationType } from '../typings/CoverageAnnotationType';
import { JsonReport, Location } from '../typings/JsonReport';
import { i18n } from '../utils/i18n';
import { isValidNumber } from '../utils/isValidNumber';
import { Annotation } from './Annotation';

const getLocation = (
start: Location = { line: 0 },
Expand Down Expand Up @@ -32,7 +32,11 @@ export const createCoverageAnnotations = (
const annotations: Partial<Annotation>[] = [];

if (annotationFilters.length === 0) {
annotationFilters = [CoverageAnnotationType.Branch, CoverageAnnotationType.Function, CoverageAnnotationType.Statement];
annotationFilters = [
CoverageAnnotationType.Branch,
CoverageAnnotationType.Function,
CoverageAnnotationType.Statement,
];
}

Object.entries(jsonReport.coverageMap).forEach(
Expand Down Expand Up @@ -60,9 +64,8 @@ export const createCoverageAnnotations = (
}
);
}


if (annotationFilters.includes(CoverageAnnotationType.Branch)) {
if (annotationFilters.includes(CoverageAnnotationType.Branch)) {
Object.entries(normalizedFileCoverage.branchMap).forEach(
([branchIndex, branchCoverage]) => {
if (branchCoverage.locations) {
Expand All @@ -80,7 +83,9 @@ export const createCoverageAnnotations = (
),
path: normalizedFilename,
annotation_level: 'warning',
title: i18n('notCoveredBranchTitle'),
title: i18n(
'notCoveredBranchTitle'
),
message: i18n(
'notCoveredBranchMessage'
),
Expand All @@ -93,7 +98,7 @@ export const createCoverageAnnotations = (
);
}

if (annotationFilters.includes(CoverageAnnotationType.Function)) {
if (annotationFilters.includes(CoverageAnnotationType.Function)) {
Object.entries(normalizedFileCoverage.fnMap).forEach(
([functionIndex, functionCoverage]) => {
if (normalizedFileCoverage.f[+functionIndex] === 0) {
Expand All @@ -111,7 +116,6 @@ export const createCoverageAnnotations = (
}
);
}

}
);

Expand Down
7 changes: 5 additions & 2 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './stages/switchBranch';
import { JsonReport } from './typings/JsonReport';
import { getOptions } from './typings/Options';
import { DataCollector, createDataCollector } from './utils/DataCollector';
import { createDataCollector, DataCollector } from './utils/DataCollector';
import { getNormalThreshold } from './utils/getNormalThreshold';
import { getPrPatch } from './utils/getPrPatch';
import { i18n } from './utils/i18n';
Expand Down Expand Up @@ -246,7 +246,10 @@ export const run = async (
skip();
}

let coverageAnnotations = createCoverageAnnotations(headCoverage!, options.annotationFilters || []);
let coverageAnnotations = createCoverageAnnotations(
headCoverage!,
options.annotationFilters || []
);

if (coverageAnnotations.length === 0) {
skip();
Expand Down
2 changes: 1 addition & 1 deletion src/typings/CoverageAnnotationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export enum CoverageAnnotationType {
Statement = 'statement',
Branch = 'branch',
Function = 'function',
}
}
6 changes: 4 additions & 2 deletions src/typings/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { getInput } from '@actions/core';
import { context, getOctokit } from '@actions/github';
import * as yup from 'yup';

import { icons } from '../format/strings.json';
import { CoverageAnnotationType } from './CoverageAnnotationType';
import { icons } from '../format/strings.json';

export type IconType = keyof typeof icons;

Expand Down Expand Up @@ -91,7 +91,9 @@ const optionSchema = yup.object().shape({
.required()
.transform((_, originalValue: string) => originalValue.split(', '))
.of(yup.string().required().oneOf(validOutputTypeOptions)),
annotationFilters: yup.string().transform((value: string) => value.split(','))
annotationFilters: yup
.string()
.transform((value: string) => value.split(',')),
});

export const shouldInstallDeps = (skipStep: SkipStepType): Boolean =>
Expand Down
23 changes: 19 additions & 4 deletions tests/annotations/createCoverageAnnotations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@ describe('createCoverageAnnotations', () => {
(_, second) => second
);

expect(createCoverageAnnotations(jsonReport, [CoverageAnnotationType.Branch, CoverageAnnotationType.Function, CoverageAnnotationType.Statement])).toMatchSnapshot();
expect(
createCoverageAnnotations(jsonReport, [
CoverageAnnotationType.Branch,
CoverageAnnotationType.Function,
CoverageAnnotationType.Statement,
])
).toMatchSnapshot();

expect(
createCoverageAnnotations((jsonReport2 as unknown) as JsonReport, [CoverageAnnotationType.Branch, CoverageAnnotationType.Function, CoverageAnnotationType.Statement])
createCoverageAnnotations((jsonReport2 as unknown) as JsonReport, [
CoverageAnnotationType.Branch,
CoverageAnnotationType.Function,
CoverageAnnotationType.Statement,
])
).toMatchSnapshot();

expect(
createCoverageAnnotations((jsonReport3 as unknown) as JsonReport, [])
createCoverageAnnotations(
(jsonReport3 as unknown) as JsonReport,
[]
)
).toMatchSnapshot();

expect(
createCoverageAnnotations((jsonReport4 as unknown) as JsonReport, [CoverageAnnotationType.Function])
createCoverageAnnotations((jsonReport4 as unknown) as JsonReport, [
CoverageAnnotationType.Function,
])
).toMatchSnapshot();

(relative as jest.Mock<any, any>).mockClear();
Expand Down

0 comments on commit 7fba574

Please sign in to comment.