Skip to content

Commit cf044a3

Browse files
committed
chore(lint): ts for lint and build
1 parent e56aab6 commit cf044a3

File tree

14 files changed

+112
-56
lines changed

14 files changed

+112
-56
lines changed

.eslintrc

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
"@gravity-ui/eslint-config/prettier",
66
"prettier"
77
],
8-
"parserOptions": {
9-
"project": "./tsconfig.eslint.json"
10-
},
118
"root": true,
129
"env": {
1310
"node": true,
1411
"jest": true
1512
},
1613
"overrides": [
1714
{
18-
// enable the rule specifically for TypeScript files
1915
"files": [
2016
"*.ts",
2117
"*.mts",
@@ -32,8 +28,8 @@
3228
"constructors": "no-public",
3329
"methods": "explicit",
3430
"properties": "off",
35-
"parameterProperties": "explicit",
36-
},
31+
"parameterProperties": "explicit"
32+
}
3733
}
3834
],
3935
"no-bitwise": [
@@ -44,31 +40,10 @@
4440
]
4541
}
4642
},
47-
{
48-
"files": [
49-
"packages/stories/src/**/*.tsx"
50-
],
51-
"rules": {
52-
"no-console": "off"
53-
}
54-
},
55-
{
56-
"files": [
57-
"**/*.test.ts",
58-
"**/*.test.tsx",
59-
"**/*.spec.ts",
60-
"**/*.spec.tsx"
61-
],
62-
"rules": {
63-
"@typescript-eslint/no-explicit-any": "off",
64-
"import/no-extraneous-dependencies": "off"
65-
}
66-
},
6743
{
6844
"files": [
6945
"jest.config.ts",
70-
"jest.config.base.ts",
71-
"**/jest.config.ts"
46+
"jest.config.base.ts"
7247
],
7348
"rules": {
7449
"import/no-extraneous-dependencies": "off"

packages/graph/.eslintrc.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
extends: "../../.eslintrc",
3+
parserOptions: {
4+
project: "./tsconfig.dev.json",
5+
tsconfigRootDir: __dirname,
6+
},
7+
overrides: [
8+
{
9+
files: ["**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"],
10+
rules: {
11+
"@typescript-eslint/no-explicit-any": "off",
12+
"import/no-extraneous-dependencies": "off",
13+
},
14+
},
15+
],
16+
};
17+

packages/graph/src/graph.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ describe("Graph export/import and updateBlock integration", () => {
2929
graph2.start();
3030
const updatedHeight = block.height + 10;
3131
expect(() => {
32+
// First block is guaranteed to exist in exported config
33+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3234
graph2.api.updateBlock({ ...exportedConfig.blocks![0]!, height: updatedHeight });
3335
}).not.toThrow();
3436
const updatedBlock = graph2.rootStore.blocksList.$blocks.value[0];

packages/graph/src/services/Layer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export class Layer<
5959
> extends Component<Props, State, Context> {
6060
public static id?: string;
6161

62-
protected canvas!: HTMLCanvasElement;
62+
protected canvas?: HTMLCanvasElement;
6363

64-
protected html!: HTMLElement;
64+
protected html?: HTMLElement;
6565

6666
protected root?: HTMLDivElement;
6767

packages/graph/src/store/block/BlocksList.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { jest } from "@jest/globals";
22

33
import { TBlock } from "../../components/canvas/blocks/Block";
44
import { Graph } from "../../graph";
5-
import { SelectionEvent } from "../../graphEvents";
5+
import { GraphEventsDefinitions } from "../../graphEvents";
66
import { ESelectionStrategy } from "../../services/selection/types";
77
import { EAnchorType } from "../anchor/Anchor";
88

9-
import { TBlockId } from "./Block";
109
import { BlockListStore } from "./BlocksList";
1110

1211
const generateBlock = (): TBlock => {
@@ -150,16 +149,16 @@ describe("Blocks selection", () => {
150149
it.todo("Should emit event on select anchor");
151150

152151
it("Should emit blocks-selection-change event with correct params", () => {
153-
const handler = jest.fn();
152+
const handler = jest.fn<GraphEventsDefinitions["blocks-selection-change"]>();
154153
graph.on("blocks-selection-change", handler);
155154

156155
store.updateBlocksSelection([block1.id], true);
157156

158157
expect(handler).toHaveBeenCalledTimes(1);
159158
const eventArg = handler.mock.calls[0][0];
160159
// Проверяем, что в eventArg есть нужные id
161-
expect((eventArg as SelectionEvent<TBlockId>).detail.changes.add).toEqual([block1.id]);
162-
expect((eventArg as SelectionEvent<TBlockId>).detail.changes.removed).toEqual([]);
160+
expect(eventArg.detail.changes.add).toEqual([block1.id]);
161+
expect(eventArg.detail.changes.removed).toEqual([]);
163162
});
164163

165164
it("Should prevent selection change if preventDefault called", () => {
@@ -208,7 +207,7 @@ describe("Anchors selection", () => {
208207
});
209208

210209
it("Should emit block-anchor-selection-change event with correct params", () => {
211-
const handler = jest.fn();
210+
const handler = jest.fn<GraphEventsDefinitions["block-anchor-selection-change"]>();
212211
graph.on("block-anchor-selection-change", handler);
213212

214213
store.setAnchorSelection(block.id, anchorId, true);

packages/graph/tsconfig.dev.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"composite": false,
5+
"noEmit": true
6+
},
7+
"include": [
8+
"src/**/*"
9+
],
10+
"exclude": [
11+
"dist",
12+
"build",
13+
"**/__snapshots__"
14+
]
15+
}
16+

packages/react/.eslintrc.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
extends: "../../.eslintrc",
3+
parserOptions: {
4+
project: "./tsconfig.dev.json",
5+
tsconfigRootDir: __dirname,
6+
},
7+
overrides: [
8+
{
9+
files: ["**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"],
10+
rules: {
11+
"@typescript-eslint/no-explicit-any": "off",
12+
"import/no-extraneous-dependencies": "off",
13+
},
14+
},
15+
],
16+
};
17+

packages/react/src/GraphPortal.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { jest } from "@jest/globals";
55
import { act, render, waitFor } from "@testing-library/react";
66

77
import { GraphCanvas } from "./GraphCanvas";
8-
import { GraphPortal } from "./GraphPortal";
8+
import { GraphPortal, TGraphPortalChildren } from "./GraphPortal";
99

1010
describe("GraphPortal", () => {
1111
let graph: Graph;
@@ -66,7 +66,7 @@ describe("GraphPortal", () => {
6666
});
6767

6868
it("should render children as function with layer parameter", async () => {
69-
const childrenFn = jest.fn().mockReturnValue(<div>Function Content</div>);
69+
const childrenFn = jest.fn<TGraphPortalChildren>().mockReturnValue(<div>Function Content</div>);
7070

7171
render(
7272
<GraphCanvas graph={graph} renderBlock={() => <div>Block</div>}>

packages/react/src/GraphPortal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class GraphPortalLayer extends Layer<GraphPortalLayerProps, LayerContext, TCompo
5151
}
5252
}
5353

54+
export type TGraphPortalChildren = (layer: GraphPortalLayer, graph: Graph) => React.ReactNode;
55+
5456
/**
5557
* GraphPortal component properties
5658
*/
@@ -71,7 +73,7 @@ export interface GraphPortalProps {
7173
/**
7274
* Function for rendering portal content
7375
*/
74-
children: React.ReactNode | ((layer: GraphPortalLayer, graph: Graph) => React.ReactNode);
76+
children: React.ReactNode | TGraphPortalChildren;
7577
}
7678

7779
/**

packages/react/src/layer/ReactLayer.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Graph } from "@gravity-ui/graph";
22
import { jest } from "@jest/globals";
33

4+
import { TBlockListProps } from "../BlocksList";
5+
46
import { ReactLayer } from "./ReactLayer";
57

68
describe("ReactLayer", () => {
@@ -238,7 +240,7 @@ describe("ReactLayer", () => {
238240
describe("renderPortal", () => {
239241
it("should return null when HTML element is forcibly removed", () => {
240242
const layer = createUnattachedLayer();
241-
const renderBlock = jest.fn();
243+
const renderBlock = jest.fn<TBlockListProps["renderBlock"]>();
242244

243245
// Mock getHTML to return null
244246
jest.spyOn(layer, "getHTML").mockReturnValue(null);

0 commit comments

Comments
 (0)