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

Upgrade linting to 2.0.0-0 #3280

Merged
merged 11 commits into from Nov 9, 2021
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 .eslintignore
Expand Up @@ -19,3 +19,4 @@ 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, without this, eslint crashes on:

  eslint:cli-engine Lint /home/kvz/code/uppy/website/src/docs/react-dashboard.md +368ms

Oops! Something went wrong! :(

ESLint: 8.0.1

Error: Rules with suggestions must set the `meta.hasSuggestions` property to `true`.
Occurred while linting /home/kvz/code/uppy/website/src/docs/react-dashboard.md/3_3.js:13
Rule: "react-hooks/exhaustive-deps"
    at Object.report (/home/kvz/code/uppy/node_modules/eslint/lib/linter/linter.js:948:35)
    at reportProblem (/home/kvz/code/uppy/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:760:15)
    at visitFunctionWithDependencies (/home/kvz/code/uppy/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1691:7)
    at visitCallExpression (/home/kvz/code/uppy/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1737:11)
    at ruleErrorHandler (/home/kvz/code/uppy/node_modules/eslint/lib/linter/linter.js:966:28)
    at /home/kvz/code/uppy/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/kvz/code/uppy/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/kvz/code/uppy/node_modules/eslint/lib/linter/node-event-generator.js:290:26)
    at NodeEventGenerator.applySelectors (/home/kvz/code/uppy/node_modules/eslint/lib/linter/node-event-generator.js:319:22)

2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -43,7 +43,6 @@ module.exports = {
rules: {
// transloadit rules we are actually ok with in the uppy repo
'import/extensions': 'off',
'no-await-in-loop': 'off',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we no longer enforce this in 2.0.0-0 as requested by Antoine

'object-shorthand': ['error', 'always'],
'strict': 'off',
'key-spacing': 'off',
Expand Down Expand Up @@ -79,6 +78,7 @@ module.exports = {
'global-require': ['warn'],
'import/no-unresolved': ['warn'],
'import/order': ['warn'],
'max-classes-per-file': ['warn'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new, setting it to warn for now, hopefully we can fix this in later, smaller, custom rolled PRs, and save this one for automation and getting the upgrade out the door.

'no-mixed-operators': ['warn'],
'no-param-reassign': ['warn'],
'no-redeclare': ['warn'],
Expand Down
1 change: 0 additions & 1 deletion bin/after-version-bump.js
Expand Up @@ -43,7 +43,6 @@ async function updateVersions (files, packageName) {
console.log('replacing', replacements, 'in', files.length, 'files')

for (const f of files) {
// eslint-disable-next-line no-await-in-loop
await replaceInFile(f, replacements)
}
}
Expand Down
14 changes: 7 additions & 7 deletions bin/build-bundle.js
Expand Up @@ -96,17 +96,17 @@ const methods = [
buildBundle(
'./packages/uppy/index.js',
'./packages/uppy/dist/uppy.js',
{ standalone: 'Uppy' }
{ standalone: 'Uppy' },
).then(minifyBundle),
buildBundle(
'./packages/uppy/bundle.js',
'./packages/uppy/dist/uppy.legacy.js',
{ standalone: 'Uppy (with polyfills)' }
{ standalone: 'Uppy (with polyfills)' },
).then(transpileDownForIE),
buildBundle(
'./packages/@uppy/robodog/bundle.js',
'./packages/@uppy/robodog/dist/robodog.js',
{ standalone: 'Robodog' }
{ standalone: 'Robodog' },
).then(minifyBundle),
]

Expand All @@ -118,17 +118,17 @@ glob.sync(localePackagePath).forEach((localePath) => {
buildBundle(
`./packages/@uppy/locales/src/${localeName}.js`,
`./packages/@uppy/locales/dist/${localeName}.min.js`,
{ minify: true }
)
{ minify: true },
),
)
})

// Add BUNDLE-README.MD
methods.push(
fs.promises.copyFile(
`${__dirname}/../BUNDLE-README.md`,
`./packages/uppy/dist/README.md`
)
`./packages/uppy/dist/README.md`,
),
)

Promise.all(methods).then(() => {
Expand Down
6 changes: 2 additions & 4 deletions bin/build-css.js
Expand Up @@ -23,7 +23,6 @@ function handleErr (err) {
async function compileCSS () {
const files = await glob('packages/{,@uppy/}*/src/style.scss')

/* eslint-disable no-await-in-loop */
for (const file of files) {
const importedFiles = new Set()
const scssResult = await renderScss({
Expand Down Expand Up @@ -78,7 +77,7 @@ async function compileCSS () {
await writeFile(outfile, postcssResult.css)
console.info(
chalk.green('✓ Built Uppy CSS:'),
chalk.magenta(path.relative(cwd, outfile))
chalk.magenta(path.relative(cwd, outfile)),
)

const minifiedResult = await postcss([
Expand All @@ -90,10 +89,9 @@ async function compileCSS () {
await writeFile(outfile.replace(/\.css$/, '.min.css'), minifiedResult.css)
console.info(
chalk.green('✓ Minified Bundle CSS:'),
chalk.magenta(path.relative(cwd, outfile).replace(/\.css$/, '.min.css'))
chalk.magenta(path.relative(cwd, outfile).replace(/\.css$/, '.min.css')),
)
}
/* eslint-enable no-await-in-loop */
}

compileCSS().then(() => {
Expand Down
4 changes: 2 additions & 2 deletions bin/build-lib.js
Expand Up @@ -34,7 +34,7 @@ async function buildLib () {
const metaMtime = Math.max(...metaMtimes)

const files = await glob(SOURCE)
/* eslint-disable no-await-in-loop, no-continue */
/* eslint-disable no-continue */
for (const file of files) {
if (IGNORE.test(file)) {
continue
Expand All @@ -60,7 +60,7 @@ async function buildLib () {
])
console.log(chalk.green('Compiled lib:'), chalk.magenta(libFile))
}
/* eslint-enable no-await-in-loop, no-continue */
/* eslint-enable no-continue */
}

console.log('Using Babel version:', require('@babel/core/package.json').version)
Expand Down
2 changes: 1 addition & 1 deletion bin/upload-to-cdn.js
Expand Up @@ -85,7 +85,7 @@ async function getLocalDistFiles (packagePath) {
files.map(async (f) => [
f,
await readFile(path.join(packagePath, 'dist', f)),
])
]),
)

return new Map(entries)
Expand Down
2 changes: 1 addition & 1 deletion examples/redux/main.js
Expand Up @@ -25,7 +25,7 @@ const reducer = combineReducers({

let enhancer = applyMiddleware(
uppyReduxStore.middleware(),
logger
logger,
)
if (typeof __REDUX_DEVTOOLS_EXTENSION__ !== 'undefined') {
// eslint-disable-next-line no-undef
Expand Down
8 changes: 4 additions & 4 deletions examples/transloadit-textarea/main.js
Expand Up @@ -26,7 +26,7 @@ class MarkdownTextarea {
this.uploadLine.classList.add('mdtxt-upload')

this.uploadLine.appendChild(
document.createTextNode('Upload an attachment')
document.createTextNode('Upload an attachment'),
)
}

Expand Down Expand Up @@ -111,7 +111,7 @@ class MarkdownTextarea {
// Was cancelled
if (result == null) return
this.insertAttachments(
this.matchFilesAndThumbs(result.results)
this.matchFilesAndThumbs(result.results),
)
}).catch((err) => {
console.error(err)
Expand All @@ -130,7 +130,7 @@ class MarkdownTextarea {
// Was cancelled
if (result == null) return
this.insertAttachments(
this.matchFilesAndThumbs(result.results)
this.matchFilesAndThumbs(result.results),
)
}).catch((err) => {
console.error(err)
Expand All @@ -140,7 +140,7 @@ class MarkdownTextarea {
}

const textarea = new MarkdownTextarea(
document.querySelector('#new textarea')
document.querySelector('#new textarea'),
)
textarea.install()

Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -68,17 +68,18 @@
"deep-freeze": "^0.0.1",
"disc": "^1.3.3",
"eslint": "^8.0.0",
"eslint-config-transloadit": "^1.2.0",
"eslint-config-transloadit": "^2.0.0",
"eslint-plugin-compat": "^3.8.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jest": "^25.0.0",
"eslint-plugin-jsdoc": "^36.0.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-markdown": "^2.2.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-import": "^0.0.1",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one still necessary even though we added the react docs to the ignore-list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "added the react docs to the ignore-list"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm referring to #3280 (comment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think eslint plugin react hooks is needed for the rule of hooks rules to work.

"events.once": "^2.0.2",
"exorcist": "^2.0.0",
"fakefile": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3-multipart/src/MultipartUploader.js
Expand Up @@ -254,7 +254,7 @@ class MultipartUploader {

if (typeof result?.presignedUrls !== 'object') {
throw new TypeError(
'AwsS3/Multipart: Got incorrect result from `prepareUploadParts()`, expected an object `{ presignedUrls }`.'
'AwsS3/Multipart: Got incorrect result from `prepareUploadParts()`, expected an object `{ presignedUrls }`.',
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3-multipart/src/index.js
Expand Up @@ -294,7 +294,7 @@ module.exports = class AwsS3Multipart extends BasePlugin {
protocol: 's3-multipart',
size: file.data.size,
metadata: file.meta,
}
},
).then((res) => {
this.uppy.setFileState(file.id, { serverToken: res.token })
file = this.uppy.getFile(file.id)
Expand Down
8 changes: 4 additions & 4 deletions packages/@uppy/aws-s3-multipart/src/index.test.js
Expand Up @@ -28,7 +28,7 @@ describe('AwsS3Multipart', () => {
const opts = {}

expect(() => awsS3Multipart.opts.createMultipartUpload(file)).toThrow(
err
err,
)
expect(() => awsS3Multipart.opts.listParts(file, opts)).toThrow(err)
expect(() => awsS3Multipart.opts.completeMultipartUpload(file, opts)).toThrow(err)
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('AwsS3Multipart', () => {

it('Calls the prepareUploadParts function totalChunks / limit times', async () => {
const scope = nock(
'https://bucket.s3.us-east-2.amazonaws.com'
'https://bucket.s3.us-east-2.amazonaws.com',
).defaultReplyHeaders({
'access-control-allow-method': 'PUT',
'access-control-allow-origin': '*',
Expand Down Expand Up @@ -103,15 +103,15 @@ describe('AwsS3Multipart', () => {
await core.upload()

expect(
awsS3Multipart.opts.prepareUploadParts.mock.calls.length
awsS3Multipart.opts.prepareUploadParts.mock.calls.length,
).toEqual(1)

scope.done()
})

it('Calls prepareUploadParts with a Math.ceil(limit / 2) minimum, instead of one at a time for the remaining chunks after the first limit batch', async () => {
const scope = nock(
'https://bucket.s3.us-east-2.amazonaws.com'
'https://bucket.s3.us-east-2.amazonaws.com',
).defaultReplyHeaders({
'access-control-allow-method': 'PUT',
'access-control-allow-origin': '*',
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3/src/index.js
Expand Up @@ -141,7 +141,7 @@ module.exports = class AwsS3 extends BasePlugin {
const metadata = Object.fromEntries(
this.opts.metaFields
.filter(key => file.meta[key] != null)
.map(key => [`metadata[${key}]`, file.meta[key].toString()])
.map(key => [`metadata[${key}]`, file.meta[key].toString()]),
)

const query = new URLSearchParams({ filename, type, ...metadata })
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion-client/src/Provider.js
Expand Up @@ -29,7 +29,7 @@ module.exports = class Provider extends RequestClient {

if (this.companionKeysParams) {
authHeaders['uppy-credentials-params'] = btoa(
JSON.stringify({ params: this.companionKeysParams })
JSON.stringify({ params: this.companionKeysParams }),
)
}
return { ...headers, ...authHeaders }
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion-client/src/Socket.test.js
Expand Up @@ -43,7 +43,7 @@ describe('Socket', () => {
expect(
new UppySocket({
target: 'foo',
}) instanceof UppySocket
}) instanceof UppySocket,
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/companion.js
Expand Up @@ -237,7 +237,7 @@ const validateConfig = (companionOptions) => {
fs.accessSync(`${companionOptions.filePath}`, fs.R_OK | fs.W_OK) // eslint-disable-line no-bitwise
} catch (err) {
throw new Error(
`No access to "${companionOptions.filePath}". Please ensure the directory exists and with read/write permissions.`
`No access to "${companionOptions.filePath}". Please ensure the directory exists and with read/write permissions.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about more commas, is this for the same reason, to add new args easier?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, less diff noise if args are added or removed from functions. Same as for object literals, but in v1 function argument comma enforcement was disabled

)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/server/Uploader.js
Expand Up @@ -403,7 +403,7 @@ class Uploader {
logger.debug(
`${combinedBytes} ${bytesTotal} ${formattedPercentage}%`,
'uploader.total.progress',
this.shortToken
this.shortToken,
)

if (this._paused || this.uploadStopped) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/server/controllers/s3.js
Expand Up @@ -248,7 +248,7 @@ module.exports = function s3 (config) {
Body: '',
Expires: config.expires,
})
})
}),
).then((urls) => {
const presignedUrls = Object.create(null)
for (let index = 0; index < partNumbersArray.length; index++) {
Expand Down
3 changes: 1 addition & 2 deletions packages/@uppy/companion/src/server/header-blacklist.js
Expand Up @@ -40,8 +40,7 @@ const forbiddenRegex = [/^proxy-.*$/, /^sec-.*$/]
*/
const isForbiddenHeader = (header) => {
const headerLower = header.toLowerCase()
const forbidden
= forbiddenNames.indexOf(headerLower) >= 0
const forbidden = forbiddenNames.indexOf(headerLower) >= 0
|| forbiddenRegex.findIndex((regex) => regex.test(headerLower)) >= 0

if (forbidden) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/server/helpers/request.js
Expand Up @@ -98,7 +98,7 @@ module.exports.getRedirectEvaluator = (rawRequestURL, blockPrivateIPs) => {
const shouldRedirect = redirectURL.protocol === requestURL.protocol
if (!shouldRedirect) {
logger.info(
`blocking redirect from ${requestURL} to ${redirectURL}`, 'redirect.protection'
`blocking redirect from ${requestURL} to ${redirectURL}`, 'redirect.protection',
)
}

Expand Down
Expand Up @@ -173,7 +173,7 @@ class Drive extends Provider {
sharedDrives,
directory,
query,
isRoot && !query.cursor // we can only show it on the first page request, or else we will have duplicates of it
isRoot && !query.cursor, // we can only show it on the first page request, or else we will have duplicates of it
)
}

Expand Down
Expand Up @@ -142,8 +142,7 @@ class Unsplash extends SearchProvider {
error (err, resp) {
if (resp) {
const fallbackMessage = `request to Unsplash returned ${resp.statusCode}`
const msg
= resp.body && resp.body.errors ? `${resp.body.errors}` : fallbackMessage
const msg = resp.body && resp.body.errors ? `${resp.body.errors}` : fallbackMessage
return new ProviderApiError(msg, resp.statusCode)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/server/s3-client.js
Expand Up @@ -35,7 +35,7 @@ module.exports = (companionOptions) => {
s3ClientOptions.credentials = new AWS.Credentials(
s3ProviderOptions.key,
s3ProviderOptions.secret,
s3ProviderOptions.sessionToken
s3ProviderOptions.sessionToken,
)
}
s3Client = new S3(s3ClientOptions)
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/standalone/index.js
Expand Up @@ -119,7 +119,7 @@ module.exports = function server (inputCompanionOptions = {}) {
if (companionOptions.redisUrl) {
const RedisStore = require('connect-redis')(session)
const redisClient = redis.client(
merge({ url: companionOptions.redisUrl }, companionOptions.redisOptions)
merge({ url: companionOptions.redisUrl }, companionOptions.redisOptions),
)
sessionOptions.store = new RedisStore({ client: redisClient })
}
Expand Down
9 changes: 4 additions & 5 deletions packages/@uppy/core/src/Uppy.js
Expand Up @@ -418,7 +418,7 @@ class Uppy {
const inProgressFiles = files.filter(({ progress }) => !progress.uploadComplete && progress.uploadStarted)
const newFiles = files.filter((file) => !file.progress.uploadStarted)
const startedFiles = files.filter(
file => file.progress.uploadStarted || file.progress.preprocess || file.progress.postprocess
file => file.progress.uploadStarted || file.progress.preprocess || file.progress.postprocess,
)
const uploadStartedFiles = files.filter((file) => file.progress.uploadStarted)
const pausedFiles = files.filter((file) => file.isPaused)
Expand Down Expand Up @@ -1286,10 +1286,9 @@ class Uppy {
}

updateOnlineStatus () {
const online
= typeof window.navigator.onLine !== 'undefined'
? window.navigator.onLine
: true
const online = typeof window.navigator.onLine !== 'undefined'
? window.navigator.onLine
: true
if (!online) {
this.emit('is-offline')
this.info(this.i18n('noInternetConnection'), 'error', 0)
Expand Down