Skip to content

Commit

Permalink
configure eslint with type and lint-staged for pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
reza-bm committed Dec 4, 2023
1 parent 7815bc1 commit 59721b6
Show file tree
Hide file tree
Showing 27 changed files with 539 additions and 221 deletions.
10 changes: 9 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
**/node_modules/*
**/out/*
**/.next/*
**/.next/*

node_modules
.next
build

next.config.js
postcss.config.js
tailwind.config.js
36 changes: 0 additions & 36 deletions .eslintrc.js

This file was deleted.

47 changes: 47 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"env": {
"browser": true,
"es2021": true
},
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"import",
"react",
"react-hooks",
"destructuring"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:@next/next/recommended",
"plugin:prettier/recommended"
],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": true,
"tsconfigRootDir": "__dirname"
},
"rules": {
// React scope no longer necessary with new JSX transform\
"react/react-in-jsx-scope": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
],
// Allow .js files to use JSX syntax
"react/jsx-filename-extension": ["error", { "extensions": [".tsx"] }],
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"react/no-unescaped-entities": "off"
},
"root": true
}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
4 changes: 4 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.{ts,tsx}": ["eslint --fix --quiet"],
"*.{ts,tsx,json}": ["prettier --write"]
}
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
.next
yarn.lock
package-lock.json
public
public
build
30 changes: 15 additions & 15 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"configurations": [
{
"name": "Next.js: debug server-side",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev"
},
{
"name": "Next.js: chrome debug client-side",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000"
}
]
}
"configurations": [
{
"name": "Next.js: debug server-side",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev"
},
{
"name": "Next.js: chrome debug client-side",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000"
}
]
}
2 changes: 1 addition & 1 deletion components/common/Button/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LinkButtonProps } from './Button.types';
import { PropsWithChildren } from 'react';

export function LinkButton(props: PropsWithChildren<LinkButtonProps>) {
const onClick = (e: any) => {
const onClick = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
const btn = e.currentTarget;
const circle = document.createElement('span');
const diameter = Math.max(btn.clientWidth, btn.clientHeight);
Expand Down
2 changes: 1 addition & 1 deletion components/common/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ButtonProps } from './Button.types';
import { PropsWithChildren } from 'react';

export function Button(props: PropsWithChildren<ButtonProps>) {
const handleClick = (e: any) => {
const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
const btn = e.currentTarget;
const circle = document.createElement('span');
const diameter = Math.max(btn.clientWidth, btn.clientHeight);
Expand Down
2 changes: 1 addition & 1 deletion components/common/Table/Table.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export interface ColumnType {
id: number;
title: string;
tokenType?: TokenType;
component?: any;
component?: React.ComponentType<CellProps>;
}
2 changes: 1 addition & 1 deletion components/detail/SwapDetailSummary/SwapDetail.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface PropsType {
export interface ColumnType {
id: number;
title: string;
component?: any;
component?: React.ComponentType<SwapDetailItem>;
}

export interface SwapDetailItem {
Expand Down
7 changes: 2 additions & 5 deletions components/detail/SwapSteps/SwapStepAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ function SwapStepAddress(props: SwapStepItemValueProps) {
address && (
<div className="flex col-span-4 items-center p-16">
<button onClick={handleClick} className="text-secondary-500 mr-5">
{address?.length > 40
? `${address.slice(0, 20)}...${address.slice(
address.length - 20,
address.length,
)}`
{address?.length > 41
? `${address.slice(0, 20)}...${address.slice(-20)}`
: address}
</button>
<ButtonCopyIcon text={address} />
Expand Down
2 changes: 1 addition & 1 deletion components/detail/SwapSteps/SwapStepSwapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function SwapStepSwapper(props: SwapStepItemProps) {
className={`bg-transaction ml-[0.875rem] border-l border-solid ${borderColor} w-fll h-[0.5rem]`}></div>
)}
<div
key={`swapper-${internalSwapper?.swapperId}`}
key={`swapper-${internalSwapper.swapperId}`}
className="flex items-center">
<img
className={`mr-10 border w-[1.75rem] h-[1.75rem] border-solid ${borderColor} rounded-full`}
Expand Down
2 changes: 1 addition & 1 deletion components/detail/SwapSteps/SwapSteps.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface TransactionURLProps {
export interface ColumnType {
id: number;
title: string;
component?: any;
component?: React.ComponentType<SwapStepItemValueProps>;
}

export interface SwapStepItemValueProps {
Expand Down
1 change: 1 addition & 0 deletions components/home/ChartBox/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const Chart = (props: ChartProps) => {
snapTooltipToDatumX
snapTooltipToDatumY
showVerticalCrosshair
// eslint-disable-next-line @typescript-eslint/no-explicit-any
renderTooltip={({ tooltipData }: any) => (
<div className="text-12">
<div className="mb-1">Swaps</div>
Expand Down
1 change: 1 addition & 0 deletions constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const MATCH_TYPE = {
REQUESTID: 'REQUESTID',
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const STATUS: any = {
success: 'success',
failed: 'failed',
Expand Down
4 changes: 2 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}
};

module.exports = nextConfig
module.exports = nextConfig;
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"prettier": "prettier ./components/navbar/deskNavbar.tsx",
"lint": "eslint --fix --quiet .",
"prettier": "prettier --write ./components/detail/SwapSteps/SwapStepAddress.tsx",
"prepare": "husky install",
"build:icons": "svgr svgs/resources/ --config-file svgs/configs/.svgrrc.default.cjs && prettier -w ./components/icons"
},
Expand Down Expand Up @@ -35,20 +35,24 @@
"@types/node": "18.11.9",
"@types/react": "18.2.33",
"@types/react-dom": "18.2.14",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"autoprefixer": "^10.4.13",
"eslint": "^8.54.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "^23.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-destructuring": "^2.2.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^15.5.1",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.0",
"lint-staged": "^15.2.0",
"postcss": "^8.4.19",
"prettier": "^3.1.0",
"tailwindcss": "^3.2.4",
"typescript": "^4.9.3"
"typescript": "^5.3.2"
}
}
1 change: 0 additions & 1 deletion pages/search.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/prefer-optional-chain */
import { GetServerSideProps } from 'next';
import { useRouter } from 'next/router';
import { getSearchResult, getWalletSwaps } from '../services';
Expand Down
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
Loading

0 comments on commit 59721b6

Please sign in to comment.