Skip to content

Commit

Permalink
Use stricter ESLint config
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis committed Mar 27, 2024
1 parent a875d67 commit 5d5aff5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
8 changes: 4 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37689,10 +37689,10 @@ async function runGit(command) {
ok(collected.join(''));
});
run.on('error', (err) => {
fail(`got error from rungit "${err.message}" ${err.stack}
fail(new Error(`got error from rungit "${err.message}" ${err.stack}

stderr:
${errors.join('')}`);
${errors.join('')}`, { cause: err }));
});
});
}
Expand All @@ -37702,7 +37702,7 @@ async function changedLines(opts) {
let currentFile = null;
for (const line of stdout.split('\n')) {
const fileHeader = line.match(/^\+\+\+ b\/(.*)/);
if (fileHeader && fileHeader[1]) {
if (fileHeader?.[1]) {
currentFile = fileHeader[1];
result[currentFile] = new (lib_default())();
continue;
Expand Down Expand Up @@ -37834,7 +37834,7 @@ async function uncoveredLines(opts) {
async function run(opts) {
const file = opts.coverage;
if (opts.coverageFormat === 'istanbul') {
external_node_assert_default()(/\.json$/.test(file), `input file '${file}' must be json coverage file`);
external_node_assert_default()(file.endsWith('.json'), `input file '${file}' must be json coverage file`);
}
return await uncoveredLines({
base: opts.base,
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import tseslint from 'typescript-eslint';
export default tseslint.config(
// Global ignores
{
ignores: ['dist/*', 'eslint.config.js', 'jest.config.js']
ignores: ['dist/*']
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
...tseslint.configs.strictTypeChecked,
{
languageOptions: {
parserOptions: {
Expand All @@ -17,7 +20,7 @@ export default tseslint.config(
}
},
{
files: ['{src,test,test-fixture}/**/*.{ts,tsx,cts,mts}', 'test.ts'],
files: ['{src,test,test-fixture}/**/*.{ts,tsx,cts,mts}'],
rules: {
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
Expand All @@ -26,11 +29,12 @@ export default tseslint.config(
}
},
{
files: ['test-fixture/**/*.{ts,tsx,cts,mts}', 'test-fixture/jest.config.js', 'test.ts'],
files: ['test-fixture/**/*.{ts,tsx,cts,mts,js}'],
rules: {
'no-undef': 'off',
'no-constant-condition': 'off',
'@typescript-eslint/no-explicit-any': 'off'
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off'
}
}
);
35 changes: 22 additions & 13 deletions src/covered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { default as cobertura } from '@cvrg-report/cobertura-json';

export type CoverageFormat = 'lcov' | 'istanbul' | 'cobertura';

type Opts = {
interface Opts {
base: string;
coverage: string;
head: string;
coverageFormat: CoverageFormat;
};
}

export type Lines = Range;
export type Path = string;
Expand All @@ -34,20 +34,25 @@ async function runGit(command: string): Promise<string> {
ok(collected.join(''));
});
run.on('error', (err: Error) => {
fail(`got error from rungit "${err.message}" ${err.stack}
fail(
new Error(
`got error from rungit "${err.message}" ${err.stack}
stderr:
${errors.join('')}`);
${errors.join('')}`,
{ cause: err }
)
);
});
});
}
async function changedLines(opts: Opts): Promise<Record<Path, Lines>> {
async function changedLines(opts: Opts): Promise<Record<Path, Lines | undefined>> {
const stdout = await runGit(`git diff -w -U0 ${opts.base}...${opts.head}`);
const result: Record<Path, Lines> = {};
const result: Record<Path, Lines | undefined> = {};
let currentFile: Path | null = null;
for (const line of stdout.split('\n')) {
const fileHeader = line.match(/^\+\+\+ b\/(.*)/);
if (fileHeader && fileHeader[1]) {
if (fileHeader?.[1]) {
currentFile = fileHeader[1];
result[currentFile] = new Range();
continue;
Expand All @@ -71,8 +76,8 @@ async function changedLines(opts: Opts): Promise<Record<Path, Lines>> {
}

export function uncovered(args: {
coverage: Record<Path, Hits>;
changes: Record<Path, Lines>;
coverage: Record<Path, Hits | undefined>;
changes: Record<Path, Lines | undefined>;
}): Result {
const result: Record<Path, Lines> = {};
let coveredChanges = 0;
Expand Down Expand Up @@ -119,11 +124,11 @@ export function uncovered(args: {
};
}

type Hits = Array<{
type Hits = {
hits: number;
start: number;
end: number;
}>;
}[];
async function coveredLines(opts: Opts): Promise<Record<Path, Hits>> {
switch (opts.coverageFormat) {
case 'lcov':
Expand Down Expand Up @@ -190,7 +195,11 @@ async function coberturaCoveredLines(opts: Opts): Promise<Record<Path, Hits>> {
);
}

export type Result = { covered: number; total: number; uncoveredLines: Record<Path, Range> };
export interface Result {
covered: number;
total: number;
uncoveredLines: Record<Path, Range>;
}
async function uncoveredLines(opts: Opts): Promise<Result> {
const coverage = await coveredLines(opts);
const changes = await changedLines(opts);
Expand All @@ -200,7 +209,7 @@ async function uncoveredLines(opts: Opts): Promise<Result> {
export async function run(opts: Opts): Promise<Result> {
const file = opts.coverage;
if (opts.coverageFormat === 'istanbul') {
assert(/\.json$/.test(file), `input file '${file}' must be json coverage file`);
assert(file.endsWith('.json'), `input file '${file}' must be json coverage file`);
}

return await uncoveredLines({
Expand Down

0 comments on commit 5d5aff5

Please sign in to comment.