Skip to content

Commit a72208b

Browse files
committed
ci: stricter linter rules
Signed-off-by: Andres Correa Casablanca <castarco@coderspirit.xyz>
1 parent 070d467 commit a72208b

File tree

5 files changed

+179
-19
lines changed

5 files changed

+179
-19
lines changed

.eslintrc.cjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,34 @@ module.exports = {
1313
},
1414
plugins: [
1515
'@typescript-eslint',
16+
'import',
1617
'prettier',
17-
'react-refresh'
18+
'react-refresh',
1819
],
1920
extends: [
2021
'eslint:recommended',
2122
'plugin:@typescript-eslint/strict-type-checked',
23+
'plugin:@typescript-eslint/stylistic-type-checked',
24+
'plugin:import/recommended',
25+
'plugin:import/typescript',
2226
'plugin:react/recommended',
2327
'plugin:react/jsx-runtime',
2428
'plugin:react-hooks/recommended',
25-
'plugin:storybook/recommended'
29+
'plugin:storybook/recommended',
30+
'prettier',
2631
],
32+
rules: {
33+
'@typescript-eslint/consistent-type-exports': 'error',
34+
'@typescript-eslint/consistent-type-imports': 'error',
35+
"@typescript-eslint/explicit-function-return-type": "error",
36+
"@typescript-eslint/explicit-member-accessibility": "error",
37+
"@typescript-eslint/explicit-module-boundary-types": "error",
38+
"@typescript-eslint/no-import-type-side-effects": "error",
39+
'@typescript-eslint/no-misused-promises': 'error',
40+
"@typescript-eslint/no-unnecessary-qualifier": "error",
41+
"@typescript-eslint/prefer-readonly": "error",
42+
"@typescript-eslint/prefer-readonly-parameter-types": "error",
43+
},
2744
settings: {
2845
react: {
2946
version: 'detect'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@vitest/coverage-v8": "^0.34.1",
5959
"eslint": "^8.47.0",
6060
"eslint-config-prettier": "^9.0.0",
61+
"eslint-plugin-import": "^2.28.0",
6162
"eslint-plugin-prettier": "^5.0.0",
6263
"eslint-plugin-react": "^7.33.1",
6364
"eslint-plugin-react-hooks": "^4.6.0",

pnpm-lock.yaml

Lines changed: 134 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BeautifulTree.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { Tree } from './core'
22

33
export interface BeautifulTreeProps {
4-
id: string,
5-
svgProps: {
6-
width: number,
7-
height: number,
4+
readonly id: string,
5+
readonly svgProps: {
6+
readonly width: number,
7+
readonly height: number,
88
},
9-
tree: Tree,
9+
readonly tree: Tree,
1010
}
1111

12-
export function BeautifulTree(props: BeautifulTreeProps) {
12+
export function BeautifulTree(props: Readonly<BeautifulTreeProps>): JSX.Element {
1313
return (
1414
<svg
1515
xmlns="http://www.w3.org/2000/svg"

src/core.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
export type TreeChild<T extends Tree = Tree> = {
2-
node: T,
3-
edgeData?: Record<string, unknown> | undefined,
1+
export interface TreeChild<T extends Tree = Tree> {
2+
readonly node: T,
3+
readonly edgeData?: Readonly<Record<string, unknown>> | undefined,
44
}
55

6-
export type Node = {
7-
data?: Record<string, unknown> | undefined,
6+
export interface Node {
7+
readonly data?: Readonly<Record<string, unknown>> | undefined,
88
}
99

1010
export type Tree = Node & {
11-
children?: TreeChild[] | undefined,
11+
readonly children?: readonly TreeChild[] | undefined,
1212
}
1313

1414
export type TreeWithLayout = Node & {
15-
children?: Required<TreeChild<TreeWithLayout>>[] | undefined,
16-
layout: {
17-
plan: { x: number, y: number },
15+
readonly children?: Required<TreeChild<TreeWithLayout>>[] | undefined,
16+
readonly layout: {
17+
readonly plan: {
18+
readonly x: number,
19+
readonly y: number
20+
},
1821
}
1922
}
2023

2124
type InternalTreeLayout = number[][]
2225

23-
const _computeLeftShiftLayout = (tree: Tree, depth: number = 0, layout?: InternalTreeLayout): TreeWithLayout => {
26+
const _computeLeftShiftLayout = (
27+
tree: Tree,
28+
depth = 0,
29+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
30+
layout?: InternalTreeLayout
31+
): TreeWithLayout => {
2432
layout ??= []
2533

2634
if (layout[depth] === undefined) {
@@ -32,7 +40,7 @@ const _computeLeftShiftLayout = (tree: Tree, depth: number = 0, layout?: Interna
3240

3341
const treeWithLayout = {
3442
data: tree.data,
35-
children: tree.children?.map(child => ({
43+
children: tree.children?.map((child: Readonly<TreeChild>) => ({
3644
edgeData: child.edgeData,
3745
node: _computeLeftShiftLayout(child.node, depth + 1, layout),
3846
})),

0 commit comments

Comments
 (0)