Skip to content

Commit ce35a98

Browse files
committed
custom script
1 parent 7daaaa4 commit ce35a98

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

.github/workflows/validate.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Check format
5656
run: npm run check-format
5757

58-
check-types-this-is-only-warning-fixing-is-not-required:
58+
type-warnings:
5959
runs-on: ubuntu-latest
6060
steps:
6161
- name: Checkout
@@ -69,6 +69,6 @@ jobs:
6969
cache: npm
7070
- name: Install dependencies
7171
run: npm ci
72-
- name: Check types (This is only warning, fixing is not required)
72+
- name: Check types
7373
continue-on-error: true
7474
run: npm run check-types
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import pathUtil from 'node:path';
2+
import ts from 'typescript';
3+
4+
/**
5+
* @fileoverview
6+
* tsc command output will be parsed by GitHub Actions as errors.
7+
* We want them to be just warnings.
8+
*/
9+
10+
const check = () => {
11+
const rootDir = pathUtil.join(import.meta.dirname, '..');
12+
13+
const tsconfigPath = pathUtil.join(rootDir, 'tsconfig.json');
14+
const commandLine = ts.getParsedCommandLineOfConfigFile(tsconfigPath, {}, ts.sys);
15+
16+
const program = ts.createProgram({
17+
rootNames: commandLine.fileNames,
18+
options: commandLine.options
19+
});
20+
const emitted = program.emit();
21+
22+
const diagnostics = [
23+
...ts.getPreEmitDiagnostics(program),
24+
...emitted.diagnostics
25+
];
26+
27+
let numWarnings = 0;
28+
29+
for (const diagnostic of diagnostics) {
30+
// https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands
31+
const relativeFileName = pathUtil.relative(rootDir, diagnostic.file.fileName);
32+
let prefix = `::warning file=${relativeFileName}`;
33+
34+
const startPosition = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
35+
const endPosition = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
36+
prefix += `,line=${startPosition.line + 1},col=${startPosition.character + 1}`;
37+
prefix += `,endLine=${endPosition.line + 1},endCol=${endPosition.character + 1}`;
38+
39+
prefix += ",title=Type warning - may indicate a bug. No action required if no bug.::";
40+
41+
let messageText = diagnostic.messageText;
42+
while (messageText) {
43+
numWarnings++;
44+
45+
if (typeof messageText === 'string') {
46+
console.log(prefix + messageText);
47+
messageText = null;
48+
} else {
49+
console.log(prefix + messageText.messageText);
50+
messageText = messageText.next;
51+
}
52+
}
53+
}
54+
55+
console.log(`${numWarnings} warnings.`);
56+
};
57+
58+
check();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"check-format": "prettier . --check",
1717
"upload-translations": "node development/upload-translations.js",
1818
"download-translations": "node development/download-translations.js",
19-
"check-types": "tsc"
19+
"check-types": "node development/check-extension-types.js"
2020
},
2121
"repository": {
2222
"type": "git",

0 commit comments

Comments
 (0)