Преглед изворни кода

meta: fix more linter warnings (#3757)

Antoine du Hamel пре 2 година
родитељ
комит
797e171179

+ 4 - 4
.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',

+ 2 - 2
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
   }
 

+ 7 - 7
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

+ 3 - 0
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

+ 1 - 0
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 '..'

+ 34 - 33
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',
-  },
-})

+ 15 - 13
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 (
       <View style={styles.container}>
@@ -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,
-  },
-})

+ 24 - 24
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',
-  },
-})

+ 2 - 0
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 <Url {...this.props} />
     }
     // return this.renderInstagram()
+    return undefined
   }
 }

+ 2 - 1
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
   })
 }
 

+ 2 - 2
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)

+ 2 - 2
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)

+ 37 - 37
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',
-  },
-})

+ 2 - 1
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": "*"
   }
 }

+ 1 - 0
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)
   }
 

+ 1 - 1
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 */
 

+ 60 - 60
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
-}

+ 1 - 0
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