Skip to content

Commit

Permalink
migrate eslint, fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Dec 7, 2024
1 parent 1da95e6 commit 2e7a9e9
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 102 deletions.
57 changes: 0 additions & 57 deletions .eslintrc.cjs

This file was deleted.

66 changes: 66 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: [
'**/node_modules',
'**/dist',
'**/build',
'**/generated',
'packages/cli/tests/cli/init',
'packages/cli/tests/cli/validation',
'packages/ts/test/',
'**/examples',
'**/vitest.config.ts',
],
},
...compat.extends('@theguild'),
{
rules: {
'import/extensions': 'off',
'unicorn/no-array-push-push': 'off',
'import/no-default-export': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-types': 'off',
eqeqeq: 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['packages/ts/**'],

rules: {
'@typescript-eslint/no-namespace': 'off',
'sonarjs/no-inverted-boolean-check': 'off',
'no-loss-of-precision': 'warn',
},
},
{
files: ['packages/cli/**'],

rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['@whatwg-node/fetch'],
message: 'Please use `fetch` from `./packages/cli/src/fetch.ts`.',
},
],
},
],
},
},
];
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "graphprotocol-tools-monorepo",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/graphprotocol/graph-cli"
Expand All @@ -17,8 +18,8 @@
"scripts": {
"build": "pnpm --filter=@graphprotocol/graph-* build",
"lint": "pnpm lint:prettier && pnpm lint:eslint",
"lint:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint .",
"lint:eslint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint . --fix",
"lint:eslint": "eslint .",
"lint:eslint:fix": "eslint . --fix",
"lint:fix": "pnpm lint:prettier:fix && pnpm lint:eslint:fix",
"lint:prettier": "prettier -c .",
"lint:prettier:fix": "prettier . --write",
Expand All @@ -30,6 +31,7 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.10",
"@eslint/js": "^9.16.0",
"@theguild/eslint-config": "0.13.1",
"@theguild/prettier-config": "3.0.0",
"@types/node": "^22.10.1",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "tsc && vite build",
"clean": "rimraf ./dist",
"dev": "vite",
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint . --report-unused-disable-directives",
"lint": "eslint . --report-unused-disable-directives",
"prebuild": "tsr generate",
"preview": "vite preview"
},
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/Dropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ACCEPTED_IMAGE_TYPES = {
};

// Limit avatar images to 1mb
const MAX_IMAGE_SIZE = 1000000;
const MAX_IMAGE_SIZE = 1_000_000;

const BOX_SIZE = 152;

Expand Down
2 changes: 1 addition & 1 deletion website/src/components/ui/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const FormControl = React.forwardRef<
<Slot
ref={ref}
id={formItemId}
aria-describedby={!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`}
aria-describedby={error ? `${formDescriptionId} ${formMessageId}` : formDescriptionId}
aria-invalid={!!error}
{...props}
/>
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { cn } from '@/lib/utils';

export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
type InputProps = React.InputHTMLAttributes<HTMLInputElement>;

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/ui/textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { cn } from '@/lib/utils';

export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>;

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => {
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/ui/toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function Toaster() {

return (
<ToastProvider>
{toasts.map(function ({ id, title, description, action, ...props }) {
{toasts.map(({ id, title, description, action, ...props }) => {
return (
<Toast key={id} {...props}>
<div className="grid gap-1">
Expand Down
28 changes: 13 additions & 15 deletions website/src/components/ui/use-toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import type { ToastActionElement, ToastProps } from '@/components/ui/toast';

const TOAST_LIMIT = 1;
const TOAST_REMOVE_DELAY = 1000000;
const TOAST_REMOVE_DELAY = 1_000_000;

type ToasterToast = ToastProps & {
id: string;
Expand All @@ -12,12 +12,12 @@ type ToasterToast = ToastProps & {
action?: ToastActionElement;
};

const actionTypes = {
ADD_TOAST: 'ADD_TOAST',
UPDATE_TOAST: 'UPDATE_TOAST',
DISMISS_TOAST: 'DISMISS_TOAST',
REMOVE_TOAST: 'REMOVE_TOAST',
} as const;
type ActionType = {
ADD_TOAST: 'ADD_TOAST';
UPDATE_TOAST: 'UPDATE_TOAST';
DISMISS_TOAST: 'DISMISS_TOAST';
REMOVE_TOAST: 'REMOVE_TOAST';
};

let count = 0;

Expand All @@ -26,8 +26,6 @@ function genId() {
return count.toString();
}

type ActionType = typeof actionTypes;

type Action =
| {
type: ActionType['ADD_TOAST'];
Expand Down Expand Up @@ -61,7 +59,7 @@ const addToRemoveQueue = (toastId: string) => {
toastTimeouts.delete(toastId);
dispatch({
type: 'REMOVE_TOAST',
toastId: toastId,
toastId,
});
}, TOAST_REMOVE_DELAY);

Expand Down Expand Up @@ -90,9 +88,9 @@ export const reducer = (state: State, action: Action): State => {
if (toastId) {
addToRemoveQueue(toastId);
} else {
state.toasts.forEach(toast => {
for (const toast of state.toasts) {
addToRemoveQueue(toast.id);
});
}
}

return {
Expand Down Expand Up @@ -127,9 +125,9 @@ let memoryState: State = { toasts: [] };

function dispatch(action: Action) {
memoryState = reducer(memoryState, action);
listeners.forEach(listener => {
for (const listener of listeners) {
listener(memoryState);
});
}
}

type Toast = Omit<ToasterToast, 'id'>;
Expand Down Expand Up @@ -157,7 +155,7 @@ function toast({ ...props }: Toast) {
});

return {
id: id,
id,
dismiss,
update,
};
Expand Down
37 changes: 19 additions & 18 deletions website/src/routes/publish.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Address } from 'viem';
import { useAccount, useSwitchChain, useWriteContract } from 'wagmi';
import yaml from 'yaml';
import { z } from 'zod';
import { SubgraphImageDropZone } from '@/components/Dropzone';
import { Editor } from '@/components/Editor';
import { SubgraphImageDropZone } from '@/components/dropzone';
import { Editor } from '@/components/editor';
import { Button } from '@/components/ui/button';
import {
Form,
Expand Down Expand Up @@ -38,18 +38,18 @@ import { ipfsHexHash } from '@/lib/utils';
import { zodResolver } from '@hookform/resolvers/zod';
import { useQuery } from '@tanstack/react-query';
import { createLazyFileRoute } from '@tanstack/react-router';
import { L2GNSABI } from '../abis/L2GNS';
import { L2GNSABI } from '../abis/l2gns';
import addresses from '../addresses.json';

const SUPPORTED_CHAIN = {
'arbitrum-one': {
chainId: 42161,
contracts: addresses[42161],
chainId: 42_161,
contracts: addresses[42_161],
subgraph: NETWORK_SUBGRAPH_MAINNET,
},
'arbitrum-sepolia': {
chainId: 421614,
contracts: addresses[421614],
chainId: 421_614,
contracts: addresses[421_614],
subgraph: NETWORK_SUBGRAPH_SEPOLIA,
},
} as const;
Expand All @@ -60,9 +60,9 @@ const getChainInfo = (chain: keyof typeof SUPPORTED_CHAIN) => {

const publishToCopy = (chain: ReturnType<typeof getChainInfo>['chainId']) => {
switch (chain) {
case 42161:
case 42_161:
return 'The Graph Network';
case 421614:
case 421_614:
return 'The Graph Testnet (not meant for production workload)';
}
};
Expand Down Expand Up @@ -390,16 +390,17 @@ function DeploySubgraph({
toast({
description: 'You are all set! You can go back to the CLI and close this window',
});
} catch (err) {
} catch (_) {
const e = contractError;
if (e?.name === 'ContractFunctionExecutionError') {
if (e.cause.name === 'ContractFunctionRevertedError') {
toast({
description: e.cause.message,
variant: 'destructive',
});
return;
}
if (
e?.name === 'ContractFunctionExecutionError' &&
e.cause.name === 'ContractFunctionRevertedError'
) {
toast({
description: e.cause.message,
variant: 'destructive',
});
return;
}

toast({
Expand Down
8 changes: 5 additions & 3 deletions website/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-undef */
/** @type {import('tailwindcss').Config} */
module.exports = {

import animate from 'tailwindcss-animate';

export default {
darkMode: ['class'],
content: [
'./pages/**/*.{ts,tsx}',
Expand Down Expand Up @@ -74,5 +76,5 @@ module.exports = {
},
},
},
plugins: [require('tailwindcss-animate')],
plugins: [animate],
};
2 changes: 1 addition & 1 deletion website/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { TanStackRouterVite } from '@tanstack/router-vite-plugin';
Expand Down

0 comments on commit 2e7a9e9

Please sign in to comment.