Skip to content

Commit

Permalink
feat: enable non-null assertions and ignore existing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vacekj committed Aug 26, 2024
1 parent b56acb7 commit b610604
Show file tree
Hide file tree
Showing 28 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/minifront/src/components/ibc/ibc-in/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const getIconFromAsset = (asset: Asset): string | undefined => {
}

if (asset.images?.length) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const first = asset.images[0]!;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- Image default is "" and thus cannot do nullish-coalescing
return first.svg || first.svg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const assembleAuctionBatch = (
a => a.addressIndex.equals(firstFoundAddressIndex),
batchLimit,
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
return { auctions: filteredBySeqAndAddressIndexAuctions, source: firstFoundAddressIndex! };
};

Expand Down
2 changes: 2 additions & 0 deletions apps/minifront/src/components/swap/duration-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const DurationSlider = () => {
const { duration, setDuration } = useStoreShallow(durationSliderSelector);

const handleChange = (newValue: number[]) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const value = newValue[0]!; // We don't use multiple values in the slider
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const option = DURATION_OPTIONS[value]!;

setDuration(option);
Expand Down
1 change: 1 addition & 0 deletions apps/minifront/src/components/tx-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const TxDetailsErrorBoundary = () => {
export const TxDetails = () => {
const { hash } = useParams<{ hash: string }>();

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
const txInfo = useTransactionInfo(undefined, hash!);

if (
Expand Down
14 changes: 12 additions & 2 deletions apps/minifront/src/components/tx-details/tx-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export const TxViewer = ({ txInfo }: { txInfo?: TransactionInfo }) => {
// use React-Query to invoke custom hooks that call async translators.
const { data: receiverView } = useQuery(
['receiverView', txInfo, option],
() => fetchReceiverView(txInfo!),
() =>
fetchReceiverView(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
txInfo!,
),
{
enabled: option === TxDetailsTab.RECEIVER && !!txInfo,
},
Expand Down Expand Up @@ -80,7 +84,13 @@ export const TxViewer = ({ txInfo }: { txInfo?: TransactionInfo }) => {
</div>
{option === TxDetailsTab.PRIVATE && txInfo && (
<>
<TransactionViewComponent txv={txInfo.view!} metadataFetcher={getMetadata} />
<TransactionViewComponent
txv={
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
txInfo.view!
}
metadataFetcher={getMetadata}
/>
<div className='mt-8'>
<div className='text-xl font-bold'>Raw JSON</div>
<JsonViewer jsonObj={txInfo.toJson({ typeRegistry }) as Jsonified<TransactionInfo>} />
Expand Down
1 change: 1 addition & 0 deletions apps/minifront/src/fetchers/balances/by-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const groupByAsset = (acc: ValueView[], curr: BalancesResponse): ValueVie
throw new Error('No amount in value view');
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
const grouping = acc.find(v => hasMatchingAssetId(v, curr.balanceView!));

if (grouping) {
Expand Down
1 change: 1 addition & 0 deletions apps/minifront/src/state/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const build = async (
case 'buildProgress':
break;
case 'complete':
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
return status.value.transaction!;
default:
console.warn(`unknown ${buildFn.name} status`, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const parseRevisionNumberFromChainId = (chainId: string): bigint => {
return 0n;
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const numStr = chainId.split('-').pop()!;
return BigInt(numStr);
};
Expand Down
1 change: 1 addition & 0 deletions apps/minifront/src/state/ibc-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export const filterBalancesPerChain = (
}
return chain?.channelId === match.channel;
})
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
.map(m => m.penumbraAssetId!);

const assetIdsToCheck = [...assetsWithMatchingChannel];
Expand Down
1 change: 1 addition & 0 deletions apps/minifront/src/state/staking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ const assembleUndelegateRequest = ({
}: StakingSlice) => {
const delegation = delegationsByAccount
.get(account)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
?.find(delegation => isDelegationTokenForValidator(delegation, validatorInfo!));
if (!delegation) {
throw new Error('Tried to assemble undelegate request from account with no delegation tokens');
Expand Down
1 change: 1 addition & 0 deletions apps/minifront/src/state/swap/instant-swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const calculatePriceImpact = (swapExec?: SwapExecution): number | undefined => {
// Get the price in the best execution trace
const inputAssetId = getAssetIdFromValue(swapExec.input);
const outputAssetId = getAssetIdFromValue(swapExec.output);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const bestTrace = swapExec.traces[0]!;
const bestInputAmount = getMatchingAmount(bestTrace.value, inputAssetId);
const bestOutputAmount = getMatchingAmount(bestTrace.value, outputAssetId);
Expand Down
3 changes: 1 addition & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ export default tseslint.config(
name: 'custom:typescript-wishlist-improvements',
files: ['**/*.@(ts|tsx)'],
rules: {
// enabled by tseslint strictTypeChecked. large diff
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-non-null-assertion': 'error',

// '@typescript-eslint/no-redeclare': 'error',
// '@typescript-eslint/no-shadow': 'error',
Expand Down
2 changes: 2 additions & 0 deletions packages/bech32m/src/test/util/corrupt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const corruptBech32 = (goodBech32: string, change?: { i: number; c: strin
export const generateInvalid = (okBytes: Uint8Array, okString: string, innerName = 'inner') => {
const prefix = okString.slice(0, okString.lastIndexOf('1'));
return {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
longBytes: { [innerName]: new Uint8Array([...okBytes, okBytes[0]!]) },
shortBytes: { [innerName]: okBytes.slice(1) },
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
longString: bech32m.encode(prefix, bech32m.toWords([...okBytes, okBytes[0]!]), Infinity),
shortString: bech32m.encode(prefix, bech32m.toWords(okBytes.slice(1)), Infinity),
corruptString: corruptBech32(okString),
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export class PenumbraClient {
/** Assert an attached provider. */
private assertAttached(): PenumbraClientAttachment {
assertProviderRecord(this.attached?.origin);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify
return this.attached!;
}

Expand Down
1 change: 1 addition & 0 deletions packages/crypto/src/mnemonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export const validateSeedPhrase = (seedPhrase: string[]): boolean => {
};

export const isInWordList = (word: string): boolean => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
return wordlists['EN']!.includes(word);
};
1 change: 1 addition & 0 deletions packages/perspective/src/translators/action-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const asPublicActionView: Translator<ActionView> = actionView => {
// to err on communicating private data as public than the other way around
// TODO: Do proper audit of what data for each action is public
default:
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
return actionView!;
}
};
Expand Down
2 changes: 2 additions & 0 deletions packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ export class BlockProcessor implements BlockProcessorInterface {
await this.identifyNewAssets(flush.newNotes);

for (const spendableNoteRecord of flush.newNotes) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
recordsByCommitment.set(spendableNoteRecord.noteCommitment!, spendableNoteRecord);
}
for (const swapRecord of flush.newSwaps) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
recordsByCommitment.set(swapRecord.swapCommitment!, swapRecord);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FullViewingKey } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/ke
* Add more assertions to this function as needed.
*/
export const assertValidAuthorizeRequest = (req: AuthorizeRequest, fvk: FullViewingKey): void =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
assertSwapClaimAddressesBelongToCurrentUser(req.plan!, address =>
isControlledAddress(fvk, address),
);
1 change: 1 addition & 0 deletions packages/services/src/view-service/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class BalancesAggregator {

this.accounts[accountNumber][assetIdBase64] ??= await this.initializeBalResponse(n);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const valueView = this.accounts[accountNumber][assetIdBase64].balanceView!;
this.aggregateAmount(valueView, n);
await this.aggregateEquivalentValues(valueView, n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const transactionPlanner: Impl['transactionPlanner'] = async (req, ctx) =

// Query IndexedDB directly to check for the existence of staking token
const nativeToken = await indexedDb.hasTokenBalance(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
req.source!.account,
indexedDb.stakingTokenAssetId,
);
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const InnerBase64Schema = z.object({ inner: Base64StringSchema });
export const base64ToUint8Array = (base64: string): Uint8Array => {
const validated = globalThis.__DEV__ ? Base64StringSchema.parse(base64) : base64;
const binString = atob(validated);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
return Uint8Array.from(binString, byte => byte.codePointAt(0)!);
};

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const hexToUint8Array = (hexString: string): Uint8Array => {
}

// Split the string into pairs of characters
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const hexPairs = hexString.match(/.{1,2}/g)!;

// Map each hexadecimal pair to the corresponding integer and create a Uint8Array from it
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/components/ui/candlestick-plot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ export const CandlesticksTooltip = ({
return () => ac.abort('Abort tooltip date query');
}, [data, getBlockDate]);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const endBase = endMetadata.denomUnits.filter(d => !d.exponent)[0]!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const startBase = startMetadata.denomUnits.filter(d => !d.exponent)[0]!;
return (
<Tooltip
Expand Down
1 change: 1 addition & 0 deletions packages/ui/components/ui/identicon/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const generateGradient = (str: string) => {
const tetrad = c.tetrad(); // 4 colors spaced around the color wheel, the first being the input
const secondColorOptions = tetrad.slice(1);
const index = hash % 3;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const toColor = secondColorOptions[index]!.toHexString();

return {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/components/ui/logo/animation-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const renderPlot = (
export const initializePlotsArr = (noiseIntensityFactor: number): Plot[] => {
const plots: Plot[] = [];
for (let i = 0; i < numPlots; i++) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const path = document.getElementById(`plot${i + 1}`)!;
const noiseIntensity = noiseIntensityFactor * (i / (numPlots - 1)); // noise intensity control for each ring as they move towards the edge
const initialValue = i * plotGap; // As the loop works itself towards the outer plots, the initialValue is increased to create a larger distance from the centre for each plot. This basically denotes the base radius of each plot.
Expand Down
1 change: 1 addition & 0 deletions packages/ui/components/ui/tx/memo-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const MemoViewComponent = ({ memo: { memoView } }: { memo: MemoView }) =>
<div className='flex flex-col gap-4'>
<ActionDetails>
<ActionDetails.Row label='Return Address'>
{/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify not using '?' operator */}
<AddressViewComponent view={memoView.value.plaintext!.returnAddress} />
</ActionDetails.Row>
<ActionDetails.Row label='Memo Text'>
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/Identicon/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const generateGradient = (str: string) => {
const tetrad = c.tetrad(); // 4 colors spaced around the color wheel, the first being the input
const secondColorOptions = tetrad.slice(1);
const index = hash % 3;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const toColor = secondColorOptions[index]!.toHexString();

return {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/SegmentedControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const SegmentedControl = <ValueType extends ToStringable>({

const handleChange = useCallback(
(optionValue: string) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: justify non-null assertion
const selected = options.find(option => option.value.toString() === optionValue)!;
onChange(selected.value);
},
Expand Down

0 comments on commit b610604

Please sign in to comment.