Skip to content

Commit 4760b72

Browse files
authored
ci: Add TypeScript type checking to CI (#747)
## Summary - Fix all 215 TypeScript type errors across the codebase - Add `pnpm typecheck` step to the lint CI workflow - Enable incremental TypeScript compilation for faster CI runs - Fix all ESLint warnings ## Changes **Dependencies:** - Added `@types/semver` and `tslib` dev dependencies **Type Fixes:** - Added `TypedTargetConfig<T>` utility type for strongly-typed target configs - Fixed type issues in 16 target files, utilities, and ~40 test files - Cleaned up unused imports across the test suite **CI:** - Added type checking step before lint in `.github/workflows/lint.yml` - Enabled incremental TS compilation with `.tsbuildinfo` caching **Lint:** - Removed unused eslint-disable directives - Modernized catch blocks to use `catch {}` pattern - Fixed type-only class exports in mustache.d.ts
1 parent 6816252 commit 4760b72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1647
-1275
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ jobs:
2828
path: |
2929
node_modules
3030
.eslintcache
31+
.tsbuildinfo
3132
key: ${{ runner.os }}-${{ hashFiles('package.json', 'pnpm-lock.yaml') }}
3233
- name: Install Dependencies
3334
if: steps.cache.outputs.cache-hit != 'true'
3435
run: pnpm install --frozen-lockfile
36+
- name: Type Check
37+
run: pnpm typecheck
3538
- name: Lint
3639
run: pnpm lint -f github-annotations

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ npm-debug.log
1616
.Trashes
1717
*.env
1818
.eslintcache
19+
.tsbuildinfo
1920
.idea

eslint.config.mjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import prettier from 'eslint-config-prettier';
44

55
export default tseslint.config(
66
{
7-
ignores: ['docs/**', 'dist/**', 'node_modules/**', 'coverage/**', '*.mjs', '**/*.js'],
7+
ignores: [
8+
'docs/**',
9+
'dist/**',
10+
'node_modules/**',
11+
'coverage/**',
12+
'*.mjs',
13+
'**/*.js',
14+
],
815
},
916
eslint.configs.recommended,
1017
...tseslint.configs.recommended,
@@ -18,7 +25,10 @@ export default tseslint.config(
1825
'@typescript-eslint/no-explicit-any': 'off',
1926
'no-constant-condition': ['error', { checkLoops: false }],
2027
// Make sure variables marked with _ are ignored (ex. _varName)
21-
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
28+
'@typescript-eslint/no-unused-vars': [
29+
'warn',
30+
{ argsIgnorePattern: '^_' },
31+
],
2232
'@typescript-eslint/ban-ts-comment': [
2333
'error',
2434
{
@@ -47,5 +57,5 @@ export default tseslint.config(
4757
},
4858
],
4959
},
50-
}
60+
},
5161
);

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@types/ora": "^1.3.4",
3434
"@types/prompts": "^2.0.11",
3535
"@types/rimraf": "^2.0.2",
36+
"@types/semver": "^7.7.1",
3637
"@types/shell-quote": "^1.6.0",
3738
"@types/tar": "^4.0.0",
3839
"@types/tmp": "^0.0.33",
@@ -68,6 +69,7 @@
6869
"string-length": "3.1.0",
6970
"tar": "7.5.7",
7071
"tmp": "0.2.4",
72+
"tslib": "^2.8.1",
7173
"typescript": "^5.7.2",
7274
"typescript-eslint": "^8.18.2",
7375
"vitest": "^3.0.2",

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__mocks__/fs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { vi } from 'vitest';
22

33
// Import the actual fs module using require to avoid circular mock issues
4-
// eslint-disable-next-line @typescript-eslint/no-require-imports
54
const actualFs = require('fs') as typeof import('fs');
65

76
// Mock existsSync to return true by default
@@ -104,4 +103,4 @@ export const readv = actualFs.readv;
104103
export default {
105104
...actualFs,
106105
existsSync,
107-
};
106+
} as typeof actualFs;

src/__tests__/prepare-dry-run.e2e.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { resolve, join } from 'path';
1313
import { mkdtemp, rm, writeFile, readFile, mkdir, chmod } from 'fs/promises';
1414
import { existsSync } from 'fs';
1515
import { tmpdir } from 'os';
16-
// eslint-disable-next-line no-restricted-imports, no-restricted-syntax -- Test file needs direct git access for setup/verification
1716
import simpleGit from 'simple-git';
1817

1918
const execFileAsync = promisify(execFile);

src/artifact_providers/__tests__/base.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { vi, type Mock, type MockInstance, type Mocked, type MockedFunction } from 'vitest';
21
import { parseFilterOptions, RawFilterOptions } from '../base';
32

43
describe('parseFilterOptions', () => {
@@ -29,12 +28,12 @@ describe('parseFilterOptions', () => {
2928
const parsedFilters = parseFilterOptions(rawFilters);
3029

3130
expect(parsedFilters.includeNames).toStrictEqual(
32-
includeNames && /include/
31+
includeNames && /include/,
3332
);
3433

3534
expect(parsedFilters.excludeNames).toStrictEqual(
36-
excludeNames && /exclude/
35+
excludeNames && /exclude/,
3736
);
38-
}
37+
},
3938
);
4039
});

src/commands/__tests__/prepare.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { vi, describe, test, expect, beforeEach, type Mock } from 'vitest';
2-
import { join as pathJoin } from 'path';
32
import { spawnProcess } from '../../utils/system';
43
import { runPreReleaseCommand, checkVersionOrPart } from '../prepare';
54

@@ -34,7 +33,7 @@ describe('runPreReleaseCommand', () => {
3433
CRAFT_NEW_VERSION: newVersion,
3534
CRAFT_OLD_VERSION: oldVersion,
3635
},
37-
}
36+
},
3837
);
3938
});
4039

@@ -57,7 +56,7 @@ describe('runPreReleaseCommand', () => {
5756
CRAFT_NEW_VERSION: newVersion,
5857
CRAFT_OLD_VERSION: oldVersion,
5958
},
60-
}
59+
},
6160
);
6261
});
6362
});
@@ -71,8 +70,8 @@ describe('checkVersionOrPart', () => {
7170
{
7271
newVersion: v,
7372
},
74-
null
75-
)
73+
null,
74+
),
7675
).toBe(true);
7776
}
7877
});
@@ -83,8 +82,8 @@ describe('checkVersionOrPart', () => {
8382
{
8483
newVersion: 'auto',
8584
},
86-
null
87-
)
85+
null,
86+
),
8887
).toBe(true);
8988
});
9089

@@ -96,8 +95,8 @@ describe('checkVersionOrPart', () => {
9695
{
9796
newVersion: bumpType,
9897
},
99-
null
100-
)
98+
null,
99+
),
101100
).toBe(true);
102101
}
103102
});
@@ -110,8 +109,7 @@ describe('checkVersionOrPart', () => {
110109
},
111110
{
112111
v: 'v2.3.3',
113-
e:
114-
'Invalid version or version part specified: "v2.3.3". Removing the "v" prefix will likely fix the issue',
112+
e: 'Invalid version or version part specified: "v2.3.3". Removing the "v" prefix will likely fix the issue',
115113
},
116114
];
117115
for (const t of invalidVersions) {
@@ -120,7 +118,7 @@ describe('checkVersionOrPart', () => {
120118
{
121119
newVersion: t.v,
122120
},
123-
null
121+
null,
124122
);
125123
};
126124
expect(fn).toThrow(t.e);

src/commands/publish.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,9 @@ export async function publishMain(argv: PublishOptions): Promise<any> {
637637
// finishes then as nothing relies on the removal of this file.
638638
safeFs
639639
.unlink(publishStateFile)
640-
.catch(err => logger.trace("Couldn't remove publish state file: ", err));
640+
.catch((err: unknown) =>
641+
logger.trace("Couldn't remove publish state file: ", err),
642+
);
641643
logger.success(`Version ${newVersion} has been published!`);
642644
} else {
643645
const msg = [

0 commit comments

Comments
 (0)