Skip to content

Commit

Permalink
apply @typescript-eslint/no-unnecessary-type-assertion and @typescrip…
Browse files Browse the repository at this point in the history
…t-eslint/no-unnecessary-type-constraint
  • Loading branch information
dcousens committed Nov 14, 2023
1 parent ed1f885 commit b136fd6
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 115 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* eslint-env node */
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: true
},
plugins: ['@typescript-eslint'],
root: true,
overrides: [{
files: ['*.js', '*.jsx', '*.ts', '*.tsx'],
}],
rules: {
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
}
}
2 changes: 1 addition & 1 deletion docs/components/docs/DocumentEditorDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function objToShorthand<
Obj extends Record<string, undefined | true | readonly any[] | Record<string, any>>
> (obj: Obj): Obj | true | undefined {
const values = Object.values(obj)
let state: (typeof values)[number] = values[0]!
let state: (typeof values)[number] = values[0]
for (const val of values) {
if (val !== state || (val !== undefined && val !== true)) {
return obj
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MyDocument extends Document {
styles: [
<React.Fragment key="1">
{initialProps.styles}
{data!.styles.map((data, i) => (
{data.styles.map((data, i) => (
<style
key={i}
data-emotion={`${data.key} ${data.ids.join(' ')}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function ItemForm ({
})
})
const labelFieldValue = list.isSingleton ? list.label : state.item.data?.[list.labelField]
const itemId = state.item.data?.id!
const itemId = state.item.data?.id
const hasChangedFields = !!changedFields.size
usePreventNavigation(useMemo(() => ({ current: hasChangedFields }), [hasChangedFields]))
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export function Cards ({
})
const itemsBeingEdited = new Set(value.itemsBeingEdited)
itemsBeingEdited.delete(id)
onChange!({
onChange({
...value,
itemsBeingEdited,
})
Expand All @@ -185,7 +185,7 @@ export function Cards ({
onCancel={() => {
const itemsBeingEdited = new Set(value.itemsBeingEdited)
itemsBeingEdited.delete(id)
onChange!({
onChange({
...value,
itemsBeingEdited,
})
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/lib/context/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export function getQueryFactory (list: InitialisedList, schema: GraphQLSchema) {
const { count } = (await context.graphql.run({
query: `query ($where: ${whereInputName}!) { count: ${listQueryCountName}(where: $where) }`,
variables: { where },
})) as {
count: number
}
}))

return count
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/core/mutations/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export async function getAccessControlledItemForUpdate (
inputData: Record<string, any>
) {
// apply access.filter.* controls
const item = await getFilteredItem(list, context, uniqueWhere!, accessFilters, 'update')
const item = await getFilteredItem(list, context, uniqueWhere, accessFilters, 'update')

await enforceListLevelAccessControl({
context,
Expand Down Expand Up @@ -254,7 +254,7 @@ export async function getAccessControlledItemForDelete (
accessFilters: boolean | InputFilter
) {
// apply access.filter.* controls
const item = await getFilteredItem(list, context, uniqueWhere!, accessFilters, 'delete')
const item = await getFilteredItem(list, context, uniqueWhere, accessFilters, 'delete')

await enforceListLevelAccessControl({
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,25 @@ test('preview props api', () => {
conditional: {
discriminant: false,
schema: componentBlocks.complex.schema.object.fields.conditional,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: undefined,
value: {
schema: componentBlocks.complex.schema.object.fields.conditional.values.false,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
value: null,
},
},
conditionalSelect: {
discriminant: 'a',
schema: componentBlocks.complex.schema.object.fields.conditionalSelect,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: [
{ label: 'A', value: 'a' },
{ label: 'B', value: 'b' },
],
value: {
schema: componentBlocks.complex.schema.object.fields.conditionalSelect.values.a,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: undefined,
value: '',
},
Expand All @@ -269,28 +269,28 @@ test('preview props api', () => {
many: {
schema: componentBlocks.complex.schema.object.fields.many,
value: [],
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
},
prop: {
schema: componentBlocks.complex.schema.object.fields.prop,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: undefined,
value: '',
},
select: {
schema: componentBlocks.complex.schema.object.fields.select,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: [
{ label: 'A', value: 'a' },
{ label: 'B', value: 'b' },
],
value: 'a',
},
},
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
},
},
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
}
expect(previewProps).toEqual(expectedPreviewProps)
})
Expand Down Expand Up @@ -371,7 +371,7 @@ test('preview props conditional change', () => {
const expectedConditionalPreviewProps: typeof conditionalPreviewProps = {
schema: componentBlocks.complex.schema.object.fields.conditional,
discriminant: true,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: undefined,
value: {
element: React.createElement(ChildFieldEditable, {
Expand Down Expand Up @@ -441,14 +441,14 @@ test('changing conditional with form inside', () => {
const expectedConditionalSelectPreviewProps: typeof conditionalSelectPreviewProps = {
discriminant: 'b',
schema: componentBlocks.complex.schema.object.fields.conditionalSelect,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: [
{ label: 'A', value: 'a' },
{ label: 'B', value: 'b' },
],
value: {
schema: componentBlocks.complex.schema.object.fields.conditionalSelect.values.b,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: undefined,
value: 'B',
},
Expand All @@ -475,14 +475,14 @@ test('changing form inside conditional', () => {
const expectedConditionalSelectPreviewProps: typeof conditionalSelectPreviewProps = {
discriminant: 'a',
schema: componentBlocks.complex.schema.object.fields.conditionalSelect,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: [
{ label: 'A', value: 'a' },
{ label: 'B', value: 'b' },
],
value: {
schema: componentBlocks.complex.schema.object.fields.conditionalSelect.values.a,
onChange: expect.any(Function) as any,
onChange: expect.any(Function) ,
options: undefined,
value: 'Some content',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/fields-document/src/DocumentEditor/marks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function withMarks (
insertText(text)
if (editor.selection && Range.isCollapsed(editor.selection)) {
for (const [mark, shortcuts] of Object.entries(selectedMarkdownShortcuts)) {
for (const shortcutText of shortcuts!) {
for (const shortcutText of shortcuts) {
if (text === shortcutText[shortcutText.length - 1]) {
// this function is not inlined because
// https://github.com/swc-project/swc/issues/2622
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ console.error = (...stuff: any[]) => {

function formatEditor (editor: Node) {
return prettyFormat(editor, {
plugins: [plugins.ReactElement, editorSerializer as Plugin],
plugins: [plugins.ReactElement, editorSerializer ],
})
}

Expand Down
6 changes: 3 additions & 3 deletions packages/fields-document/src/relationship-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function addRelationshipData (
}
}
if (node.type === 'component-block') {
const componentBlock = componentBlocks[node.component as string]
const componentBlock = componentBlocks[node.component ]
if (componentBlock) {
const [props, children] = await Promise.all([
addRelationshipDataToComponentProps(
Expand Down Expand Up @@ -97,7 +97,7 @@ export async function fetchRelationshipData (
selection || ''
}}}`,
variables: { ids },
})) as { items: { [idFieldAlias]: string | number, [labelFieldAlias]: string }[] }
}))

return Array.isArray(val.items)
? val.items.map(({ [labelFieldAlias]: label, [idFieldAlias]: id, ...data }) => {
Expand Down Expand Up @@ -126,7 +126,7 @@ async function fetchDataForOne (
context.gqlNames(listKey).itemQueryName
}(where: {id:$id}) {${labelFieldAlias}:${labelField}\n${selection}}}`,
variables: { id },
})) as { item: Record<string, any> | null }
}))

if (val.item === null) {
if (!process.env.TEST_ADAPTER) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fields-document/src/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const controller = (
return true
}
if (node.type === 'component-block') {
const componentBlock = componentBlocks[node.component as string]
const componentBlock = componentBlocks[node.component ]
if (componentBlock) {
if (!memoizedIsComponentBlockValid(componentBlock)(node.props)) {
return false
Expand Down
20 changes: 10 additions & 10 deletions tests/api-tests/access-control/field-access.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ describe(`Field access`, () => {
const { data, errors } = await context.graphql.raw({ query })
expect(errors).toBe(undefined)
if (!access.query) {
expect(data!).toEqual({
expect(data).toEqual({
[singleQueryName]: { id: item.id, [fieldName]: null },
})
} else {
expect(data!).toEqual({ [singleQueryName]: { id: item.id, [fieldName]: 'hello' } })
expect(data).toEqual({ [singleQueryName]: { id: item.id, [fieldName]: 'hello' } })
}
})
test(`field allowed - multi: ${JSON.stringify(access)}`, async () => {
Expand All @@ -65,7 +65,7 @@ describe(`Field access`, () => {
data: { [fieldName]: 'hello' },
})
const query = `query { ${allQueryName} { id ${fieldName} } }`
const { data, errors } = (await context.graphql.raw({ query })) as ExecutionResult<any>
const { data, errors } = (await context.graphql.raw({ query }))
expect(errors).toBe(undefined)
if (!access.query) {
expect(data).toEqual({
Expand All @@ -75,9 +75,9 @@ describe(`Field access`, () => {
],
})
} else {
expect(data![allQueryName]).toHaveLength(2)
expect(data![allQueryName]).toContainEqual({ id: expect.any(String), [fieldName]: '' })
expect(data![allQueryName]).toContainEqual({ id: item.id, [fieldName]: 'hello' })
expect(data[allQueryName]).toHaveLength(2)
expect(data[allQueryName]).toContainEqual({ id: expect.any(String), [fieldName]: '' })
expect(data[allQueryName]).toContainEqual({ id: item.id, [fieldName]: 'hello' })
}
})
})
Expand All @@ -102,14 +102,14 @@ describe(`Field access`, () => {
} else {
expect(errors).toBe(undefined)
if (access.query) {
expect(data!).toEqual({
expect(data).toEqual({
[createMutationName]: {
id: expect.any(String),
[fieldName]: 'bar',
},
})
} else {
expect(data!).toEqual({
expect(data).toEqual({
[createMutationName]: {
id: expect.any(String),
[fieldName]: null,
Expand Down Expand Up @@ -141,9 +141,9 @@ describe(`Field access`, () => {
} else {
expect(errors).toBe(undefined)
if (access.query) {
expect(data!).toEqual({ [updateMutationName]: { id: item.id, [fieldName]: 'bar' } })
expect(data).toEqual({ [updateMutationName]: { id: item.id, [fieldName]: 'bar' } })
} else {
expect(data!).toEqual({ [updateMutationName]: { id: item.id, [fieldName]: null } })
expect(data).toEqual({ [updateMutationName]: { id: item.id, [fieldName]: null } })
}
}
})
Expand Down
Loading

0 comments on commit b136fd6

Please sign in to comment.