Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 4819a2f

Browse files
committed
Include JS files in TypeScript build
1 parent 5ac9408 commit 4819a2f

File tree

16 files changed

+120
-41
lines changed

16 files changed

+120
-41
lines changed

.eslintrc-ts.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2022-2023 Developer Innovations, LLC
2+
3+
module.exports = {
4+
extends: [
5+
"plugin:@typescript-eslint/recommended",
6+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
7+
"plugin:import/typescript",
8+
],
9+
parser: "@typescript-eslint/parser",
10+
parserOptions: {
11+
// Find the tsconfig.json nearest each source file.
12+
project: true,
13+
},
14+
plugins: ["@typescript-eslint"],
15+
rules: {
16+
"@typescript-eslint/explicit-function-return-type": ["error"],
17+
"@typescript-eslint/explicit-module-boundary-types": ["error"],
18+
"@typescript-eslint/no-unused-expressions": ["error"],
19+
"@typescript-eslint/no-unused-vars": [
20+
"error",
21+
{
22+
argsIgnorePattern: "^_",
23+
caughtErrorsIgnorePattern: "^_",
24+
varsIgnorePattern: "^_",
25+
},
26+
],
27+
"@typescript-eslint/no-use-before-define": ["error", { functions: false }],
28+
"@typescript-eslint/strict-boolean-expressions": [
29+
"error",
30+
{
31+
allowString: false,
32+
allowNumber: false,
33+
allowNullableObject: false,
34+
},
35+
],
36+
"@typescript-eslint/switch-exhaustiveness-check": ["error"],
37+
},
38+
overrides: [
39+
{
40+
files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
41+
rules: {
42+
// JS files don't have explicit types, and this lint rule fails even if they have doc
43+
// comment type annotations.
44+
"@typescript-eslint/explicit-function-return-type": "off",
45+
"@typescript-eslint/explicit-module-boundary-types": "off",
46+
// Allow require() in JS files (most of which are CommonJS, not ESM).
47+
"@typescript-eslint/no-var-requires": "off",
48+
},
49+
},
50+
],
51+
settings: {
52+
"import/resolver": {
53+
typescript: true,
54+
},
55+
},
56+
};

.eslintrc.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,34 @@ module.exports = {
66
},
77
extends: [
88
"eslint:recommended",
9-
"plugin:@typescript-eslint/recommended",
10-
"plugin:@typescript-eslint/recommended-requiring-type-checking",
119
"plugin:import/errors",
1210
"plugin:import/warnings",
13-
"plugin:import/typescript",
1411
],
15-
parser: "@typescript-eslint/parser",
1612
parserOptions: {
17-
// Find the tsconfig.json nearest each source file.
18-
project: true,
13+
// Support `??` operator.
14+
ecmaVersion: 2020,
1915
},
20-
plugins: ["@typescript-eslint", "import"],
16+
plugins: ["import"],
2117
root: true,
2218
rules: {
2319
curly: ["error", "all"],
2420
eqeqeq: ["error", "always"],
2521
"no-implicit-coercion": ["error"],
2622
// https://github.com/eslint/eslint/blob/master/docs/rules/no-sequences.md#when-not-to-use-it
2723
"no-restricted-syntax": ["error", "SequenceExpression"],
28-
"prefer-const": ["error", { destructuring: "all" }],
29-
"require-await": ["error"],
30-
"@typescript-eslint/explicit-function-return-type": ["error"],
31-
"@typescript-eslint/explicit-module-boundary-types": ["error"],
32-
"@typescript-eslint/no-unused-expressions": ["error"],
33-
"@typescript-eslint/no-unused-vars": [
24+
"no-unused-vars": [
3425
"error",
3526
{
3627
argsIgnorePattern: "^_",
3728
caughtErrorsIgnorePattern: "^_",
3829
varsIgnorePattern: "^_",
3930
},
4031
],
41-
"@typescript-eslint/no-use-before-define": ["error", { functions: false }],
42-
"@typescript-eslint/strict-boolean-expressions": [
43-
"error",
44-
{
45-
allowString: false,
46-
allowNumber: false,
47-
allowNullableObject: false,
48-
},
49-
],
50-
"@typescript-eslint/switch-exhaustiveness-check": ["error"],
32+
"prefer-const": ["error", { destructuring: "all" }],
33+
"require-await": ["error"],
5134
},
5235
settings: {
5336
"import/resolver": {
54-
typescript: true,
5537
node: true,
5638
},
5739
},

packages/jest-plugin/.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright (c) 2023 Developer Innovations, LLC
22

33
module.exports = {
4+
extends: ["../../.eslintrc-ts.js"],
45
overrides: [
56
{
67
// Disable some rules that fail for vendored Jest code. If we fix these, it'll be harder to
78
// merge upstream changes.
8-
files: ["src/vendored/**/*.ts"],
9+
files: ["src/vendored/**"],
910
rules: {
1011
"@typescript-eslint/no-inferrable-types": "off",
1112
"@typescript-eslint/no-unsafe-member-access": "off",

packages/jest-plugin/rollup.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export default {
3030
"@unflakable/js-api/consts",
3131
"@unflakable/plugins-common",
3232
].includes(id),
33+
// Unclear why this is necessary.
34+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3335
plugins: [
3436
pluginCommonJs(),
3537
pluginJson(),

packages/jest-plugin/test/integration-input/tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@
55
// Some versions of Jest (e.g., 28.0.0) have internally broken types.
66
"skipLibCheck": true
77
},
8-
"include": [
9-
"src/**/*.ts"
10-
]
8+
"include": ["jest.config.js", "src"]
119
}

packages/jest-plugin/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@
1515
"skipLibCheck": true,
1616
"sourceMap": true
1717
},
18-
"include": ["src/**/*.ts", "window.d.ts"]
18+
"include": [
19+
".eslintrc.js",
20+
"src",
21+
"test/.eslintrc.js",
22+
"rollup.config.mjs",
23+
"window.d.ts"
24+
]
1925
}

packages/js-api/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2023 Developer Innovations, LLC
2+
3+
module.exports = {
4+
extends: ["../../.eslintrc-ts.js"],
5+
};

packages/js-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@types/node-fetch": "^2.6.2"
2626
},
2727
"scripts": {
28-
"build": "tsc --build",
28+
"build": "rm -rf dist && tsc --noEmit && tsc -p src",
2929
"build:watch": "tsc --build --watch"
3030
}
3131
}

packages/js-api/src/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../dist/",
5+
"declaration": true,
6+
// Removes DOM types.
7+
"lib": ["ES2019"],
8+
// Avoids conflicting global definitions from, e.g., jasmine.
9+
"types": ["node"]
10+
},
11+
"include": ["."]
12+
}

packages/js-api/tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "dist/",
5-
"declaration": true,
64
// Removes DOM types.
75
"lib": ["ES2019"],
86
// Avoids conflicting global definitions from, e.g., jasmine.
97
"types": ["node"]
108
},
11-
"include": ["src/**/*.ts"]
9+
"include": [".eslintrc.js"]
1210
}

0 commit comments

Comments
 (0)