Skip to content

Commit

Permalink
meta: fix all ESLint warnings and turn them into errors (#4398)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Apr 4, 2023
1 parent 6eac997 commit 0a7ecea
Show file tree
Hide file tree
Showing 40 changed files with 1,115 additions and 891 deletions.
14 changes: 0 additions & 14 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ lib
dist
coverage
test/lib/**
website/public/**
website/src/examples/**/*.html
website/themes/uppy/source/js/smooth-scroll.min.js
website/themes/uppy/source/js/uppy.js
website/themes/uppy/source/uppy/**
test/endtoend/*/build
examples/svelte-example/public/build/
bundle-legacy.js
website/src/_posts/201*.md
website/src/_posts/2020-*.md
website/src/_posts/2021-01-*.md
website/src/_posts/2021-02-*.md
website/src/_posts/2021-03-*.md
website/src/_posts/2021-04-*.md
website/src/_posts/2021-05-*.md
website/src/_posts/2021-06-*.md
website/src/docs/react-dashboard.md
52 changes: 10 additions & 42 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ module.exports = {
ignore: svgPresentationAttributes,
}],

// Special rules for CI:
...(process.env.CI && {
// Some imports are available only after a full build, which we don't do on CI.
'import/no-unresolved': 'off',
}),

// rules we want to enforce
'array-callback-return': 'error',
'func-names': 'error',
'implicit-arrow-linebreak': 'error',
'import/no-dynamic-require': 'error',
'import/no-extraneous-dependencies': 'error',
Expand All @@ -76,25 +83,8 @@ module.exports = {
'prefer-spread': 'error',
'unicorn/prefer-node-protocol': 'error',

// transloadit rules we would like to enforce in the future
// but will require separate PRs to gradually get there
// and so the meantime: just warn
'class-methods-use-this': ['warn'],
'consistent-return': ['warn'],
'default-case': ['warn'],
'global-require': ['warn'],
'import/no-unresolved': ['warn'],
'import/order': ['warn'],
'no-mixed-operators': ['warn'],
'no-param-reassign': ['warn'],
'no-redeclare': ['warn'],
'no-shadow': ['warn'],
'no-use-before-define': ['warn', { 'functions': false }],
'radix': ['warn'],
'react/button-has-type': 'error',
'react/destructuring-assignment': ['warn'],
'react/forbid-prop-types': 'error',
'react/jsx-props-no-spreading': ['warn'],
'react/no-access-state-in-setstate': 'error',
'react/no-array-index-key': 'error',
'react/no-deprecated': 'error',
Expand Down Expand Up @@ -122,8 +112,8 @@ module.exports = {
// jsdoc
'jsdoc/check-alignment': 'error',
'jsdoc/check-examples': 'off', // cannot yet be supported for ESLint 8, see https://github.com/eslint/eslint/issues/14745
'jsdoc/check-param-names': ['warn'],
'jsdoc/check-syntax': ['warn'],
'jsdoc/check-param-names': 'error',
'jsdoc/check-syntax': 'error',
'jsdoc/check-tag-names': ['error', { jsxTags: true }],
'jsdoc/check-types': 'error',
'jsdoc/newline-after-description': 'error',
Expand Down Expand Up @@ -253,7 +243,6 @@ module.exports = {
'packages/@uppy/webcam/src/**/*.js',
'packages/@uppy/xhr-upload/src/**/*.js',
'packages/@uppy/zoom/src/**/*.js',
'website/src/examples/*/*.es6',
],
parser: 'espree',
parserOptions: {
Expand Down Expand Up @@ -359,20 +348,10 @@ module.exports = {
'no-use-before-define': 'warn',
},
},
{
files: [
'website/src/examples/*/*.es6',
],
rules: {
'import/no-extraneous-dependencies': 'off',
'no-console': 'off',
},
},
{
files: [
'*.test.js',
'test/endtoend/*.js',
'website/*.js',
'bin/**.js',
],
rules: {
Expand All @@ -383,17 +362,15 @@ module.exports = {
files: [
'bin/**.js',
'bin/**.mjs',
'examples/**/*.config.js',
'examples/**/*.cjs',
'examples/**/*.js',
'packages/@uppy/companion/test/**/*.js',
'test/**/*.js',
'test/**/*.ts',
'*.test.js',
'*.test-d.ts',
'postcss.config.js',
'.eslintrc.js',
'website/*.js',
'website/**/*.js',
'private/**/*.js',
],
rules: {
Expand All @@ -415,15 +392,6 @@ module.exports = {
},
},

{
files: [
'website/themes/uppy/source/js/*.js',
],
rules: {
'prefer-const': ['off'],
},
},

{
files: ['test/endtoend/*/*.mjs', 'test/endtoend/*/*.ts'],
rules: {
Expand Down
12 changes: 0 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ test/endtoend/create-react-app/coverage/
uppy-*.tgz
generatedLocale.d.ts

website/db.json
website/*.log
website/node_modules/
website/public/
website/.deploy*/
website/src/_drafts
website/themes/uppy/source/uppy/
website/themes/uppy/_config.yml
website/src/_template/list_of_locale_packs.md
website/src/examples/locale_list.json
website/themes/uppy/layout/partials/generated_stargazers.ejs

**/output/*
!output/.keep
examples/dev/file.txt
Expand Down
8 changes: 3 additions & 5 deletions e2e/cypress/integration/dashboard-aws-multipart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ describe('Dashboard with @uppy/aws-s3-multipart', () => {
it('should upload cat image successfully', () => {
cy.get('@file-input').selectFile('cypress/fixtures/images/cat.jpg', { force:true })

cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
cy.wait(['@post', '@get', '@put']).then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
})
cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait(['@post', '@get', '@put'])
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
})
8 changes: 3 additions & 5 deletions e2e/cypress/integration/dashboard-aws.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ describe('Dashboard with @uppy/aws-s3', () => {
it('should upload cat image successfully', () => {
cy.get('@file-input').selectFile('cypress/fixtures/images/cat.jpg', { force:true })

cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
cy.wait(['@post', '@get']).then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
})
cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait(['@post', '@get'])
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
})
65 changes: 28 additions & 37 deletions e2e/cypress/integration/dashboard-transloadit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ describe('Dashboard with Transloadit', () => {
it('should upload cat image successfully', () => {
cy.get('@file-input').selectFile('cypress/fixtures/images/cat.jpg', { force:true })

cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
cy.wait(['@assemblies', '@resumable']).then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait(['@assemblies', '@resumable']).then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
})

Expand All @@ -31,17 +30,16 @@ describe('Dashboard with Transloadit', () => {
cy.get('@file-input').selectFile(
['cypress/fixtures/images/cat.jpg', 'cypress/fixtures/images/traffic.jpg', 'cypress/fixtures/images/car.jpg'],
{ force:true },
).then(() => {
cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
cy.wait(['@createAssemblies']).then(() => {
expect(Object.values(uppy.getPlugin('Transloadit').activeAssemblies).every((a: any) => a.pollInterval)).to.equal(true)
)
cy.get('.uppy-StatusBar-actionBtn--upload').click()

cy.wait(['@createAssemblies']).then(() => {
expect(Object.values(uppy.getPlugin('Transloadit').activeAssemblies).every((a: any) => a.pollInterval)).to.equal(true)

uppy.cancelAll()
uppy.cancelAll()

cy.wait(['@delete']).then(() => {
expect(Object.values(uppy.getPlugin('Transloadit').activeAssemblies).some((a: any) => a.pollInterval)).to.equal(false)
})
})
cy.wait(['@delete']).then(() => {
expect(Object.values(uppy.getPlugin('Transloadit').activeAssemblies).some((a: any) => a.pollInterval)).to.equal(false)
})
})
})
Expand Down Expand Up @@ -75,20 +73,15 @@ describe('Dashboard with Transloadit', () => {
{ method: 'DELETE', pathname: '/assemblies/*', times: 1 },
).as('assemblyDeletion')

cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
cy.wait('@assemblyPolling').then(() => {
cy.get('button[data-cy=cancel]').click().then(() => {
cy.wait('@assemblyDeletion').then(() => {
// Unfortunately, waiting on a network request somehow often results in a race condition.
// We just want to know wether this is called or not, so waiting for 2 sec to be sure.
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(2000).then(() => {
expect(spy).to.be.calledOnce
})
})
})
})
})
cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait('@assemblyPolling')
cy.get('button[data-cy=cancel]').click()
cy.wait('@assemblyDeletion')
// Unfortunately, waiting on a network request somehow often results in a race condition.
// We just want to know wether this is called or not, so waiting for 2 sec to be sure.
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(2000)
expect(spy).to.be.calledOnce
})
})

Expand Down Expand Up @@ -116,18 +109,16 @@ describe('Dashboard with Transloadit', () => {
{ method: 'DELETE', pathname: '/assemblies/*', times: 1 },
).as('assemblyDeletion')

cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
cy.wait('@assemblyPolling').then(() => {
expect(Object.values(uppy.getPlugin('Transloadit').activeAssemblies).every((a: any) => a.pollInterval)).to.equal(true)
cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait('@assemblyPolling')
expect(Object.values(uppy.getPlugin('Transloadit').activeAssemblies).every((a: any) => a.pollInterval)).to.equal(true)

const { files } = uppy.getState()
uppy.removeFiles(Object.keys(files))
const { files } = uppy.getState()
uppy.removeFiles(Object.keys(files))

cy.wait('@assemblyDeletion').then(() => {
expect(Object.values(uppy.getPlugin('Transloadit').activeAssemblies).some((a: any) => a.pollInterval)).to.equal(false)
expect(spy).to.be.calledOnce
})
})
cy.wait('@assemblyDeletion').then(() => {
expect(Object.values(uppy.getPlugin('Transloadit').activeAssemblies).some((a: any) => a.pollInterval)).to.equal(false)
expect(spy).to.be.calledOnce
})
})
})
Expand Down
14 changes: 6 additions & 8 deletions e2e/cypress/integration/dashboard-tus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ describe('Dashboard with Tus', () => {
it('should upload cat image successfully', () => {
cy.get('@file-input').selectFile('cypress/fixtures/images/cat.jpg', { force:true })

cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
cy.wait(['@post', '@patch']).then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait(['@post', '@patch']).then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
})

Expand All @@ -37,10 +36,9 @@ describe('Dashboard with Tus', () => {
{ statusCode: 429, body: {} },
).as('patch')

cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
cy.wait('@tus').then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait('@tus').then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
})

Expand Down
2 changes: 1 addition & 1 deletion examples/angular-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/jasmine": "~4.0.0",
"eslint": "^8.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^39.0.0",
"eslint-plugin-jsdoc": "^40.0.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"jasmine-core": "~4.2.0",
"karma": "~6.4.0",
Expand Down
5 changes: 3 additions & 2 deletions examples/aws-nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ app.get('/s3/multipart/:uploadId', (req, res, next) => {
const { key } = req.query

if (typeof key !== 'string') {
return res.status(400).json({ error: 's3: the object key must be passed as a query parameter. For example: "?key=abc.jpg"' })
res.status(400).json({ error: 's3: the object key must be passed as a query parameter. For example: "?key=abc.jpg"' })
return
}

const parts = []
listPartsPage(0)

function listPartsPage (startAt) {
client.listParts({
Expand All @@ -165,6 +165,7 @@ app.get('/s3/multipart/:uploadId', (req, res, next) => {
}
})
}
listPartsPage(0)
})

function isValidPart (part) {
Expand Down
1 change: 1 addition & 0 deletions examples/react-native-expo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default function App () {
<View style={{ alignItems: 'center' }}>
<Image
style={styles.logo}
// eslint-disable-next-line global-require
source={require('./assets/uppy-logo.png')}
/>
</View>
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"description": "Extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:",
"lint-staged": {
"*.js": "eslint",
"*.js": "eslint --fix",
"*.jsx": "eslint --fix",
"*.md": [
"remark --silently-ignore -i .remarkignore -foq",
Expand Down Expand Up @@ -68,16 +68,16 @@
"eslint-plugin-compat": "^4.0.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-jsdoc": "^39.0.0",
"eslint-plugin-jest": "^27.0.0",
"eslint-plugin-jsdoc": "^40.0.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-import": "^0.0.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-unicorn": "^43.0.0",
"eslint-plugin-unicorn": "^46.0.0",
"github-contributors-list": "^1.2.4",
"glob": "^8.0.0",
"jest": "^29.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/companion/src/server/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,10 @@ class Uploader {
// previously made to providers. Deleting the field would prevent it from getting leaked
// to the frontend etc.
// @ts-ignore
// eslint-disable-next-line no-param-reassign
delete error.originalRequest
// @ts-ignore
// eslint-disable-next-line no-param-reassign
delete error.originalResponse
reject(error)
},
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/companion/src/server/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable global-require */
module.exports = {
callback: require('./callback'),
deauthorizationCallback: require('./deauth-callback'),
Expand Down
Loading

0 comments on commit 0a7ecea

Please sign in to comment.