Skip to content

Commit 44b7b85

Browse files
authored
Convert the entire codebase to TypeScript (#5549)
FIxes #2931. [717 files changed, 13586 insertions(+), 64498 deletions(-)](https://gist.github.com/mstange/ed98002f852ba6f3e5979bae9cc6571c)
2 parents 927870f + fe67997 commit 44b7b85

File tree

1,202 files changed

+179015
-229927
lines changed

Some content is hidden

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

1,202 files changed

+179015
-229927
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ jobs:
6262
- checkout-and-dependencies
6363
- run: yarn license-check
6464

65-
flow:
65+
typecheck:
6666
executor: node
6767
resource_class: large
6868
steps:
6969
- checkout-and-dependencies
70-
- run: yarn flow:ci
70+
- run: yarn ts
7171

7272
alex:
7373
executor: node
@@ -110,7 +110,7 @@ workflows:
110110
- tests
111111
- lint
112112
- build-prod
113-
- flow
113+
- typecheck
114114
- licence-check
115115
- alex
116116
- yarn_lock

.eslintrc.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
// @flow
21
module.exports = {
32
env: {
43
browser: true,
54
es6: true,
65
es2020: true,
76
node: true,
87
},
9-
parser: '@babel/eslint-parser',
10-
plugins: ['@babel', 'react', 'flowtype', 'import'],
8+
parser: '@typescript-eslint/parser',
9+
plugins: ['@babel', '@typescript-eslint', 'react', 'import'],
1110
extends: [
1211
'eslint:recommended',
12+
'plugin:@typescript-eslint/recommended',
1313
'plugin:react/recommended',
14-
'plugin:flowtype/recommended',
1514
'prettier',
1615
],
1716
parserOptions: {
18-
ecmaVersion: '2017',
17+
ecmaVersion: '2022',
1918
ecmaFeatures: {
2019
experimentalObjectRestSpread: true,
2120
jsx: true,
@@ -37,8 +36,7 @@ module.exports = {
3736
'react/no-unused-class-component-methods': 'error',
3837
'react/no-this-in-sfc': 'error',
3938
'react/no-typos': 'error',
40-
// Flow provides enough coverage over the prop types, and there can be errors
41-
// with some of the more complicated Flow types.
39+
// TypeScript provides enough coverage over the prop types.
4240
'react/prop-types': 'off',
4341
'react/jsx-curly-brace-presence': [
4442
'error',
@@ -51,20 +49,10 @@ module.exports = {
5149
'react/no-unused-state': 'error',
5250
'react/jsx-no-bind': 'error',
5351
'react/jsx-no-leaked-render': 'error',
54-
'flowtype/require-valid-file-annotation': [
55-
'error',
56-
'always',
57-
{ annotationStyle: 'line' },
58-
],
59-
// no-dupe-keys crashes with recent eslint. See
60-
// https://github.com/gajus/eslint-plugin-flowtype/pull/266 and
61-
// https://github.com/gajus/eslint-plugin-flowtype/pull/302
62-
// 'flowtype/no-dupe-keys': 'error',
6352

6453
// overriding recommended rules
6554
'no-constant-condition': ['error', { checkLoops: false }],
6655
'no-console': ['error', { allow: ['log', 'warn', 'error'] }],
67-
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
6856

6957
// possible errors
7058
'array-callback-return': 'error',
@@ -88,21 +76,6 @@ module.exports = {
8876
'no-self-compare': 'error',
8977
'no-throw-literal': 'error',
9078
'no-unmodified-loop-condition': 'error',
91-
// We use the version from the flowtype plugin so that flow assertions don't
92-
// output an error.
93-
'flowtype/no-unused-expressions': 'error',
94-
// The Object type and Function type aren't particularly useful, and usually hide
95-
// type errors. It also blocks a migration to TypeScript. Disable this rule if
96-
// using the Object or Function as generic type bounds.
97-
'flowtype/no-weak-types': [
98-
'error',
99-
{
100-
any: false,
101-
Object: true,
102-
Function: true,
103-
},
104-
],
105-
'flowtype/no-existential-type': 'error',
10679
'no-useless-call': 'error',
10780
'no-useless-computed-key': 'error',
10881
'no-useless-concat': 'error',
@@ -118,6 +91,34 @@ module.exports = {
11891
'prefer-spread': 'error',
11992
'no-else-return': 'error',
12093
'no-nested-ternary': 'error',
94+
95+
// Use `import type` everywhere we can.
96+
'@typescript-eslint/consistent-type-imports': 'error',
97+
// Allow `as any` escape hatches
98+
'@typescript-eslint/no-explicit-any': 'off',
99+
// Disable a rule that the TypeScript FAQ disapproves of
100+
'@typescript-eslint/no-empty-object-type': 'off',
101+
// Should enable this soon, mostly finds `catch (e)` with unused e
102+
'@typescript-eslint/no-unused-vars': 'off',
103+
// TypeScript imports react-jsx into .tsx files for us
104+
'react/react-in-jsx-scope': 'off',
105+
// Allow @ts-expect-error annotations with descriptions.
106+
'@typescript-eslint/ban-ts-comment': [
107+
'error',
108+
{
109+
// Allow @ts-expect-error annotations with descriptions.
110+
'ts-expect-error': 'allow-with-description',
111+
// Don't allow @ts-ignore or @ts-nocheck because we want to be notified
112+
// when the error goes away so we can remove the annotation - use
113+
// @ts-expect-error instead
114+
'ts-ignore': true,
115+
'ts-nocheck': true,
116+
'ts-check': false, // allow even without description
117+
},
118+
],
119+
// TODO: Re-enable for src when we update to eslint and switch to the new
120+
// config format
121+
'@typescript-eslint/no-require-imports': 'off',
121122
},
122123
// This property is specified both here in addition to the command line in
123124
// package.json.
@@ -129,15 +130,14 @@ module.exports = {
129130
react: {
130131
pragma: 'React',
131132
version: '17.0',
132-
flowVersion: '0.96.0',
133133
},
134134
'import/resolver': {
135135
alias: {
136136
map: [
137137
['firefox-profiler', './src'],
138138
['firefox-profiler-res', './res'],
139139
],
140-
extensions: ['.js', '.jpg'],
140+
extensions: ['.js', '.ts', '.tsx', '.jpg'],
141141
},
142142
},
143143
},

.flowconfig

Lines changed: 0 additions & 17 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ flow-coverage
88
coverage
99
.eslintcache
1010
.prettiercache
11+
.tsbuildinfo
1112
webpack.local-config.js
1213
*.orig
1314
*.rej

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = function (config, serverConfig) {
5050
};
5151
```
5252

53-
[Flow](https://flow.org/) is used for type checking. VSCode users can install the ["Flow Language Support" extension](https://marketplace.visualstudio.com/items?itemName=flowtype.flow-for-vscode), and disable VSCode's built-in TypeScript extension in the workspace via the [setup instructions here](https://github.com/flow/flow-for-vscode#setup).
53+
This project uses [TypeScript](https://www.typescriptlang.org/).
5454

5555
## Using Gitpod
5656

@@ -87,7 +87,7 @@ When working on a new feature and code changes, it's important that things work
8787
- `yarn test-all` - Test all the things!
8888
- `yarn test` - Run the tests in [`./src/test/`](./src/test/).
8989
- `yarn lint` - Run prettier, stylelint, and eslint to check for correct code formatting.
90-
- `yarn flow` - Check the [Flow types](https://flow.org/) for correctness.
90+
- `yarn ts` - Check for TypeScript type correctness.
9191
- `yarn license-check` - Check the dependencies' licenses.
9292
- `git push` and `git commit`
9393
- We have [husky](https://www.npmjs.com/package/husky) installed to run automated checks when committing and pushing.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ yarn install
4141
yarn start
4242
```
4343

44-
[Flow](https://flow.org/) is used for type checking. VSCode users can install the ["Flow Language Support" extension](https://marketplace.visualstudio.com/items?itemName=flowtype.flow-for-vscode), and disable VSCode's built-in TypeScript extension in the workspace via the [setup instructions here](https://github.com/flow/flow-for-vscode#setup).
44+
This project uses [TypeScript](https://www.typescriptlang.org/).
4545

4646
You can also develop the Firefox Profiler online in a pre-configured development environment.
4747

__mocks__/copy-to-clipboard.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

__mocks__/copy-to-clipboard.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
module.exports = jest.fn() as (arg: string) => void;

__mocks__/gecko-profiler-demangle.js

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This module replaces the wasm-pack generated module 'gecko-profiler-demangle'
2+
// in our tests.
3+
// The reason for this replacement is the fact that wasm-pack (or rather,
4+
// wasm-bindgen), when targeting the browser + webpack, generates an ES6 module
5+
// that node cannot deal with. Most importantly, it uses the syntax
6+
// "import * as wasm from './gecko_profiler_demangle_bg';" in order to load
7+
// the wasm module, which is currently only supported by webpack.
8+
// The long-term path to make this work correctly is to wait for node to
9+
// support ES6 modules (and WASM as ES6 modules) natively [1]. It's possible
10+
// that in the medium term, wasm-bindgen will get support for outputting JS
11+
// files which work in both webpack and in node natively [2].
12+
// [1] https://medium.com/@giltayar/native-es-modules-in-nodejs-status-and-future-directions-part-i-ee5ea3001f71
13+
// [2] https://github.com/rustwasm/wasm-bindgen/issues/233
14+
15+
// There's only one exported function.
16+
// Do the simplest thing possible: no demangling.
17+
export function demangle_any(s: string): string {
18+
return s;
19+
}

0 commit comments

Comments
 (0)