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

meta: disable @typescript-eslint/no-non-null-assertion lint rule #4945

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extra-semi': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
{
Expand Down
36 changes: 36 additions & 0 deletions .yarn/patches/tus-js-client-npm-3.1.3-dc57874d23.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 7a4efead6df94263db77b12c72ddaeafaeaa406c..e47e63f1159f19dd780986f7e33ffdd70bfdc371 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -2,7 +2,12 @@

export const isSupported: boolean
export const canStoreURLs: boolean
-export const defaultOptions: UploadOptions
+export const defaultOptions: UploadOptions & Required<Pick<UploadOptions,
+| 'httpStack'
+| 'fileReader'
+| 'urlStorage'
+| 'fingerprint'
+>>

// TODO: Consider using { read: () => Promise<{ done: boolean; value?: any; }>; } as type
export class Upload {
@@ -12,7 +17,7 @@ export class Upload {
options: UploadOptions
url: string | null

- static terminate(url: string, options?: UploadOptions): Promise<void>
+ static terminate(url: string, options: UploadOptions): Promise<void>
start(): void
abort(shouldTerminate?: boolean): Promise<void>
findPreviousUploads(): Promise<PreviousUpload[]>
@@ -25,7 +30,7 @@ interface UploadOptions {

uploadUrl?: string | null
metadata?: { [key: string]: string }
- fingerprint?: (file: File, options?: UploadOptions) => Promise<string>
+ fingerprint?: (file: File, options: UploadOptions) => Promise<string>
uploadSize?: number | null

onProgress?: ((bytesSent: number, bytesTotal: number) => void) | null
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"preact": "patch:preact@npm:10.10.0#.yarn/patches/preact-npm-10.10.0-dd04de05e8.patch",
"start-server-and-test": "patch:start-server-and-test@npm:1.14.0#.yarn/patches/start-server-and-test-npm-1.14.0-841aa34fdf.patch",
"stylelint-config-rational-order": "patch:stylelint-config-rational-order@npm%3A0.1.2#./.yarn/patches/stylelint-config-rational-order-npm-0.1.2-d8336e84ed.patch",
"uuid@^8.3.2": "patch:uuid@npm:8.3.2#.yarn/patches/uuid-npm-8.3.2-eca0baba53.patch"
"uuid@^8.3.2": "patch:uuid@npm:8.3.2#.yarn/patches/uuid-npm-8.3.2-eca0baba53.patch",
"tus-js-client": "patch:tus-js-client@npm%3A3.1.3#./.yarn/patches/tus-js-client-npm-3.1.3-dc57874d23.patch"
}
}
1 change: 0 additions & 1 deletion packages/@uppy/companion-client/src/RequestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ export default class RequestClient<M extends Meta, B extends Body> {
try {
return await new Promise((resolve, reject) => {
const token = file.serverToken
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const host = getSocketHost(file.remote!.companionUrl)

let socket: WebSocket | undefined
Expand Down
5 changes: 2 additions & 3 deletions packages/@uppy/companion-client/src/Socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ export default class UppySocket {
this.#isOpen = true

while (this.#queued.length > 0 && this.#isOpen) {
const first = this.#queued.shift()
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.send(first!.action, first!.payload)
const first = this.#queued.shift()!
this.send(first.action, first.payload)
}
}

Expand Down
2 changes: 0 additions & 2 deletions packages/@uppy/core/src/Uppy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint no-console: "off", no-restricted-syntax: "off" */
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -166,7 +165,6 @@ describe('src/Core', () => {

core.use(AcquirerPlugin1)
const plugin = core.getPlugin('TestSelector1')
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(plugin!.id).toEqual('TestSelector1')
expect(plugin instanceof UIPlugin)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/image-editor/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ export default class Editor<M extends Meta, B extends Body> extends Component<
const newCropboxData = limitCropboxMovementOnMove(
canvasData,
cropboxData,
prevCropboxData,
prevCropboxData!,
)
if (newCropboxData) this.cropper.setCropBoxData(newCropboxData)
// 2. When we stretch the cropbox by one of its sides
} else {
const newCropboxData = limitCropboxMovementOnResize(
canvasData,
cropboxData,
prevCropboxData,
prevCropboxData!,
)
if (newCropboxData) this.cropper.setCropBoxData(newCropboxData)
}
Expand Down
1 change: 0 additions & 1 deletion packages/@uppy/image-editor/src/ImageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ export default class ImageEditor<

this.cropper
.getCroppedCanvas(this.opts.cropperOptions.croppedCanvasOptions)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.toBlob(saveBlobCallback, currentImage!.type, this.opts.quality)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ import type Cropper from 'cropperjs'
function limitCropboxMovementOnMove(
canvas: Cropper.CanvasData,
cropbox: Cropper.CropBoxData,
prevCropbox: Cropper.CropBoxData | null,
prevCropbox: Cropper.CropBoxData,
): { left?: number; top?: number; width?: number; height?: number } | null {
// For the left boundary
if (cropbox.left < canvas.left) {
return {
left: canvas.left,
width: prevCropbox!.width,
width: prevCropbox.width,
}
}

// For the top boundary
if (cropbox.top < canvas.top) {
return {
top: canvas.top,
height: prevCropbox!.height,
height: prevCropbox.height,
}
}

// For the right boundary
if (cropbox.left + cropbox.width > canvas.left + canvas.width) {
return {
left: canvas.left + canvas.width - prevCropbox!.width,
width: prevCropbox!.width,
left: canvas.left + canvas.width - prevCropbox.width,
width: prevCropbox.width,
}
}

// For the bottom boundary
if (cropbox.top + cropbox.height > canvas.top + canvas.height) {
return {
top: canvas.top + canvas.height - prevCropbox!.height,
height: prevCropbox!.height,
top: canvas.top + canvas.height - prevCropbox.height,
height: prevCropbox.height,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ import type Cropper from 'cropperjs'
function limitCropboxMovementOnResize(
canvas: Cropper.CanvasData,
cropboxData: Cropper.CropBoxData,
prevCropbox: Cropper.CropBoxData | null,
prevCropbox: Cropper.CropBoxData,
): { left?: number; top?: number; width?: number; height?: number } | null {
// For the left boundary
if (cropboxData.left < canvas.left) {
return {
left: canvas.left,
width: prevCropbox!.left + prevCropbox!.width - canvas.left,
width: prevCropbox.left + prevCropbox.width - canvas.left,
}
}

// For the top boundary
if (cropboxData.top < canvas.top) {
return {
top: canvas.top,
height: prevCropbox!.top + prevCropbox!.height - canvas.top,
height: prevCropbox.top + prevCropbox.height - canvas.top,
}
}

// For the right boundary
if (cropboxData.left + cropboxData.width > canvas.left + canvas.width) {
return {
left: prevCropbox!.left,
width: canvas.left + canvas.width - prevCropbox!.left,
left: prevCropbox.left,
width: canvas.left + canvas.width - prevCropbox.left,
}
}

// For the bottom boundary
if (cropboxData.top + cropboxData.height > canvas.top + canvas.height) {
return {
top: prevCropbox!.top,
height: canvas.top + canvas.height - prevCropbox!.top,
top: prevCropbox.top,
height: canvas.top + canvas.height - prevCropbox.top,
}
}

Expand Down
7 changes: 3 additions & 4 deletions packages/@uppy/status-bar/src/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function PauseResumeButton<M extends Meta, B extends Body>(

interface DoneBtnProps {
i18n: I18n
doneButtonHandler: (() => void) | null
doneButtonHandler: (() => void) | undefined
}

function DoneBtn(props: DoneBtnProps): JSX.Element {
Expand All @@ -219,7 +219,7 @@ function DoneBtn(props: DoneBtnProps): JSX.Element {
<button
type="button"
className="uppy-u-reset uppy-c-btn uppy-StatusBar-actionBtn uppy-StatusBar-actionBtn--done"
onClick={doneButtonHandler!}
onClick={doneButtonHandler}
data-uppy-super-focusable
>
{i18n('done')}
Expand Down Expand Up @@ -251,13 +251,12 @@ interface ProgressBarProcessingProps {
function ProgressBarProcessing(props: ProgressBarProcessingProps): JSX.Element {
const { progress } = props
const { value, mode, message } = progress
const roundedValue = Math.round(value! * 100)
const dot = `\u00B7`

return (
<div className="uppy-StatusBar-content">
<LoadingSpinner />
{mode === 'determinate' ? `${roundedValue}% ${dot} ` : ''}
{mode === 'determinate' ? `${Math.round(value * 100)}% ${dot} ` : ''}
{message}
</div>
)
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/status-bar/src/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ export default class StatusBar<M extends Meta, B extends Body> extends UIPlugin<

onMount(): void {
// Set the text direction if the page has not defined one.
const element = this.el
const direction = getTextDirection(element!)
const element = this.el!
const direction = getTextDirection(element)
if (!direction) {
element!.dir = 'ltr'
element.dir = 'ltr'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function calculateProcessingProgress(
// In the future we should probably do this differently. For now we'll take the
// mode and message from the first file…
if (message == null && (preprocess || postprocess)) {
;({ mode, message } = preprocess || postprocess!) // eslint-disable-line @typescript-eslint/no-non-null-assertion
;({ mode, message } = preprocess || postprocess!)
}
if (preprocess?.mode === 'determinate') values.push(preprocess.value)
if (postprocess?.mode === 'determinate') values.push(postprocess.value)
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/tus/src/getFingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export default function getFingerprint<M extends Meta, B extends Body>(
): tus.UploadOptions['fingerprint'] {
return (file, options) => {
if (isCordova() || isReactNative()) {
return tus.defaultOptions.fingerprint!(file, options)
return tus.defaultOptions.fingerprint(file, options)
}

const uppyFingerprint = ['tus', uppyFile.id, options!.endpoint].join('-')
const uppyFingerprint = ['tus', uppyFile.id, options.endpoint].join('-')

return Promise.resolve(uppyFingerprint)
}
Expand Down
9 changes: 4 additions & 5 deletions packages/@uppy/tus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,12 @@ export default class Tus<M extends Meta, B extends Body> extends BasePlugin<
* any events related to the file, and the Companion WebSocket connection.
*/
resetUploaderReferences(fileID: string, opts?: { abort: boolean }): void {
if (this.uploaders[fileID]) {
const uploader = this.uploaders[fileID]

uploader!.abort()
const uploader = this.uploaders[fileID]
if (uploader) {
uploader.abort()

if (opts?.abort) {
uploader!.abort(true)
uploader.abort(true)
}

this.uploaders[fileID] = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function getAsFileSystemHandleFromEntry(
onSuccess: (dirEntries) =>
resolve(
dirEntries.map(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(file) => getAsFileSystemHandleFromEntry(file, logDropError)!,
),
),
Expand Down
1 change: 0 additions & 1 deletion packages/@uppy/xhr-upload/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { vi, describe, it, expect } from 'vitest'
import nock from 'nock'
import Core from '@uppy/core'
Expand Down
17 changes: 16 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30266,7 +30266,7 @@ __metadata:
languageName: node
linkType: hard

"tus-js-client@npm:^3.1.3":
"tus-js-client@npm:3.1.3":
version: 3.1.3
resolution: "tus-js-client@npm:3.1.3"
dependencies:
Expand All @@ -30281,6 +30281,21 @@ __metadata:
languageName: node
linkType: hard

"tus-js-client@patch:tus-js-client@npm%3A3.1.3#./.yarn/patches/tus-js-client-npm-3.1.3-dc57874d23.patch::locator=%40uppy-dev%2Fbuild%40workspace%3A.":
version: 3.1.3
resolution: "tus-js-client@patch:tus-js-client@npm%3A3.1.3#./.yarn/patches/tus-js-client-npm-3.1.3-dc57874d23.patch::version=3.1.3&hash=f79010&locator=%40uppy-dev%2Fbuild%40workspace%3A."
dependencies:
buffer-from: ^1.1.2
combine-errors: ^3.0.3
is-stream: ^2.0.0
js-base64: ^3.7.2
lodash.throttle: ^4.1.1
proper-lockfile: ^4.1.2
url-parse: ^1.5.7
checksum: ae7275f12e016271e67f8d465f914f4b8c8b6ecd75501ebba95374176247903bada06452f5b7a0e8e7d80342cd63dc395eda5a707bf216c770b95cf60e1b0d63
languageName: node
linkType: hard

"tv4@npm:^1.3.0":
version: 1.3.0
resolution: "tv4@npm:1.3.0"
Expand Down