Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Setup typescript in expensify-common & Migrate CONST, fastMerge, Device, Logger to Typescript #699

Merged
merged 28 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
91d752f
Install deps, change configuration, add scripts to package.json
blazejkustra May 17, 2024
3d910ce
Ignore dist
blazejkustra May 17, 2024
ddfc91e
Adjust prettier and eslint ignore files
blazejkustra May 17, 2024
b981ab4
Prepare eslint config
blazejkustra May 17, 2024
479c9cf
Prepare tsconfigs
blazejkustra May 17, 2024
243308a
Add prettier and typecheks workflows
blazejkustra May 17, 2024
e85751d
Migrate CONST
blazejkustra May 17, 2024
3914542
Add endlines
blazejkustra May 17, 2024
1334540
Fix basic eslint errors
blazejkustra May 17, 2024
d31f093
Fix rest of the eslint issues
blazejkustra May 17, 2024
eb6f98b
Run prettier
blazejkustra May 20, 2024
a5b8bb7
Add babel to tests to enable Typescript
blazejkustra May 20, 2024
1df5b90
Migrate Logger to TS
blazejkustra May 20, 2024
78b719e
Migrate Device to TS
blazejkustra May 20, 2024
d12063c
Remove Logger.d.ts
blazejkustra May 20, 2024
55933f5
Migrate fastMerge to TS
blazejkustra May 20, 2024
35b4683
Fix fastMerge types
blazejkustra May 20, 2024
2c983a1
Create missing index.ts file
blazejkustra May 20, 2024
cfc6b0a
Adjust after review
blazejkustra May 21, 2024
8516cd9
Merge branch 'main' into ts/configure-typescript
blazejkustra May 21, 2024
4bbd354
Add Error to Logger parameters type
blazejkustra May 21, 2024
fda1a9b
Merge branch 'main' into ts/configure-typescript
blazejkustra May 22, 2024
aab8898
Fix es/no-nullish-coalescing eslint rule
blazejkustra May 27, 2024
229b2f3
Remove return from a Logger constructor
blazejkustra May 27, 2024
a19fc65
Configure you-dont-need-lodash-underscore eslint plugin
blazejkustra May 27, 2024
5ad4e37
Add publish workflow from react-native-onyx
blazejkustra May 27, 2024
163f4e6
Ignore gpg and .tgz files
blazejkustra May 27, 2024
cfaa9f2
Update readme
blazejkustra May 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.d.ts
dist
node_modules
*.config.js
77 changes: 69 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,72 @@
module.exports = {
extends: ['expensify', 'prettier'],
rules: {
// Allow JSX to be written in any file ignoring the extension type
'react/jsx-filename-extension': 'off'
},
plugins: ['jest'],
env: {
"jest/globals": true
}
parser: '@typescript-eslint/parser',
overrides: [
{
files: ['*.js', '*.jsx'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
rules: {
// Allow JSX to be written in any file ignoring the extension type
'react/jsx-filename-extension': 'off',
'rulesdir/no-api-in-views': 'off',
'rulesdir/no-multiple-api-calls': 'off',
'rulesdir/prefer-import-module-contents': 'off',
'no-constructor-return': 'off',
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
},
},
{
files: ['*.ts', '*.tsx'],
extends: ['expensify', 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/stylistic', 'plugin:import/typescript', 'prettier', 'plugin:prettier/recommended'],
plugins: ['react', 'import', '@typescript-eslint'],
blazejkustra marked this conversation as resolved.
Show resolved Hide resolved
parserOptions: {
project: './tsconfig.json',
},
rules: {
'prefer-regex-literals': 'off',
'rulesdir/prefer-underscore-method': 'off',
'react/jsx-props-no-spreading': 'off',
'react/require-default-props': 'off',
'valid-jsdoc': 'off',
'es/no-optional-chaining': 'off',
'es/no-nullish-coalescing': 'off',
'react/jsx-filename-extension': ['error', {extensions: ['.tsx', '.jsx']}],
'import/no-unresolved': 'error',
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}],
'@typescript-eslint/consistent-type-imports': ['error', {prefer: 'type-imports'}],
'@typescript-eslint/consistent-type-exports': ['error', {fixMixedExportsWithInlineTypeSpecifier: false}],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/array-type': ['error', {default: 'array-simple'}],
'@typescript-eslint/consistent-type-definitions': 'off',
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
},
},
],
};
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ jobs:
- run: npm run lint
env:
CI: true

- name: Verify there's no Prettier diff
run: |
npm run prettier -- --loglevel silent
if ! git diff --name-only --exit-code; then
# shellcheck disable=SC2016
echo 'Error: Prettier diff detected! Please run `npm run prettier` and commit the changes.'
exit 1
fi
24 changes: 24 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: TypeScript Checks

on:
pull_request:
types: [opened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
cache: npm
cache-dependency-path: package-lock.json

- run: npm ci

- name: Type check with TypeScript
run: npm run typecheck
env:
CI: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ npm-debug.log
package.json-e
.DS_Store
*.swp
dist
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
package.json
package-lock.json
*.html
11 changes: 1 addition & 10 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
presets: [['@babel/preset-env', {targets: {node: 'current'}}], '@babel/preset-typescript'],
};
5 changes: 3 additions & 2 deletions lib/API.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default function API(network, args) {
* @param {String} commandName The name of the API command
*/
function requireParameters(parameterNames, parameters, commandName) {
// eslint-disable-next-line rulesdir/prefer-early-return
parameterNames.forEach((parameterName) => {
if (!_(parameters).has(parameterName) || parameters[parameterName] === null || parameters[parameterName] === undefined) {
const parametersCopy = _.clone(parameters);
Expand Down Expand Up @@ -823,7 +824,7 @@ export default function API(network, args) {
*
* @returns {APIDeferred}
*/
createAdminIssuedVirtualCard: function (parameters) {
createAdminIssuedVirtualCard(parameters) {
const commandName = 'Card_CreateAdminIssuedVirtualCard';
requireParameters(['cardTitle', 'assigneeEmail', 'cardLimit', 'cardLimitType', 'domainName'], parameters, commandName);
return performPOSTRequest(commandName, parameters);
Expand All @@ -842,7 +843,7 @@ export default function API(network, args) {
*
* @returns {APIDeferred}
*/
editAdminIssuedVirtualCard: function (parameters) {
editAdminIssuedVirtualCard(parameters) {
const commandName = 'Card_EditAdminIssuedVirtualCard';
requireParameters(['domainName', 'cardID', 'cardTitle', 'assigneeEmail', 'cardLimit', 'cardLimitType'], parameters, commandName);
return performPOSTRequest(commandName, parameters);
Expand Down
Loading
Loading