Skip to content

Commit

Permalink
Merge pull request #30 from smartlyio/simplify-configs
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis authored Apr 4, 2024
2 parents 9d2a1c1 + 5d5aff5 commit 8c7cc0c
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 83 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/check-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ name: Check Labels
on:
pull_request:
branches:
- master
- master
types:
- opened
- labeled
- unlabeled
- synchronize
- opened
- labeled
- unlabeled
- synchronize

jobs:
check_labels:
runs-on: ubuntu-latest
steps:
- uses: smartlyio/check-versioning-action@v5
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: smartlyio/check-versioning-action@v5
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
uses: smartlyio/github-actions@release-action-node-v1
with:
dry_run: true
token: "${{ secrets.GITHUB_TOKEN }}"
token: '${{ secrets.GITHUB_TOKEN }}'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
- name: Release flow
uses: smartlyio/github-actions@release-action-node-v1
with:
token: "${{ secrets.GITHUB_TOKEN }}"
token: '${{ secrets.GITHUB_TOKEN }}'
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
package-lock.json
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"parser": "typescript",
"printWidth": 100,
"singleQuote": true,
"trailingComma": "none",
Expand Down
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.

26 changes: 0 additions & 26 deletions dist/src/covered.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/src/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/test/test.spec.d.ts

This file was deleted.

27 changes: 12 additions & 15 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,37 @@ 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: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
tsconfigRootDir: import.meta.dirname
}
}
},
{
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',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/restrict-template-expressions': 'off'
}
},
{
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-unnecessary-condition': 'off'
}
},
}
);
9 changes: 3 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
export default {
extensionsToTreatAsEsm: [".ts", ".tsx", ".mts"],
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
transform: {
"^.+\\.m?[tj]sx?$": [
"ts-jest",
{ useESM: true, isolatedModules: true, diagnostics: false },
],
},
'^.+\\.m?[tj]sx?$': ['ts-jest', { useESM: true, isolatedModules: true, diagnostics: false }]
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"lint": "eslint -c eslint.config.js .",
"fixture:pack": "rm -f fixture.tgz && rm -rf test-fixture/node_modules && rm -rf test-fixture/coverage && tar czf fixture.tgz test-fixture",
"fixture:setup": "rm -rf test-fixture && tar xzf fixture.tgz && npm -C test-fixture install && npm -C test-fixture test -c jest.config.js -- --coverage",
"format": "prettier --write src",
"format:check": "prettier --check src",
"format": "prettier --write .",
"format:check": "prettier --check .",
"clean": "rm -rf dist",
"prebundle": "npm run clean",
"bundle": "ncc build src/index.ts --source-map --license licenses.txt --target es2022",
Expand Down
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
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"strict": true,
"declaration": true,
"declaration": false,
"sourceMap": true,
"module": "ESNext",
"lib": ["es2023"],
Expand All @@ -11,6 +11,5 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist"
},
"include": ["src/**/*", "test/**/*", "test-fixture/**/*"],
}
}

0 comments on commit 8c7cc0c

Please sign in to comment.