Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint): enable 'typescript-eslint/no-unnecessary-type-assertion' #11284

Merged
merged 15 commits into from
Aug 16, 2024
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ module.exports = {
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const createCache = (

try {
await Promise.race([
(result = client.del(cacheKey as string)),
(result = client.del(cacheKey)),
wait(timeout).then(() => {
throw new CacheTimeoutError()
}),
Expand Down
6 changes: 2 additions & 4 deletions packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,9 @@ export class DbAuthHandler<
}

// check if password is valid using signup criteria
;(this.options.signup as SignupFlowOptions).passwordValidation?.(
password as string,
)
;(this.options.signup as SignupFlowOptions).passwordValidation?.(password)

let user = await this._findUserByToken(resetToken as string)
let user = await this._findUserByToken(resetToken)
const [hashedPassword] = hashPassword(password, {
salt: user.salt,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function getFirebaseAuth(customProviderHooks?: {
) => (rolesToCheck: string | string[]) => boolean
}) {
const { useAuth, AuthProvider } = createAuth(
firebaseMockClient as FirebaseClient,
firebaseMockClient,
customProviderHooks,
)
const { result } = renderHook(() => useAuth(), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function getSuperTokensAuth(customProviderHooks?: {
) => (rolesToCheck: string | string[]) => boolean
}) {
const { useAuth, AuthProvider } = createAuth(
superTokensMockClient as SuperTokensAuth,
superTokensMockClient,
customProviderHooks,
)
const { result } = renderHook(() => useAuth(), {
Expand Down
5 changes: 1 addition & 4 deletions packages/babel-config/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ export const getPathsFromTypeScriptConfig = (
continue
}
const aliasKey = key.replace('/*', '')
const aliasValue = path.join(
absoluteBase,
(value as string)[0].replace('/*', ''),
)
const aliasValue = path.join(absoluteBase, value[0].replace('/*', ''))
Comment on lines -166 to +165
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this highlights that the type definition above is a little wrong?

type CompilerOptionsForPaths = {
  compilerOptions: { baseUrl: string; paths: string }
}

I might have thought that paths would be a record of strings and not just a string itself?


pathsObj[aliasKey] = aliasValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function ({ types: t }: { types: typeof types }): PluginObj {
let name
if (declaration.type === 'VariableDeclaration') {
const id = declaration.declarations[0].id as types.Identifier
name = id.name as string
name = id.name
}
if (declaration.type === 'FunctionDeclaration') {
name = declaration?.id?.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { NodePath, PluginObj, PluginPass, types } from '@babel/core'

// This extracts the options passed to the graphql function and stores them in an exported variable so they can be imported elsewhere.

const exportVariableName = '__rw_graphqlOptions' as const
const exportVariableName = '__rw_graphqlOptions'

function optionsConstNode(
t: typeof types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const getCellMetadata = (p: string) => {
const id = declaration.declarations[0].id as types.Identifier

namedExports.push({
name: id.name as string,
name: id.name,
type: 'variable',
})
} else if (declaration.type === 'FunctionDeclaration') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function wrapExportNamedDeclaration(
if (param.type === 'ObjectPattern') {
const objectProperties = param.properties.filter(
(p) => p.type === 'ObjectProperty',
) as types.ObjectProperty[]
)
originalFunctionArgumentsWithoutDefaults.push(
t.objectExpression(
objectProperties.map((p) => {
Expand All @@ -122,7 +122,7 @@ function wrapExportNamedDeclaration(
} else if (param.left.type === 'ObjectPattern') {
const objectProperties = param.left.properties.filter(
(p) => p.type === 'ObjectProperty',
) as types.ObjectProperty[]
)
originalFunctionArgumentsWithoutDefaults.push(
t.objectExpression(
objectProperties.map((p) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/testLib/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const getNamedExports = (ast: types.Node): NamedExports[] => {
if (declaration.type === 'VariableDeclaration') {
const id = declaration.declarations[0].id as types.Identifier
namedExports.push({
name: id.name as string,
name: id.name,
type: 'variable',
})
} else if (declaration.type === 'FunctionDeclaration') {
Expand Down Expand Up @@ -240,7 +240,7 @@ const getFields = (field: FieldNode): any => {
node.selectionSet?.selections.forEach((subField) => {
switch (subField.kind) {
case Kind.FIELD:
obj[field.name.value].push(getFields(subField as FieldNode))
obj[field.name.value].push(getFields(subField))
break
case Kind.FRAGMENT_SPREAD:
// TODO: Maybe this will also be needed, right now it's accounted for to not crash in the tests
Expand Down
4 changes: 2 additions & 2 deletions packages/codemods/src/lib/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const getNamedExports = (ast: types.Node): NamedExports[] => {
if (declaration.type === 'VariableDeclaration') {
const id = declaration.declarations[0].id as types.Identifier
namedExports.push({
name: id.name as string,
name: id.name,
type: 'variable',
})
} else if (declaration.type === 'FunctionDeclaration') {
Expand Down Expand Up @@ -240,7 +240,7 @@ const getFields = (field: FieldNode): any => {
node.selectionSet?.selections.forEach((subField) => {
switch (subField.kind) {
case Kind.FIELD:
obj[field.name.value].push(getFields(subField as FieldNode))
obj[field.name.value].push(getFields(subField))
break
case Kind.FRAGMENT_SPREAD:
// TODO: Maybe this will also be needed, right now it's accounted for to not crash in the tests
Expand Down
2 changes: 1 addition & 1 deletion packages/context/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const getAsyncStoreInstance = () => {
if (!CONTEXT_STORAGE) {
CONTEXT_STORAGE = new AsyncLocalStorage<Map<string, GlobalContext>>()
}
return CONTEXT_STORAGE as AsyncLocalStorage<Map<string, GlobalContext>>
return CONTEXT_STORAGE
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/service-type-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const serviceTypeAnnotations = createRule({
}

// Switch from the estree type to the typescript-eslint type
const tsID = vd.id as TSESTree.Identifier
const tsID = vd.id

// If there's no type annotation, then we should add one
if (!tsID.typeAnnotation) {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-server/src/globalContextStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const getAsyncStoreInstance = () => {
if (!CONTEXT_STORAGE) {
CONTEXT_STORAGE = new AsyncLocalStorage<Map<string, GlobalContext>>()
}
return CONTEXT_STORAGE as AsyncLocalStorage<Map<string, GlobalContext>>
return CONTEXT_STORAGE
}
4 changes: 2 additions & 2 deletions packages/graphql-server/src/plugins/useRedwoodLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const useRedwoodLogger = (
})
},
onParse({ params }) {
const options = params.options as any
const options = params.options

const envelopLogger = childLogger.child({
...options,
Expand All @@ -232,7 +232,7 @@ export const useRedwoodLogger = (
}
},
onValidate({ params }) {
const options = params.options as any
const options = params.options

const envelopLogger = childLogger.child({
...options,
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const getNamedExports = (ast: types.Node): NamedExports[] => {
if (declaration.type === 'VariableDeclaration') {
const id = declaration.declarations[0].id as types.Identifier
namedExports.push({
name: id.name as string,
name: id.name,
type: 'variable',
location: {
line: id.loc?.start.line ?? 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/src/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const getFields = (field: FieldNode): any => {
node.selectionSet?.selections.forEach((subField) => {
switch (subField.kind) {
case Kind.FIELD:
obj[field.name.value].push(getFields(subField as FieldNode))
obj[field.name.value].push(getFields(subField))
break
case Kind.FRAGMENT_SPREAD:
// TODO: Maybe this will also be needed, right now it's accounted for to not crash in the tests
Expand Down
4 changes: 2 additions & 2 deletions packages/prerender/src/babelPlugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import mime from 'mime-types'
// Not sure if possible in actually running builds
export function convertToDataUrl(assetPath: string) {
try {
const base64AssetContents = fs.readFileSync(assetPath as string, 'base64')
const mimeType = mime.lookup(assetPath as string)
const base64AssetContents = fs.readFileSync(assetPath, 'base64')
const mimeType = mime.lookup(assetPath)
return `data:${mimeType};base64,${base64AssetContents}`
} catch {
console.warn(`Could not read file ${assetPath} for conversion to data uri`)
Expand Down
7 changes: 2 additions & 5 deletions packages/router/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ const coreParamTypes: Record<string, ParamType> = {
},
}

type SupportedRouterParamTypes = keyof typeof coreParamTypes

/**
* Determine if the given route is a match for the given pathname. If so,
* extract any named params and return them in an object.
Expand Down Expand Up @@ -145,8 +143,7 @@ export function matchPath(
const params = providedParams.reduce<Record<string, unknown>>(
(acc, value, index) => {
const [name, transformName] = routeParamsDefinition[index]
const typeInfo =
allParamTypes[transformName as SupportedRouterParamTypes]
const typeInfo = allParamTypes[transformName]

let transformedValue: string | unknown = value
if (typeof typeInfo?.parse === 'function') {
Expand Down Expand Up @@ -192,7 +189,7 @@ export function getRouteRegexAndParams(
// /recipe/{id} -> /recipe/([^/$1*]+)
for (const [_name, type, match] of routeParams) {
// `undefined` matcher if `type` is not supported
const matcher = allParamTypes[type as SupportedRouterParamTypes]?.match
const matcher = allParamTypes[type]?.match

// Get the regex as a string, or default regexp if `match` is not specified
const typeRegexp = matcher?.source || '[^/]+'
Expand Down
2 changes: 1 addition & 1 deletion packages/structure/src/ide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export abstract class FileNode extends BaseNode {
if (typeof this.text === 'undefined') {
throw new Error('undefined file ' + this.filePath)
}
return createTSMSourceFile_cached(this.filePath, this.text!)
return createTSMSourceFile_cached(this.filePath, this.text)
}
@lazy() get basenameNoExt() {
return basenameNoExt(this.filePath)
Expand Down
14 changes: 7 additions & 7 deletions packages/structure/src/model/RWRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class RWRoute extends BaseNode {
}
if (tsm.Node.isJsxAttribute(a)) {
const init = a.getInitializer()
if (tsm.Node.isStringLiteral(init!)) {
if (tsm.Node.isStringLiteral(init)) {
return init.getLiteralValue()
}
}
Expand Down Expand Up @@ -189,9 +189,9 @@ export class RWRoute extends BaseNode {
}
if (tsm.Node.isJsxAttribute(a)) {
const init = a.getInitializer()
if (tsm.Node.isJsxExpression(init!)) {
if (tsm.Node.isJsxExpression(init)) {
const expr = init.getExpression()
if (tsm.Node.isIdentifier(expr!)) {
if (tsm.Node.isIdentifier(expr)) {
return expr
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ export class RWRoute extends BaseNode {
}
if (tsm.Node.isJsxAttribute(a)) {
const init = a.getInitializer()
if (tsm.Node.isStringLiteral(init!)) {
if (tsm.Node.isStringLiteral(init)) {
return init
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ export class RWRoute extends BaseNode {
}
if (this.isPrivate && this.isNotFound) {
yield err(
this.jsxNode!,
this.jsxNode,
"The 'Not Found' page cannot be within a <PrivateSet> or a <Private> tag",
)
}
Expand Down Expand Up @@ -369,7 +369,7 @@ export class RWRoute extends BaseNode {
// If it is explicitly set to true
// e.g. <Route prerender={true} />
return tsm.Node.isTrueLiteral(init.getExpression())
} else if (tsm.Node.isStringLiteral(init!)) {
} else if (tsm.Node.isStringLiteral(init)) {
// If its using the incorrect string form, we're accepting it as true
// e.g. <Route prerender="true" />
const literalValue = init.getLiteralValue()
Expand All @@ -387,7 +387,7 @@ export class RWRoute extends BaseNode {
}
if (tsm.Node.isJsxAttribute(a)) {
const init = a.getInitializer()
if (tsm.Node.isStringLiteral(init!)) {
if (tsm.Node.isStringLiteral(init)) {
return init.getLiteralValue()
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/structure/src/model/util/advanced_path_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export function advanced_path_parser(route: string) {
const paramTypeRanges: [number, number][] = []
for (const param of route.matchAll(/\{([^}]+)\}/g)) {
const [paramName, paramType] = param[1].split(':')
const index = param.index! + 1
const index = param.index + 1
paramRanges.push([index, index + paramName.length])
if (paramType) {
const typeIndex = index + paramName.length + 2
paramTypeRanges.push([typeIndex, typeIndex + paramType.length])
}
}
const punctuationIndexes = [...route.matchAll(/[{}:]/g)].map((x) => x.index!)
const slashIndexes = [...route.matchAll(/[\/]/g)].map((x) => x.index!)
const punctuationIndexes = [...route.matchAll(/[{}:]/g)].map((x) => x.index)
const slashIndexes = [...route.matchAll(/[\/]/g)].map((x) => x.index)
return { punctuationIndexes, slashIndexes, paramRanges, paramTypeRanges }
}
2 changes: 1 addition & 1 deletion packages/structure/src/x/URL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function URL_toFile(uriOrFilePath: string, sep = path_sep): string {
if (!isAbsolute(p)) {
throw new Error('absolute path expected: ' + p)
}
return p!
return p
}

const FILE_SCHEME = 'file://'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/devFeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async function createServer() {
const routeHandler = await createReactStreamingHandler(
{
routes,
clientEntryPath: rwPaths.web.entryClient as string,
clientEntryPath: rwPaths.web.entryClient,
getStylesheetLinks: (route) => {
// In dev route is a RouteSpec, with additional properties
return getCssLinks({ rwPaths, route: route as RouteSpec, vite })
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/rsc/rscBuildEntriesFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function rscBuildEntriesMappings(
serverBuildOutput.find(
(item) =>
'moduleIds' in item &&
item.moduleIds.includes(clientEntryFiles[name] as string),
item.moduleIds.includes(clientEntryFiles[name]),
)?.fileName

if (entryFile) {
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function rscBuildEntriesMappings(
serverBuildOutput.find(
(item) =>
'moduleIds' in item &&
item.moduleIds.includes(clientEntryFiles[name] as string),
item.moduleIds.includes(clientEntryFiles[name]),
)?.fileName

if (entryFile) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/rsc/rscStudioHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const processRenderRscStream = async (

pipeable.on('end', () => {
const resultBuffer = Buffer.concat(chunks)
const resultString = resultBuffer.toString('utf-8') as string
const resultString = resultBuffer.toString('utf-8')
resolve(resultString)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/Metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const propToMetaTag = (
// plain text
const attributes = {
[options['attr']]: parentKey,
content: parentValue as string,
content: parentValue,
}
return <meta {...attributes} />
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/cell/createSuspendingCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function createSuspendingCell<
function SuspendingSuccess(props: SuspendingSuccessProps) {
const { queryRef, suspenseQueryResult, userProps } = props
const { data, networkStatus } = useReadQuery<DataObject>(queryRef)
const afterQueryData = afterQuery(data as DataObject)
const afterQueryData = afterQuery(data)

const queryResultWithNetworkStatus: SuspenseCellQueryResult = {
...suspenseQueryResult,
Expand Down
Loading
Loading