Skip to content

Commit e2cd26c

Browse files
MA-16191: fix RouterLink and refactor pre-commit hook
1 parent c4a153a commit e2cd26c

File tree

13 files changed

+86
-33
lines changed

13 files changed

+86
-33
lines changed

.eslintrc.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ module.exports = {
1111
},
1212
},
1313
],
14+
settings: {
15+
"import/resolver": {
16+
"node": {
17+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
18+
}
19+
}
20+
},
1421
rules: {
1522
'import/named': 'off',
16-
'import/no-unresolved': 'off',
1723
'no-shadow': 'off',
1824
'guard-for-in': 'off',
25+
'import/no-unresolved': ['error', { ignore: ['^[a-z@]'] }],
1926
'@typescript-eslint/ban-types': 'off',
2027
'@typescript-eslint/array-type': 'off',
2128
'@typescript-eslint/prefer-readonly': 'off',

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
yarn lint-staged && yarn run lint:prettier
4+
yarn lint-staged

.lintstagedrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"*.ts": "eslint",
3-
"*.tsx": "eslint"
2+
"*.ts": ["eslint", "prettier --check"],
3+
"*.tsx": ["eslint", "prettier --check"]
44
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
},
2121
"scripts": {
2222
"build": "tsc",
23-
"lint:js": "eslint src/ --ext ts,tsx --fix",
24-
"lint:prettier": "prettier --check .",
23+
"eslint:check": "eslint src/ --ext ts,tsx",
24+
"eslint:fix": "eslint src/ --ext ts,tsx",
25+
"prettier:check": "prettier --check .",
2526
"prettier:fix": "prettier --write .",
2627
"prepare": "husky install",
2728
"prepublishOnly": "yarn build"

src/components/RouterLink.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2-
// @ts-expect-error
31
import { Link } from '@vkontakte/vkui';
42
import { useHref } from '../hooks/useHref';
53
import { RelativeRoutingType, To } from '@remix-run/router';
@@ -20,13 +18,11 @@ export interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>,
2018
}
2119

2220
export interface RouterLinkProps extends Omit<LinkProps, 'className' | 'style' | 'children'> {
23-
children?: ReactNode | ((props: { isActive: boolean; isPending: boolean }) => ReactNode);
21+
children?: ReactNode;
2422
caseSensitive?: boolean;
25-
className?: string | ((props: { isActive: boolean; isPending: boolean }) => string | undefined);
23+
className?: string;
2624
end?: boolean;
27-
style?:
28-
| CSSProperties
29-
| ((props: { isActive: boolean; isPending: boolean }) => CSSProperties | undefined);
25+
style?: CSSProperties;
3026
}
3127

3228
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
@@ -83,7 +79,7 @@ export const RouterLink = forwardRef<HTMLAnchorElement, RouterLinkProps>(functio
8379
{...rest}
8480
href={absoluteHref || href}
8581
onClick={isExternal || reloadDocument ? onClick : handleClick}
86-
ref={ref}
82+
getRootRef={ref}
8783
target={target}
8884
></Link>
8985
);

src/hooks/useEnableSwipeBack.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import { useEffect, useRef } from 'react';
22
import { BridgeService } from '../services/BridgeService';
3-
import {
4-
parseURLSearchParamsForGetLaunchParams,
5-
EGetLaunchParamsResponsePlatforms,
6-
} from '@vkontakte/vk-bridge';
73

84
export function useEnableSwipeBack() {
9-
const { vk_platform } = parseURLSearchParamsForGetLaunchParams(window.location.search);
105
const consumerId = useRef<string | null>(null);
116

127
useEffect(() => {
13-
if (
14-
vk_platform !== EGetLaunchParamsResponsePlatforms.MOBILE_IPHONE &&
15-
vk_platform !== EGetLaunchParamsResponsePlatforms.MOBILE_IPHONE_MESSENGER &&
16-
vk_platform !== EGetLaunchParamsResponsePlatforms.MOBILE_IPAD
17-
) {
18-
return;
19-
}
208
consumerId.current = BridgeService.enableNativeSwipeBack();
219

2210
return () => {

src/page-types/PanelPage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type AnySubPage = AnyModalPage | AnyTabPage;
1414
abstract class BasePanelPage<I extends string> implements RepresentsRoutes<PanelRoutePartial>, HasId<I> {
1515
protected constructor(public id: I, public path: string, protected modals: AnySubPage[]) {
1616
modals.forEach((modal) => {
17+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1718
// @ts-expect-error
1819
this[uniqueKey(this, modal.id)] = modal;
1920
});

src/page-types/RootConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class RootConfig<T extends string> implements HasId<T>, HasChildren<ViewC
1515
throw new Error(`Trying to create root ${id} without views. Root must have at least one view.`);
1616
}
1717
views.forEach((views) => {
18+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1819
// @ts-expect-error
1920
this[uniqueKey(this, views.id)] = views;
2021
});

src/page-types/RoutesConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class RoutesConfig implements RepresentsRoutes<RoutePartial> {
5050
const config = new RoutesConfig();
5151
config.items = routes;
5252
routes.forEach((route) => {
53+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5354
// @ts-expect-error
5455
config[uniqueKey(config, route.id)] = route;
5556
});

src/page-types/TabPage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface TabRoutePartial extends CommonRouteObject {
1010
abstract class BaseTabPage<I extends string> implements RepresentsRoutes<TabRoutePartial>, HasId<I> {
1111
protected constructor(public id: I, public path: string, protected modals: AnyModalPage[]) {
1212
modals.forEach((modal) => {
13+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1314
// @ts-expect-error
1415
this[uniqueKey(this, modal.id)] = modal;
1516
});

0 commit comments

Comments
 (0)