Skip to content

Commit

Permalink
[DDW-596] switch to SWC and latest eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikGuzei committed Apr 27, 2022
1 parent 889fbb6 commit e1a612b
Show file tree
Hide file tree
Showing 79 changed files with 1,188 additions and 1,370 deletions.
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@
"react/no-did-update-set-state": 1,
"react/sort-comp": 0,
"react/state-in-constructor": 0,
"react/static-property-placement": 0
"react/static-property-placement": 0,
"react/jsx-no-useless-fragment": 0,
"prefer-regex-literals": 0,
"no-unused-vars": "warn",
"react/no-unused-class-component-methods": "warn",
"react/no-unstable-nested-components": "warn",
"no-promise-executor-return": "warn",
"default-param-last": "warn"
},
"plugins": ["@typescript-eslint", "import", "promise", "react", "jest"],
"globals": {
Expand Down
66 changes: 32 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"start:dev": "nodemon --watch 'dist/main' --exec 'NODE_ENV=development yarn start'",
"test": "NODE_ENV=test yarn build && yarn test:unit && yarn test:e2e:fail-fast",
"test:jest": "jest",
"test:generate:report": "ts-node tests/reporter.ts",
"test:generate:report": "yarn node-swc tests/reporter.ts",
"test:unit": "yarn cucumber:run --require 'tests/**/unit/**/*.ts' --tags '@unit and not @skip and not @wip'",
"test:unit:rerun": "yarn cucumber:rerun --require 'tests/**/unit/**/*.ts' --tags '@unit and not @skip and not @wip'",
"test:unit:watch": "nodemon --watch source --watch tests --exec \"yarn test:unit --tags '@unit and @watch'\"",
Expand All @@ -30,15 +30,17 @@
"test:e2e:rerun:fail-fast": "yarn cucumber:rerun --require 'tests/setup-e2e.ts' --require 'tests/**/e2e/**/*.ts' --tags '@e2e and not @skip and not @wip'",
"test:e2e:watch": "gulp test:e2e:watch",
"test:e2e:watch:once": "KEEP_APP_AFTER_TESTS=true yarn test:e2e --tags '@e2e and @watch'",
"cucumber": "cross-env NODE_ENV=test cucumber-js --require 'tests/setup-common.ts' --require-module @babel/register -f json:tests-report/report-data.json -f summary:tests-report/summary.log -f node_modules/cucumber-pretty:tests-report/results.log --format-options '{\"snippetInterface\": \"async-await\"}' -f node_modules/cucumber-pretty --format-options '{\"snippetInterface\": \"async-await\"}' -f rerun:tests/@rerun.txt",
"cucumber": "cross-env NODE_ENV=test cucumber-js --require-module '@swc-node/register' --require 'tests/setup-common.ts' -f json:tests-report/report-data.json -f summary:tests-report/summary.log -f node_modules/cucumber-pretty:tests-report/results.log --format-options '{\"snippetInterface\": \"async-await\"}' -f node_modules/cucumber-pretty --format-options '{\"snippetInterface\": \"async-await\"}' -f rerun:tests/@rerun.txt",
"cucumber:run": "yarn cucumber tests",
"cucumber:fail-fast": "yarn cucumber tests --fail-fast",
"cucumber:rerun": "yarn cucumber tests-report/@rerun.txt",
"cucumber:rerun:fail-fast": "yarn cucumber tests-report/@rerun.txt --fail-fast",
"node-swc": "node -r @swc-node/register",
"debug": "gulp debug",
"package": "cross-env NODE_ENV=production yarn build && cross-env NODE_ENV=production babel-node scripts/package.js",
"package": "cross-env NODE_ENV=production yarn build && cross-env NODE_ENV=production yarn node-swc scripts/package.js",
"package:all": "yarn package --all",
"lint": "eslint --format=node_modules/eslint-formatter-pretty source storybook utils --ext .ts,.tsx",
"lint": "eslint --format=node_modules/eslint-formatter-pretty source storybook utils --ext .ts,.tsx",
"lint:fix": "eslint --fix --fix-type problem --ext '.ts,.tsx' source storybook utils",
"compile": "tsc --noEmit",
"precompile": "yarn typedef:sass",
"prettier": "./node_modules/.bin/prettier \"**/*.*\"",
Expand All @@ -47,14 +49,14 @@
"stylelint": "./node_modules/.bin/stylelint \"**/*.scss\"",
"stylelint:fix": "yarn stylelint --fix",
"i18n:extract": "formatjs extract 'source/**/*.{ts,tsx}' --ignore='**/*.d.ts' --format='translations/formatter.js' --extract-source-location --out-file='translations/messages.json'",
"i18n:check": "ts-node ./translations/translation-runner.ts",
"i18n:check": "yarn node-swc ./translations/translation-runner.ts",
"i18n:manage": "yarn i18n:extract && yarn i18n:check",
"storybook": "start-storybook -p 6006 -c storybook --ci /",
"storybook:build": "build-storybook -c storybook -o dist/storybook",
"storybook:build:chromatic": "build-storybook -c storybook",
"themes:check:createTheme": "gulp build:themes && ts-node -r esm ./dist/scripts/check.js",
"themes:update": "gulp build:themes && ts-node -r esm ./dist/scripts/update.js && yarn prettier --loglevel warn --write source/renderer/app/themes/daedalus/*.ts",
"themes:copy": "ts-node -r @babel/register -r @babel/polyfill source/renderer/app/themes/utils/copyTheme.ts && yarn prettier --loglevel warn --write source/renderer/app/themes/daedalus/*.ts",
"themes:check:createTheme": "gulp build:themes && yarn node-swc ./dist/scripts/check.js",
"themes:update": "gulp build:themes && yarn node-swc ./dist/scripts/update.js && yarn prettier --loglevel warn --write source/renderer/app/themes/daedalus/*.ts",
"themes:copy": "yarn node-swc source/renderer/app/themes/utils/copyTheme.ts && yarn prettier --loglevel warn --write source/renderer/app/themes/daedalus/*.ts",
"clear:cache": "rimraf ./node_modules/.cache",
"clear:translations": "rimraf ./translations/messages",
"nix:alonzo_purple": "./nix/yarn-nix-shell.sh alonzo_purple alonzo_purple",
Expand All @@ -64,15 +66,15 @@
"nix:shelley_qa": "./nix/yarn-nix-shell.sh shelley_qa shelley_qa",
"nix:staging": "./nix/yarn-nix-shell.sh staging staging",
"nix:testnet": "./nix/yarn-nix-shell.sh testnet testnet",
"byron:wallet:importer": "ts-node utils/api-importer/byron-wallet-importer.ts",
"shelley:wallet:importer": "ts-node utils/api-importer/shelley-wallet-importer.ts",
"mary:wallet:importer": "ts-node utils/api-importer/mary-wallet-importer.ts",
"itn:byron:wallet:importer": "ts-node utils/api-importer/itn-byron-wallet-importer.ts",
"itn:shelley:wallet:importer": "ts-node utils/api-importer/itn-shelley-wallet-importer.ts",
"yoroi:wallet:importer": "ts-node utils/api-importer/yoroi-wallet-importer.ts",
"create-news-verification-hashes": "ts-node utils/create-news-verification-hashes/index.ts",
"lockfile:check": "ts-node utils/lockfile-checker/index.ts --check",
"lockfile:fix": "ts-node utils/lockfile-checker/index.ts --fix",
"byron:wallet:importer": "yarn node-swc utils/api-importer/byron-wallet-importer.ts",
"shelley:wallet:importer": "yarn node-swc utils/api-importer/shelley-wallet-importer.ts",
"mary:wallet:importer": "yarn node-swc utils/api-importer/mary-wallet-importer.ts",
"itn:byron:wallet:importer": "yarn node-swc utils/api-importer/itn-byron-wallet-importer.ts",
"itn:shelley:wallet:importer": "yarn node-swc utils/api-importer/itn-shelley-wallet-importer.ts",
"yoroi:wallet:importer": "yarn node-swc utils/api-importer/yoroi-wallet-importer.ts",
"create-news-verification-hashes": "yarn node-swc utils/create-news-verification-hashes/index.ts",
"lockfile:check": "yarn node-swc utils/lockfile-checker/index.ts --check",
"lockfile:fix": "yarn node-swc utils/lockfile-checker/index.ts --fix",
"postinstall": "./scripts/postinstall.sh",
"typedef:sass": "typed-scss-modules source/renderer/app"
},
Expand All @@ -92,6 +94,7 @@
"@storybook/core": "6.4.20",
"@storybook/manager-webpack5": "6.4.20",
"@storybook/react": "6.4.20",
"@swc-node/register": "1.4.2",
"@swc/core": "1.2.164",
"@testing-library/jest-dom": "5.15.1",
"@testing-library/react": "12.1.2",
Expand All @@ -102,16 +105,12 @@
"@types/react": "17.0.38",
"@types/react-svg-inline": "2.1.3",
"@types/react-table": "^7.7.9",
"@typescript-eslint/eslint-plugin": "5.10.1",
"@typescript-eslint/parser": "5.10.1",
"@typescript-eslint/eslint-plugin": "5.20.0",
"@typescript-eslint/parser": "5.20.0",
"@xarc/run": "1.1.1",
"asar": "2.1.0",
"autodll-webpack-plugin": "0.4.2",
"axios": "0.24.0",
"babel-eslint": "10.1.0",
"babel-jest": "27.4.2",
"babel-loader": "8.2.3",
"babel-plugin-react-intl": "3.0.1",
"bufferutil": "4.0.1",
"cache-loader": "4.1.0",
"chai": "4.3.4",
Expand All @@ -128,17 +127,17 @@
"electron-packager": "15.4.0",
"electron-rebuild": "2.0.1",
"electron-reloader": "1.2.1",
"eslint": "7.32.0",
"eslint-config-airbnb": "18.2.0",
"eslint": "8.13.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "8.5.0",
"eslint-formatter-pretty": "4.0.0",
"eslint-import-resolver-webpack": "0.13.1",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-jest": "25.3.0",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-react": "7.25.1",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-formatter-pretty": "4.1.0",
"eslint-import-resolver-webpack": "0.13.2",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "26.1.4",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-promise": "6.0.0",
"eslint-plugin-react": "7.29.4",
"eslint-plugin-react-hooks": "4.4.0",
"esm": "3.2.25",
"gulp-shell": "0.8.0",
"hash.js": "1.1.7",
Expand Down Expand Up @@ -185,7 +184,6 @@
"thread-loader": "2.1.3",
"timemachine": "0.3.2",
"transform-loader": "0.2.4",
"ts-node": "10.4.0",
"typed-scss-modules": "5.0.0",
"typescript": "4.6.2",
"utf-8-validate": "5.0.2",
Expand Down
3 changes: 2 additions & 1 deletion source/common/ipc/lib/IpcChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export class IpcChannel<Incoming, Outgoing> {

// Enforce the singleton pattern based on the channel name
const existingChannel = IpcChannel._instances[channelName];
if (existingChannel) return existingChannel;
if (existingChannel)
throw new Error(`Channel ${channelName} already exists`);
IpcChannel._instances[channelName] = this;
this._broadcastChannel = `${channelName}-broadcast`;
this._requestChannel = `${channelName}-request`;
Expand Down
2 changes: 1 addition & 1 deletion source/main/cardano/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const createSelfnodeConfig = async (

const configFileContent = await fs.readFile(configFilePath);
const configFile = JSON.stringify({
...JSON.parse(configFileContent),
...JSON.parse(configFileContent.toString()),
GenesisFile: genesisPath,
});
const configPath = path.join(stateDir, 'config.yaml');
Expand Down
6 changes: 3 additions & 3 deletions source/main/ipc/load-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const loadAssetChannel: MainIpcChannel<
export default () => {
loadAssetChannel.onRequest((request: LoadAssetRendererRequest) => {
const asset = path.resolve(__dirname, `../renderer/${request.fileName}`);
return new Promise((resolve, reject) =>
return new Promise((resolve, reject) => {
fs.readFile(asset, 'base64', (error, data) => {
if (error) {
reject(error);
} else {
resolve(data);
}
})
);
});
});
});
};
2 changes: 1 addition & 1 deletion source/main/ipc/manageAppUpdateChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const handleManageAppUpdateRequests = (window: BrowserWindow) => {
success: boolean | null | undefined,
functionPrefix: string,
messageText = '',
_data?: Record<string, any>
_data: Record<string, unknown> = {}
): Response => {
let status = statuses.PROGRESS;
if (success === true) status = statuses.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion source/renderer/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class App extends Component<{
{/* @ts-ignore ts-migrate(2769) FIXME: No overload matches this call. */}
<ThemeManager variables={themeVars} />
<Provider stores={stores} actions={actions}>
<MenuUpdater />
<MenuUpdater stores={stores} />
<ThemeProvider
theme={daedalusTheme}
skins={SimpleSkins}
Expand Down
39 changes: 15 additions & 24 deletions source/renderer/app/WindowSizeManager.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
/* eslint-disable react/prop-types */
import React, { Component, Fragment } from 'react';
import { useEffect } from 'react';

export default class WindowSizeManager extends Component {
componentDidMount() {
// @ts-ignore ts-migrate(2339) FIXME: Property 'minScreenHeight' does not exist on type ... Remove this comment to see the full error message
this.updateMinScreenHeight(this.props.minScreenHeight);
}

componentDidUpdate(prevProps) {
// @ts-ignore ts-migrate(2339) FIXME: Property 'minScreenHeight' does not exist on type ... Remove this comment to see the full error message
if (this.props.minScreenHeight !== prevProps.minScreenHeight) {
// @ts-ignore ts-migrate(2339) FIXME: Property 'minScreenHeight' does not exist on type ... Remove this comment to see the full error message
this.updateMinScreenHeight(this.props.minScreenHeight);
}
}
type Props = {
minScreenHeight: number;
children: Node;
};

updateMinScreenHeight(minScreenHeight) {
const rootWindowEl = document.getElementById('root');

if (rootWindowEl) {
rootWindowEl.style.minHeight = minScreenHeight;
}
function updateMinScreenHeight(minScreenHeight: number) {
const rootWindowEl = document.getElementById('root');
if (rootWindowEl) {
rootWindowEl.style.minHeight = minScreenHeight.toString();
}
}

render() {
return <Fragment>{this.props.children}</Fragment>;
}
export default function WindowSizeManager(props: Props) {
useEffect(() => {
updateMinScreenHeight(props.minScreenHeight);
}, [props.minScreenHeight]);
return props.children;
}
4 changes: 3 additions & 1 deletion source/renderer/app/api/utils/apiHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export const testSync = (apiMethod: (...args: Array<any>) => any) => {
};
// helper code for deferring API call execution
export const wait = (ms: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, ms));
new Promise((resolve) => {
setTimeout(resolve, ms);
});
export const doesWalletRequireAdaToRemainToSupportTokens = (
error: ErrorType,
hasAssetsRemainingAfterTransaction?: boolean
Expand Down
2 changes: 0 additions & 2 deletions source/renderer/app/components/assets/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class Asset extends Component<Props, State> {
intl: intlShape.isRequired,
};
// @ts-ignore ts-migrate(2304) FIXME: Cannot find name 'TimeoutID'.
copyNotificationTimeout: TimeoutID;
// @ts-ignore ts-migrate(2304) FIXME: Cannot find name 'TimeoutID'.
displayDelayTimeout: TimeoutID;
state = {
isPillPopOverVisible: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,38 +312,32 @@ class HardwareWalletStatus extends Component<Props, State> {
}

return (
<>
<div className={componentClasses}>
<div className={styles.messageWrapper}>
<div className={styles.message}>
{hasInstructionsLink && instructionsLink ? (
<FormattedMessage
{...messages[hwDeviceStatus]}
values={{
instructionsLink,
}}
/>
) : (
label
)}
</div>
{secondaryMessage && (
<div className={styles.secondaryMessage}>
{intl.formatMessage(secondaryMessage)}
</div>
<div className={componentClasses}>
<div className={styles.messageWrapper}>
<div className={styles.message}>
{hasInstructionsLink && instructionsLink ? (
<FormattedMessage
{...messages[hwDeviceStatus]}
values={{
instructionsLink,
}}
/>
) : (
label
)}
</div>
{isLoading && (
<LoadingSpinner className="hardwareWalletProcessProgress" />
)}
{isReady && (
<SVGInline svg={checkIcon} className={styles.checkIcon} />
)}
{isError && (
<SVGInline svg={clearIcon} className={styles.clearIcon} />
{secondaryMessage && (
<div className={styles.secondaryMessage}>
{intl.formatMessage(secondaryMessage)}
</div>
)}
</div>
</>
{isLoading && (
<LoadingSpinner className="hardwareWalletProcessProgress" />
)}
{isReady && <SVGInline svg={checkIcon} className={styles.checkIcon} />}
{isError && <SVGInline svg={clearIcon} className={styles.clearIcon} />}
</div>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ type Props = {
children?: Node | null | undefined;
};

const VerticalFlexContainer = ({ children }: Props) => (
<div className={styles.component}>{children}</div>
);
function VerticalFlexContainer({ children }: Props) {
return <div className={styles.component}>{children}</div>;
}

export default memo<Props>(VerticalFlexContainer);
Loading

0 comments on commit e1a612b

Please sign in to comment.