Skip to content

Commit

Permalink
Prettier Import Sort Plugin (MystenLabs#13957)
Browse files Browse the repository at this point in the history
## Description 

We currently use `import/order` to sort imports. I hate this for a
couple reasons:

- This feels like formatting, which is what prettier is for. ESLint is
for catching functional or code issues, not formatting.
- I don't run ESLint auto-fixing automatically, and IMO folks generally
shouldn't need to because it really shouldn't be catching much that's
super auto-fixable, because only formatting is easily auto-fixable
without supervision.
- I want to move to a world where we don't have anything yell at you
locally for prettier because ideally you just set that up and don't
think about it, and it can fail in CI, but ESLint / TS will yell at you
in your editor, keeping your signal to noise ratio high, which is good.
- I just personally hate import sorting and this will at least make me
think about it less.

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
Jordan-Mysten authored Sep 25, 2023
1 parent e5235d2 commit 05eed92
Show file tree
Hide file tree
Showing 665 changed files with 2,301 additions and 2,195 deletions.
44 changes: 0 additions & 44 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,6 @@ module.exports = {
{
files: ['apps/explorer/**/*'],
rules: {
'import/order': [
'warn',
{
groups: [['builtin', 'external'], ['internal', 'parent', 'sibling', 'index'], 'type'],
pathGroups: [
{
pattern: '{.,..}/**/*.css',
group: 'type',
position: 'after',
},
{
pattern: '~/**',
group: 'internal',
},
],
'newlines-between': 'always',
alphabetize: { order: 'asc' },
warnOnUnassignedImports: true,
},
],
'import/no-duplicates': ['error'],
'import/no-anonymous-default-export': 'off',
'@typescript-eslint/consistent-type-imports': [
Expand Down Expand Up @@ -220,30 +200,6 @@ module.exports = {
files: ['apps/wallet/**/*'],
rules: {
'react/display-name': 'off',
'import/order': [
'warn',
{
groups: [['builtin', 'external'], ['internal', 'parent', 'sibling', 'index'], 'type'],
pathGroups: [
{
pattern: '{.,..,_*,*}/**/*.?(s)css',
group: 'type',
position: 'after',
},
{
pattern: '_*',
group: 'internal',
},
{
pattern: '_*/**',
group: 'internal',
},
],
pathGroupsExcludedImportTypes: ['builtin', 'object', 'type'],
alphabetize: { order: 'asc' },
warnOnUnassignedImports: true,
},
],
'import/no-duplicates': ['error'],
'@typescript-eslint/consistent-type-imports': [
'error',
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/hooks/__tests__/useFormatCoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

import BigNumber from 'bignumber.js';
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';

import { formatBalance, CoinFormat } from '../useFormatCoin';
import { CoinFormat, formatBalance } from '../useFormatCoin';

const SUI_DECIMALS = 9;

Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/hooks/nameService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useQuery } from '@tanstack/react-query';
import { useSuiClient } from '@mysten/dapp-kit';
import { useFeatureIsOn } from '@growthbook/growthbook-react';
import { useSuiClient } from '@mysten/dapp-kit';
import { useQuery } from '@tanstack/react-query';

const SUI_NS_FEATURE_FLAG = 'suins';

Expand Down
1 change: 1 addition & 0 deletions apps/core/src/hooks/useCookieConsentBanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useEffect } from 'react';

import { PersistableStorage } from '../utils/persistableStorage';
import { useProductAnalyticsConfig } from './useProductAnalyticsConfig';

Expand Down
3 changes: 2 additions & 1 deletion apps/core/src/hooks/useFormatCoin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { CoinMetadata } from '@mysten/sui.js/client';
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
import BigNumber from 'bignumber.js';
import { useMemo } from 'react';

import { formatAmount } from '../utils/formatAmount';
import { useSuiClient } from '@mysten/dapp-kit';

type FormattedCoin = [
formattedBalance: string,
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { useSuiClient } from '@mysten/dapp-kit';
import { PaginatedCoins } from '@mysten/sui.js/client';
import { UseInfiniteQueryResult, useInfiniteQuery } from '@tanstack/react-query';
import { useInfiniteQuery, UseInfiniteQueryResult } from '@tanstack/react-query';

const MAX_COINS_PER_REQUEST = 10;

Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/hooks/useGetDynamicFields.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useInfiniteQuery } from '@tanstack/react-query';
import { normalizeSuiAddress } from '@mysten/sui.js/utils';
import { useSuiClient } from '@mysten/dapp-kit';
import { normalizeSuiAddress } from '@mysten/sui.js/utils';
import { useInfiniteQuery } from '@tanstack/react-query';

const MAX_PAGE_SIZE = 10;

Expand Down
7 changes: 4 additions & 3 deletions apps/core/src/hooks/useGetKioskContents.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { KIOSK_ITEM, KioskClient, KioskItem, KioskOwnerCap, Network } from '@mysten/kiosk';
import { useQuery } from '@tanstack/react-query';
import { ORIGINBYTE_KIOSK_OWNER_TOKEN, getKioskIdFromOwnerCap } from '../utils/kiosk';
import { SuiClient } from '@mysten/sui.js/src/client';
import { useSuiClient } from '@mysten/dapp-kit';
import { useQuery } from '@tanstack/react-query';

import { getKioskIdFromOwnerCap, ORIGINBYTE_KIOSK_OWNER_TOKEN } from '../utils/kiosk';

export enum KioskTypes {
SUI = 'sui',
Expand Down
3 changes: 2 additions & 1 deletion apps/core/src/hooks/useGetTransferAmount.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { useMemo } from 'react';

import { getTotalGasUsed } from '../utils/transaction';

export function useGetTransferAmount(txnData: SuiTransactionBlockResponse) {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetValidatorsApy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useLatestSuiSystemState, useSuiClient } from '@mysten/dapp-kit';
import { useQuery } from '@tanstack/react-query';

import { roundFloat } from '../utils/roundFloat';
import { useSuiClient, useLatestSuiSystemState } from '@mysten/dapp-kit';

// recentEpochRewards is list of the last 30 epoch rewards for a specific validator
// APY_e = (1 + epoch_rewards / stake)^365-1
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetValidatorsEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { useSuiClient } from '@mysten/dapp-kit';
import { type EventId, SuiEvent } from '@mysten/sui.js/client';
import { SuiEvent, type EventId } from '@mysten/sui.js/client';
import { useQuery } from '@tanstack/react-query';

type GetValidatorsEvent = {
Expand Down
5 changes: 3 additions & 2 deletions apps/core/src/hooks/useMultiGetObjects.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { SuiObjectDataOptions } from '@mysten/sui.js/src/client';
import { useQuery } from '@tanstack/react-query';

import { chunkArray } from '../utils/chunkArray';
import { SuiObjectDataOptions } from '@mysten/sui.js/src/client';
import { useSuiClient } from '@mysten/dapp-kit';

export function useMultiGetObjects(
ids: string[],
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useOnScreen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useState, useEffect, MutableRefObject } from 'react';
import { MutableRefObject, useEffect, useState } from 'react';

export const useOnScreen = (elementRef: MutableRefObject<Element | null>) => {
const [isIntersecting, setIsIntersecting] = useState(false);
Expand Down
1 change: 1 addition & 0 deletions apps/core/src/hooks/useSuiCoinData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useQuery } from '@tanstack/react-query';

import { useAppsBackend } from './useAppsBackend';

// TODO: We should consider using tRPC or something for apps-backend
Expand Down
8 changes: 4 additions & 4 deletions apps/core/src/hooks/useTransactionSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
import { useMemo } from 'react';

import { getBalanceChangeSummary } from '../utils/transaction/getBalanceChangeSummary';
import { getGasSummary } from '../utils/transaction/getGasSummary';
import { getLabel } from '../utils/transaction/getLabel';
import {
SuiObjectChangeWithDisplay,
getObjectChangeSummary,
SuiObjectChangeWithDisplay,
} from '../utils/transaction/getObjectChangeSummary';
import { getLabel } from '../utils/transaction/getLabel';
import { getGasSummary } from '../utils/transaction/getGasSummary';
import { useMultiGetObjects } from './useMultiGetObjects';
import { getObjectDisplayLookup } from '../utils/transaction/getObjectDisplayLookup';
import { useMultiGetObjects } from './useMultiGetObjects';

export function useTransactionSummary({
transaction,
Expand Down
3 changes: 1 addition & 2 deletions apps/core/src/hooks/useZodForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';

import type { UseFormProps } from 'react-hook-form';
import type { ZodSchema, TypeOf } from 'zod';
import type { TypeOf, ZodSchema } from 'zod';

interface UseZodFormProps<T extends ZodSchema<any>> extends UseFormProps<TypeOf<T>> {
schema: T;
Expand Down
1 change: 1 addition & 0 deletions apps/core/src/utils/getRefGasPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { SuiValidatorSummary } from '@mysten/sui.js/client';

import { calculateStakeShare } from './calculateStakeShare';

const REF_THRESHOLD = 66.67;
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/kiosk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { SuiObjectData, SuiObjectResponse } from '@mysten/sui.js/client';
import { KIOSK_OWNER_CAP } from '@mysten/kiosk';
import { SuiObjectData, SuiObjectResponse } from '@mysten/sui.js/client';

export const ORIGINBYTE_KIOSK_MODULE =
'0x95a441d389b07437d00dd07e0b6f05f513d7659b13fd7c5d3923c7d9d847199b::ob_kiosk';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/transaction/getBalanceChangeSummary.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import {
type ObjectOwner,
type DryRunTransactionBlockResponse,
type ObjectOwner,
type SuiTransactionBlockResponse,
} from '@mysten/sui.js/client';
import { normalizeSuiObjectId, parseStructTag } from '@mysten/sui.js/utils';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/transaction/getGasSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import {
DryRunTransactionBlockResponse,
GasCostSummary,
SuiTransactionBlockResponse,
SuiGasData,
SuiTransactionBlockResponse,
TransactionEffects,
} from '@mysten/sui.js/client';

Expand Down
9 changes: 5 additions & 4 deletions apps/core/src/utils/transaction/getObjectChangeSummary.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import {
SuiObjectChangeTransferred,
DisplayFieldsResponse,
SuiObjectChange,
SuiObjectChangeCreated,
SuiObjectChangeDeleted,
SuiObjectChangeMutated,
SuiObjectChangePublished,
SuiObjectChange,
DisplayFieldsResponse,
SuiObjectChangeDeleted,
SuiObjectChangeTransferred,
SuiObjectChangeWrapped,
} from '@mysten/sui.js/client';

import { groupByOwner } from './groupByOwner';
import { SuiObjectChangeTypes } from './types';

Expand Down
1 change: 1 addition & 0 deletions apps/core/src/utils/transaction/getObjectDisplayLookup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { DisplayFieldsResponse, SuiObjectResponse } from '@mysten/sui.js/client';

import { hasDisplayData } from '../hasDisplayData';

export function getObjectDisplayLookup(objects: SuiObjectResponse[] = []) {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import { type Config } from 'tailwindcss';
import { fontFamily } from 'tailwindcss/defaultTheme';
import colors from 'tailwindcss/colors';
import { fontFamily } from 'tailwindcss/defaultTheme';

/** The minimum line height that text should use to avoid clipping and overflow scrolling */
const MIN_LINE_HEIGHT = '1.13';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { defineConfig } from 'vite';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import { defineConfig } from 'vite';

process.env.VITE_VERCEL_ENV = process.env.VERCEL_ENV || 'development';

Expand Down
5 changes: 2 additions & 3 deletions apps/explorer/tests/utils/localnet.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// eslint-disable-next-line import/order
import 'tsconfig-paths/register';

import { SuiClient, getFullnodeUrl } from '@mysten/sui.js/client';
import { type Keypair } from '@mysten/sui.js/cryptography';
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
import { TransactionBlock } from '@mysten/sui.js/transactions';
import 'tsconfig-paths/register';
// eslint-disable-next-line import/order

const addressToKeypair = new Map<string, Keypair>();

Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { CheckFill16, Search16 } from '@mysten/icons';
import type { Meta, StoryObj } from '@storybook/react';

import { Button } from './Button';
import { CheckFill16, Search16 } from '@mysten/icons';

const meta = {
component: Button,
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { Slot } from '@radix-ui/react-slot';
import { cva, type VariantProps } from 'class-variance-authority';
import { ButtonHTMLAttributes, forwardRef, type ReactNode } from 'react';

import { LoadingIndicator } from './LoadingIndicator';
import { Slot } from '@radix-ui/react-slot';

const buttonStyles = cva(['inline-flex flex-nowrap items-center justify-center gap-2 relative'], {
variants: {
Expand Down
10 changes: 5 additions & 5 deletions apps/ui/src/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

import { Command } from 'cmdk';
import {
type ComponentProps,
type ReactNode,
type RefObject,
createContext,
useCallback,
useContext,
useEffect,
useRef,
useState,
type ComponentProps,
type ReactNode,
type RefObject,
} from 'react';

import { Text } from './Text';
import { LoadingIndicator } from './LoadingIndicator';
import { useOnClickOutside } from './hooks/useOnClickOutside';
import { LoadingIndicator } from './LoadingIndicator';
import { Text } from './Text';

export type ComboboxItem = {
value: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/IconButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { X12 } from '@mysten/icons';
import { type StoryObj, type Meta } from '@storybook/react';
import { type Meta, type StoryObj } from '@storybook/react';

import { IconButton } from './IconButton';

Expand Down
Loading

0 comments on commit 05eed92

Please sign in to comment.