From 530a6d662d0137dbee51d5f28e1ef2e79feb4b8d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 18 May 2022 12:40:19 +0200 Subject: [PATCH] meta: fix more linter warnings --- .eslintrc.js | 8 +- bin/upload-to-cdn.js | 4 +- e2e/clients/dashboard-tus/app.js | 14 +- e2e/cypress/support/createFakeFile.ts | 3 + packages/@uppy/core/types/index.test-d.ts | 1 + .../@uppy/react-native/file-picker/index.js | 67 +++++----- .../react-native/file-picker/instagram.js | 28 ++-- .../react-native/file-picker/provider-grid.js | 48 +++---- .../react-native/file-picker/provider.js | 2 + .../file-picker/selectDocument.js | 3 +- .../react-native/file-picker/selectImage.js | 4 +- .../react-native/file-picker/takePicture.js | 4 +- .../@uppy/react-native/file-picker/url.js | 74 +++++------ packages/@uppy/react-native/package.json | 3 +- packages/@uppy/robodog/src/upload.js | 1 + packages/@uppy/robodog/types/index.test-d.ts | 2 +- packages/@uppy/status-bar/src/_StatusBar.jsx | 120 +++++++++--------- yarn.lock | 1 + 18 files changed, 200 insertions(+), 187 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c203026829..f0ee0c4c1a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -47,6 +47,10 @@ module.exports = { 'object-shorthand': ['error', 'always'], 'strict': 'off', 'key-spacing': 'off', + 'max-classes-per-file': ['error', 2], + 'react/no-unknown-property': ['error', { + ignore: svgPresentationAttributes, + }], // rules we want to enforce 'array-callback-return': 'error', @@ -79,7 +83,6 @@ module.exports = { 'global-require': ['warn'], 'import/no-unresolved': ['warn'], 'import/order': ['warn'], - 'max-classes-per-file': ['warn', 2], 'no-mixed-operators': ['warn'], 'no-param-reassign': ['warn'], 'no-redeclare': ['warn'], @@ -98,9 +101,6 @@ module.exports = { 'react/prefer-stateless-function': 'error', 'react/sort-comp': 'error', 'react/style-prop-object': 'error', - 'react/no-unknown-property': ['error', { - ignore: svgPresentationAttributes, - }], // accessibility 'jsx-a11y/alt-text': 'error', diff --git a/bin/upload-to-cdn.js b/bin/upload-to-cdn.js index 8ec9baff6b..5f6e90ef16 100644 --- a/bin/upload-to-cdn.js +++ b/bin/upload-to-cdn.js @@ -106,7 +106,7 @@ async function main (packageName, version) { // version should only be a positional arg and semver string // this deals with usage like `npm run uploadcdn uppy -- --force` // where we force push a local build - if (version && version.startsWith('-')) version = undefined + if (version?.startsWith('-')) version = undefined // eslint-disable-line no-param-reassign const s3 = new AWS.S3({ credentials: new AWS.Credentials({ @@ -118,7 +118,7 @@ async function main (packageName, version) { const remote = !!version if (!remote) { - // eslint-disable-next-line import/no-dynamic-require + // eslint-disable-next-line import/no-dynamic-require, global-require, no-param-reassign version = require(`../packages/${packageName}/package.json`).version } diff --git a/e2e/clients/dashboard-tus/app.js b/e2e/clients/dashboard-tus/app.js index 2704574517..4ce9ec0337 100644 --- a/e2e/clients/dashboard-tus/app.js +++ b/e2e/clients/dashboard-tus/app.js @@ -7,13 +7,6 @@ import Url from '@uppy/url' import '@uppy/core/dist/style.css' import '@uppy/dashboard/dist/style.css' -const companionUrl = 'http://localhost:3020' -const uppy = new Uppy() - .use(Dashboard, { target: '#app', inline: true }) - .use(Tus, { endpoint: 'https://tusd.tusdemo.net/files', onShouldRetry }) - .use(Url, { target: Dashboard, companionUrl }) - .use(Unsplash, { target: Dashboard, companionUrl }) - function onShouldRetry (err, retryAttempt, options, next) { if (err?.originalResponse?.getStatus() === 418) { return true @@ -21,5 +14,12 @@ function onShouldRetry (err, retryAttempt, options, next) { return next(err) } +const companionUrl = 'http://localhost:3020' +const uppy = new Uppy() + .use(Dashboard, { target: '#app', inline: true }) + .use(Tus, { endpoint: 'https://tusd.tusdemo.net/files', onShouldRetry }) + .use(Url, { target: Dashboard, companionUrl }) + .use(Unsplash, { target: Dashboard, companionUrl }) + // Keep this here to access uppy in tests window.uppy = uppy diff --git a/e2e/cypress/support/createFakeFile.ts b/e2e/cypress/support/createFakeFile.ts index a94947f891..4e55087126 100644 --- a/e2e/cypress/support/createFakeFile.ts +++ b/e2e/cypress/support/createFakeFile.ts @@ -1,6 +1,7 @@ declare global { namespace Cypress { interface Chainable { + // eslint-disable-next-line no-use-before-define createFakeFile: typeof createFakeFile; } } @@ -14,7 +15,9 @@ interface File { } export function createFakeFile (name?: string, type?: string, b64?: string): File { + // eslint-disable-next-line no-param-reassign if (!b64) b64 = 'PHN2ZyB2aWV3Qm94PSIwIDAgMTIwIDEyMCI+CiAgPGNpcmNsZSBjeD0iNjAiIGN5PSI2MCIgcj0iNTAiLz4KPC9zdmc+Cg==' + // eslint-disable-next-line no-param-reassign if (!type) type = 'image/svg+xml' // https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript diff --git a/packages/@uppy/core/types/index.test-d.ts b/packages/@uppy/core/types/index.test-d.ts index 93cb2eac5f..cf70453b79 100644 --- a/packages/@uppy/core/types/index.test-d.ts +++ b/packages/@uppy/core/types/index.test-d.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { expectError, expectType } from 'tsd' import DefaultStore from '@uppy/store-default' import Uppy, { UIPlugin } from '..' diff --git a/packages/@uppy/react-native/file-picker/index.js b/packages/@uppy/react-native/file-picker/index.js index 53a12b063b..2776766afc 100644 --- a/packages/@uppy/react-native/file-picker/index.js +++ b/packages/@uppy/react-native/file-picker/index.js @@ -11,6 +11,39 @@ import selectImage from './selectImage.js' import selectDocument from './selectDocument.js' import Provider from './provider.js' +const styles = StyleSheet.create({ + providerList: { + flex: 1, + marginTop: 22, + justifyContent: 'center', + }, + providerButton: { + alignItems: 'center', + backgroundColor: '#0077cc', + marginBottom: 15, + marginLeft: 50, + marginRight: 50, + padding: 10, + borderRadius: 5, + }, + providerButtonText: { + color: '#fff', + }, + cancelButton: { + alignItems: 'center', + borderWidth: 1, + borderColor: '#0077cc', + marginBottom: 15, + marginLeft: 50, + marginRight: 50, + padding: 10, + borderRadius: 5, + }, + cancelButtonText: { + color: '#0077cc', + }, +}) + export default class UppyReactNativeFilePicker extends React.Component { constructor () { super() @@ -147,6 +180,7 @@ export default class UppyReactNativeFilePicker extends React.Component { }) this.props.onRequestClose() }} + // eslint-disable-next-line react/jsx-props-no-spreading {...this.props} /> ) : ( @@ -156,36 +190,3 @@ export default class UppyReactNativeFilePicker extends React.Component { ) } } - -const styles = StyleSheet.create({ - providerList: { - flex: 1, - marginTop: 22, - justifyContent: 'center', - }, - providerButton: { - alignItems: 'center', - backgroundColor: '#0077cc', - marginBottom: 15, - marginLeft: 50, - marginRight: 50, - padding: 10, - borderRadius: 5, - }, - providerButtonText: { - color: '#fff', - }, - cancelButton: { - alignItems: 'center', - borderWidth: 1, - borderColor: '#0077cc', - marginBottom: 15, - marginLeft: 50, - marginRight: 50, - padding: 10, - borderRadius: 5, - }, - cancelButtonText: { - color: '#0077cc', - }, -}) diff --git a/packages/@uppy/react-native/file-picker/instagram.js b/packages/@uppy/react-native/file-picker/instagram.js index 9d8b77339f..7513d554a2 100644 --- a/packages/@uppy/react-native/file-picker/instagram.js +++ b/packages/@uppy/react-native/file-picker/instagram.js @@ -9,6 +9,7 @@ import { import Instagram from '@uppy/instagram' function getQueryParamValueFromUrl (name, url) { + // eslint-disable-next-line no-param-reassign name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]') const regexS = `[\\?&]${name}=([^&#]*)` const regex = new RegExp(regexS) @@ -16,6 +17,19 @@ function getQueryParamValueFromUrl (name, url) { return results == null ? null : results[1] } +const styles = StyleSheet.create({ + container: { + justifyContent: 'center', + flex: 1, + paddingTop: 30, + }, + item: { + justifyContent: 'center', + alignItems: 'center', + height: 100, + }, +}) + // how instagram provider can be render, not ready export default class UppyRNInstagram extends React.Component { constructor () { @@ -60,6 +74,7 @@ export default class UppyRNInstagram extends React.Component { uppy.removePlugin(this.plugin) } + // eslint-disable-next-line class-methods-use-this renderGrid (items) { return ( @@ -96,16 +111,3 @@ export default class UppyRNInstagram extends React.Component { return this.renderInstagram() } } - -const styles = StyleSheet.create({ - container: { - justifyContent: 'center', - flex: 1, - paddingTop: 30, - }, - item: { - justifyContent: 'center', - alignItems: 'center', - height: 100, - }, -}) diff --git a/packages/@uppy/react-native/file-picker/provider-grid.js b/packages/@uppy/react-native/file-picker/provider-grid.js index c621a67795..ce37467f79 100644 --- a/packages/@uppy/react-native/file-picker/provider-grid.js +++ b/packages/@uppy/react-native/file-picker/provider-grid.js @@ -1,6 +1,29 @@ import React from 'react' import { StyleSheet, View, Text } from 'react-native' -import { FlatGrid } from 'react-native-super-grid' +import { FlatGrid } from 'react-native-super-grid' // eslint-disable-line import/no-unresolved + +const styles = StyleSheet.create({ + gridView: { + marginTop: 20, + flex: 1, + }, + itemContainer: { + justifyContent: 'flex-end', + borderRadius: 5, + padding: 10, + height: 150, + }, + itemName: { + fontSize: 16, + color: '#fff', + fontWeight: '600', + }, + itemCode: { + fontWeight: '600', + fontSize: 12, + color: '#fff', + }, +}) // test grid, can be used for instagram export default class Example extends React.Component { @@ -36,26 +59,3 @@ export default class Example extends React.Component { ) } } - -const styles = StyleSheet.create({ - gridView: { - marginTop: 20, - flex: 1, - }, - itemContainer: { - justifyContent: 'flex-end', - borderRadius: 5, - padding: 10, - height: 150, - }, - itemName: { - fontSize: 16, - color: '#fff', - fontWeight: '600', - }, - itemCode: { - fontWeight: '600', - fontSize: 12, - color: '#fff', - }, -}) diff --git a/packages/@uppy/react-native/file-picker/provider.js b/packages/@uppy/react-native/file-picker/provider.js index 635367f0ea..369c0f8d68 100644 --- a/packages/@uppy/react-native/file-picker/provider.js +++ b/packages/@uppy/react-native/file-picker/provider.js @@ -5,8 +5,10 @@ import Url from './url.js' export default class UppyRNProvider extends React.Component { render () { if (this.props.providerID === 'Url') { + // eslint-disable-next-line react/jsx-props-no-spreading return } // return this.renderInstagram() + return undefined } } diff --git a/packages/@uppy/react-native/file-picker/selectDocument.js b/packages/@uppy/react-native/file-picker/selectDocument.js index f856dd9afa..fcd46243a0 100644 --- a/packages/@uppy/react-native/file-picker/selectDocument.js +++ b/packages/@uppy/react-native/file-picker/selectDocument.js @@ -1,4 +1,4 @@ -import * as DocumentPicker from 'expo-document-picker' +import * as DocumentPicker from 'expo-document-picker' // eslint-disable-line import/no-unresolved function selectDocumentWithExpo () { return DocumentPicker.getDocumentAsync({ @@ -7,6 +7,7 @@ function selectDocumentWithExpo () { if (!result.cancelled && result.type !== 'cancel') { return result } + return undefined }) } diff --git a/packages/@uppy/react-native/file-picker/selectImage.js b/packages/@uppy/react-native/file-picker/selectImage.js index 8d9abc2b47..7bacfb5b24 100644 --- a/packages/@uppy/react-native/file-picker/selectImage.js +++ b/packages/@uppy/react-native/file-picker/selectImage.js @@ -1,6 +1,6 @@ // Using leading underscore so eslint compat plugin doesn't yell at us. -import * as _Permissions from 'expo-permissions' -import * as ImagePicker from 'expo-image-picker' +import * as _Permissions from 'expo-permissions' // eslint-disable-line import/no-unresolved +import * as ImagePicker from 'expo-image-picker' // eslint-disable-line import/no-unresolved function selectImageWithExpo (options) { return _Permissions.askAsync(_Permissions.CAMERA_ROLL) diff --git a/packages/@uppy/react-native/file-picker/takePicture.js b/packages/@uppy/react-native/file-picker/takePicture.js index e857c2af55..71647ee63b 100644 --- a/packages/@uppy/react-native/file-picker/takePicture.js +++ b/packages/@uppy/react-native/file-picker/takePicture.js @@ -1,6 +1,6 @@ // Using leading underscore so eslint compat plugin doesn't yell at us. -import * as _Permissions from 'expo-permissions' -import * as ImagePicker from 'expo-image-picker' +import * as _Permissions from 'expo-permissions' // eslint-disable-line import/no-unresolved +import * as ImagePicker from 'expo-image-picker' // eslint-disable-line import/no-unresolved function takePictureWithExpo () { return _Permissions.askAsync(_Permissions.CAMERA) diff --git a/packages/@uppy/react-native/file-picker/url.js b/packages/@uppy/react-native/file-picker/url.js index 7b65d24b0f..1c031cb81e 100644 --- a/packages/@uppy/react-native/file-picker/url.js +++ b/packages/@uppy/react-native/file-picker/url.js @@ -9,6 +9,43 @@ import { } from 'react-native' import Url from '@uppy/url' +const styles = StyleSheet.create({ + container: { + flex: 1, + alignItems: 'center', + justifyContent: 'center', + }, + input: { + width: '90%', + height: 40, + borderColor: '#7f8a93', + borderWidth: 1, + padding: 5, + borderRadius: 4, + marginBottom: 15, + }, + buttonImport: { + alignItems: 'center', + backgroundColor: '#2275d7', + paddingHorizontal: 25, + paddingVertical: 8, + borderRadius: 5, + marginBottom: 10, + }, + buttonCancel: { + alignItems: 'center', + paddingHorizontal: 15, + paddingVertical: 8, + borderRadius: 5, + }, + buttonImportText: { + color: '#fff', + }, + buttonCancelText: { + color: '#0077cc', + }, +}) + export default class UppyRNUrl extends React.Component { constructor () { super() @@ -74,40 +111,3 @@ export default class UppyRNUrl extends React.Component { ) } } - -const styles = StyleSheet.create({ - container: { - flex: 1, - alignItems: 'center', - justifyContent: 'center', - }, - input: { - width: '90%', - height: 40, - borderColor: '#7f8a93', - borderWidth: 1, - padding: 5, - borderRadius: 4, - marginBottom: 15, - }, - buttonImport: { - alignItems: 'center', - backgroundColor: '#2275d7', - paddingHorizontal: 25, - paddingVertical: 8, - borderRadius: 5, - marginBottom: 10, - }, - buttonCancel: { - alignItems: 'center', - paddingHorizontal: 15, - paddingVertical: 8, - borderRadius: 5, - }, - buttonImportText: { - color: '#fff', - }, - buttonCancelText: { - color: '#0077cc', - }, -}) diff --git a/packages/@uppy/react-native/package.json b/packages/@uppy/react-native/package.json index 139a9c72b2..da9433c205 100644 --- a/packages/@uppy/react-native/package.json +++ b/packages/@uppy/react-native/package.json @@ -30,6 +30,7 @@ "expo-image-picker": ">=6.0.0", "expo-permissions": ">=6.0.0", "react": "^16.0.0 || ^17.0.0 || ^18.0.0", - "react-native": "*" + "react-native": "*", + "react-native-super-grid": "*" } } diff --git a/packages/@uppy/robodog/src/upload.js b/packages/@uppy/robodog/src/upload.js index 665e6948a7..383969b9a8 100644 --- a/packages/@uppy/robodog/src/upload.js +++ b/packages/@uppy/robodog/src/upload.js @@ -4,6 +4,7 @@ const addTransloaditPlugin = require('./addTransloaditPlugin') function upload (files, opts = {}) { if (!Array.isArray(files) && typeof files.length === 'number') { + // eslint-disable-next-line no-param-reassign files = toArray(files) } diff --git a/packages/@uppy/robodog/types/index.test-d.ts b/packages/@uppy/robodog/types/index.test-d.ts index 9a6d4f9c75..7b39a2fc5f 100644 --- a/packages/@uppy/robodog/types/index.test-d.ts +++ b/packages/@uppy/robodog/types/index.test-d.ts @@ -1,6 +1,6 @@ import { Transloadit } from 'uppy' // eslint-disable-line import/no-extraneous-dependencies import { expectError } from 'tsd' -import Robodog from '.' +import Robodog from '.' // eslint-disable-line import/no-unresolved /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/packages/@uppy/status-bar/src/_StatusBar.jsx b/packages/@uppy/status-bar/src/_StatusBar.jsx index c75c1ff51a..c977980763 100644 --- a/packages/@uppy/status-bar/src/_StatusBar.jsx +++ b/packages/@uppy/status-bar/src/_StatusBar.jsx @@ -10,6 +10,66 @@ import StatusBarUI from './StatusBar.jsx' import packageJson from '../package.json' import locale from './locale.js' +function getTotalSpeed (files) { + let totalSpeed = 0 + files.forEach((file) => { + totalSpeed += getSpeed(file.progress) + }) + return totalSpeed +} + +function getTotalETA (files) { + const totalSpeed = getTotalSpeed(files) + if (totalSpeed === 0) { + return 0 + } + + const totalBytesRemaining = files.reduce((total, file) => { + return total + getBytesRemaining(file.progress) + }, 0) + + return Math.round((totalBytesRemaining / totalSpeed) * 10) / 10 +} + +function getUploadingState (error, isAllComplete, recoveredState, files) { + if (error && !isAllComplete) { + return statusBarStates.STATE_ERROR + } + + if (isAllComplete) { + return statusBarStates.STATE_COMPLETE + } + + if (recoveredState) { + return statusBarStates.STATE_WAITING + } + + let state = statusBarStates.STATE_WAITING + const fileIDs = Object.keys(files) + for (let i = 0; i < fileIDs.length; i++) { + const { progress } = files[fileIDs[i]] + // If ANY files are being uploaded right now, show the uploading state. + if (progress.uploadStarted && !progress.uploadComplete) { + return statusBarStates.STATE_UPLOADING + } + // If files are being preprocessed AND postprocessed at this time, we show the + // preprocess state. If any files are being uploaded we show uploading. + if (progress.preprocess && state !== statusBarStates.STATE_UPLOADING) { + state = statusBarStates.STATE_PREPROCESSING + } + // If NO files are being preprocessed or uploaded right now, but some files are + // being postprocessed, show the postprocess state. + if ( + progress.postprocess + && state !== statusBarStates.STATE_UPLOADING + && state !== statusBarStates.STATE_PREPROCESSING + ) { + state = statusBarStates.STATE_POSTPROCESSING + } + } + return state +} + /** * StatusBar: renders a status bar with upload/pause/resume/cancel/retry buttons, * progress percentage and time remaining. @@ -160,63 +220,3 @@ export default class StatusBar extends UIPlugin { this.unmount() } } - -function getTotalSpeed (files) { - let totalSpeed = 0 - files.forEach((file) => { - totalSpeed += getSpeed(file.progress) - }) - return totalSpeed -} - -function getTotalETA (files) { - const totalSpeed = getTotalSpeed(files) - if (totalSpeed === 0) { - return 0 - } - - const totalBytesRemaining = files.reduce((total, file) => { - return total + getBytesRemaining(file.progress) - }, 0) - - return Math.round((totalBytesRemaining / totalSpeed) * 10) / 10 -} - -function getUploadingState (error, isAllComplete, recoveredState, files) { - if (error && !isAllComplete) { - return statusBarStates.STATE_ERROR - } - - if (isAllComplete) { - return statusBarStates.STATE_COMPLETE - } - - if (recoveredState) { - return statusBarStates.STATE_WAITING - } - - let state = statusBarStates.STATE_WAITING - const fileIDs = Object.keys(files) - for (let i = 0; i < fileIDs.length; i++) { - const { progress } = files[fileIDs[i]] - // If ANY files are being uploaded right now, show the uploading state. - if (progress.uploadStarted && !progress.uploadComplete) { - return statusBarStates.STATE_UPLOADING - } - // If files are being preprocessed AND postprocessed at this time, we show the - // preprocess state. If any files are being uploaded we show uploading. - if (progress.preprocess && state !== statusBarStates.STATE_UPLOADING) { - state = statusBarStates.STATE_PREPROCESSING - } - // If NO files are being preprocessed or uploaded right now, but some files are - // being postprocessed, show the postprocess state. - if ( - progress.postprocess - && state !== statusBarStates.STATE_UPLOADING - && state !== statusBarStates.STATE_PREPROCESSING - ) { - state = statusBarStates.STATE_POSTPROCESSING - } - } - return state -} diff --git a/yarn.lock b/yarn.lock index c1d3ed1bb8..3fd72507e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10028,6 +10028,7 @@ __metadata: expo-permissions: ">=6.0.0" react: ^16.0.0 || ^17.0.0 || ^18.0.0 react-native: "*" + react-native-super-grid: "*" languageName: unknown linkType: soft