Skip to content

Commit

Permalink
enforce some eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Aug 11, 2021
1 parent 72873c4 commit ef72d5a
Show file tree
Hide file tree
Showing 98 changed files with 373 additions and 262 deletions.
81 changes: 47 additions & 34 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const path = require('path')

const svgPresentationAttributes = [
'alignment-baseline', 'baseline-shift', 'clip', 'clip-path', 'clip-rule', 'color', 'color-interpolatio', 'color-interpolatio-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'display', 'dominant-baseline', 'enable-background', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'lighting-color', 'marker-end', 'marker-mid', 'marker-start', 'mask', 'opacity', 'overflow', 'pointer-events', 'shape-rendering', 'stop-color', 'stop-opacity', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-decoration', 'text-rendering', 'transform', 'transform-origin', 'unicode-bidi', 'vector-effect', 'visibility', 'word-spacing', 'writing-mod',
'alignment-baseline', 'baseline-shift', 'class', 'clip', 'clip-path', 'clip-rule', 'color', 'color-interpolatio', 'color-interpolatio-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'display', 'dominant-baseline', 'enable-background', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'lighting-color', 'marker-end', 'marker-mid', 'marker-start', 'mask', 'opacity', 'overflow', 'pointer-events', 'shape-rendering', 'stop-color', 'stop-opacity', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-decoration', 'text-rendering', 'transform', 'transform-origin', 'unicode-bidi', 'vector-effect', 'visibility', 'word-spacing', 'writing-mod',
]

module.exports = {
Expand Down Expand Up @@ -44,54 +44,45 @@ module.exports = {
},
rules: {
// transloadit rules we are actually ok with in the uppy repo
'guard-for-in': ['off'],
'import/extensions': ['off'],
'strict': ['off'],
'key-spacing': ['off'],
'import/extensions': 'off',
'no-await-in-loop': 'off',
'object-shorthand': ['error', 'always'],
'strict': 'off',
'key-spacing': 'off',

// rules we want to enforce
'implicit-arrow-linebreak': 'error',
'import/no-extraneous-dependencies': 'error',
'max-len': 'error',
'no-empty': 'error',
'no-underscore-dangle': 'error',
'no-useless-concat': 'error',
'no-var': '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
'array-callback-return': ['warn'],
'block-scoped-var': ['warn'],
'class-methods-use-this': ['warn'],
'consistent-return': ['warn'],
'default-case': ['warn'],
'global-require': ['warn'],
'implicit-arrow-linebreak': ['warn'],
'import/no-dynamic-require': ['warn'],
'import/no-unresolved': ['warn'],
'import/order': ['warn'],
'jsx-a11y/alt-text': ['warn'],
'jsx-a11y/anchor-has-content': ['warn'],
'jsx-a11y/click-events-have-key-events': ['warn'],
'jsx-a11y/control-has-associated-label': ['warn'],
'jsx-a11y/label-has-associated-control': ['warn'],
'jsx-a11y/media-has-caption': ['warn'],
'jsx-a11y/mouse-events-have-key-events': ['warn'],
'jsx-a11y/no-interactive-element-to-noninteractive-role': ['warn'],
'jsx-a11y/no-noninteractive-element-interactions': ['warn'],
'jsx-a11y/no-static-element-interactions': ['warn'],
'no-await-in-loop': ['warn'],
'no-bitwise': ['warn'],
'no-continue': ['warn'],
'no-empty': ['warn'],
'no-lonely-if': ['warn'],
'no-mixed-operators': ['warn'],
'no-nested-ternary': ['warn'],
'no-param-reassign': ['warn'],
'no-redeclare': ['warn'],
'no-restricted-globals': ['warn'],
'no-restricted-properties': ['warn'],
'no-restricted-syntax': ['warn'],
'no-return-assign': ['warn'],
'no-shadow': ['warn'],
'no-underscore-dangle': ['warn'],
'no-unused-expressions': ['warn'],
'no-unused-vars': ['warn'],
'no-use-before-define': ['warn'],
'no-useless-concat': ['warn'],
'no-var': ['warn'],
'node/handle-callback-err': ['warn'],
'prefer-destructuring': ['warn'],
'prefer-spread': ['warn'],
Expand All @@ -100,31 +91,41 @@ module.exports = {
'react/destructuring-assignment': ['warn'],
'react/forbid-prop-types': ['warn'],
'react/jsx-props-no-spreading': ['warn'],
'react/no-access-state-in-setstate': ['warn'],
'react/no-access-state-in-setstate': 'error',
'react/no-array-index-key': ['warn'],
'react/no-deprecated': ['warn'],
'react/no-this-in-sfc': ['warn'],
'react/no-will-update-set-state': ['warn'],
'react/prefer-stateless-function': ['warn'],
'react/sort-comp': ['warn'],
'react/style-prop-object': ['warn'],
'react/no-unknown-property': ['warn', {
'react/no-unknown-property': ['error', {
ignore: svgPresentationAttributes,
}],
'vars-on-top': ['warn'],
'import/no-extraneous-dependencies': ['error'],

// accessibility
'jsx-a11y/alt-text': ['warn'],
'jsx-a11y/anchor-has-content': ['warn'],
'jsx-a11y/click-events-have-key-events': ['warn'],
'jsx-a11y/control-has-associated-label': ['warn'],
'jsx-a11y/label-has-associated-control': ['warn'],
'jsx-a11y/media-has-caption': ['warn'],
'jsx-a11y/mouse-events-have-key-events': ['warn'],
'jsx-a11y/no-interactive-element-to-noninteractive-role': ['warn'],
'jsx-a11y/no-noninteractive-element-interactions': ['warn'],
'jsx-a11y/no-static-element-interactions': ['warn'],

// compat
'compat/compat': ['error'],

// jsdoc
'jsdoc/check-alignment': ['warn'],
'jsdoc/check-examples': ['warn'],
'jsdoc/check-alignment': 'error',
'jsdoc/check-examples': 'error',
'jsdoc/check-param-names': ['warn'],
'jsdoc/check-syntax': ['warn'],
'jsdoc/check-tag-names': ['warn'],
'jsdoc/check-types': ['warn'],
'jsdoc/newline-after-description': ['warn'],
'jsdoc/check-types': 'error',
'jsdoc/newline-after-description': 'error',
'jsdoc/valid-types': ['warn'],
'jsdoc/check-indentation': ['off'],
},
Expand All @@ -151,6 +152,13 @@ module.exports = {
},

overrides: [
{
files: ['./packages/@uppy/companion/**/*.js'],
rules: {
'no-restricted-syntax': 'warn',
'no-underscore-dangle': 'off',
},
},
{
files: [
'*.test.js',
Expand All @@ -162,17 +170,22 @@ module.exports = {
'compat/compat': ['off'],
},
},

{
files: [
'bin/**.js',
'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',
],
rules: {
'no-console': ['off'],
'no-console': 'off',
'import/no-extraneous-dependencies': ['error', {
devDependencies: true,
}],
Expand Down
2 changes: 1 addition & 1 deletion examples/angular-example/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
module.exports = function karma (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
Expand Down
1 change: 1 addition & 0 deletions examples/bundled/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// https://uppy.io/docs/golden-retriever/

/* globals clients */
/* eslint-disable no-restricted-globals */

const fileCache = Object.create(null)

Expand Down
54 changes: 27 additions & 27 deletions examples/custom-provider/server/customprovider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@ const request = require('request')

const BASE_URL = 'https://api.unsplash.com'

function adaptData (res) {
const data = {
username: null,
items: [],
nextPagePath: null,
}

const items = res
items.forEach((item) => {
const isFolder = !!item.published_at
data.items.push({
isFolder,
icon: isFolder ? item.cover_photo.urls.thumb : item.urls.thumb,
name: item.title || item.description,
mimeType: isFolder ? null : 'image/jpeg',
id: item.id,
thumbnail: isFolder ? item.cover_photo.urls.thumb : item.urls.thumb,
requestPath: item.id,
modifiedDate: item.updated_at,
size: null,
})
})

return data
}

/**
* an example of a custom provider module. It implements @uppy/companion's Provider interface
*/
Expand All @@ -28,7 +54,7 @@ class MyCustomProvider {
return
}

done(null, this._adaptData(body))
done(null, adaptData(body))
})
}

Expand Down Expand Up @@ -76,32 +102,6 @@ class MyCustomProvider {
done(null, body.width * body.height)
})
}

_adaptData (res) {
const data = {
username: null,
items: [],
nextPagePath: null,
}

const items = res
items.forEach((item) => {
const isFolder = !!item.published_at
data.items.push({
isFolder,
icon: isFolder ? item.cover_photo.urls.thumb : item.urls.thumb,
name: item.title || item.description,
mimeType: isFolder ? null : 'image/jpeg',
id: item.id,
thumbnail: isFolder ? item.cover_photo.urls.thumb : item.urls.thumb,
requestPath: item.id,
modifiedDate: item.updated_at,
size: null,
})
})

return data
}
}

module.exports = MyCustomProvider
1 change: 1 addition & 0 deletions examples/dev/sw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals clients */
/* eslint-disable no-restricted-globals */

const fileCache = Object.create(null)

Expand Down
2 changes: 1 addition & 1 deletion examples/react-native-expo/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (api) {
module.exports = function babel (api) {
api.cache(true)
return {
presets: ['babel-preset-expo'],
Expand Down
5 changes: 3 additions & 2 deletions examples/redux/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ let enhancer = applyMiddleware(
uppyReduxStore.middleware(),
logger
)
if (window.__REDUX_DEVTOOLS_EXTENSION__) {
enhancer = compose(enhancer, window.__REDUX_DEVTOOLS_EXTENSION__())
if (typeof __REDUX_DEVTOOLS_EXTENSION__ !== 'undefined') {
// eslint-disable-next-line no-undef
enhancer = compose(enhancer, __REDUX_DEVTOOLS_EXTENSION__())
}

const store = createStore(reducer, enhancer)
Expand Down
6 changes: 4 additions & 2 deletions packages/@uppy/aws-s3-multipart/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ module.exports = class AwsS3Multipart extends BasePlugin {
queuedRequest.abort()
upload.pause()
} else {
// Resuming an upload should be queued, else you could pause and then resume a queued upload to make it skip the queue.
// Resuming an upload should be queued, else you could pause and then
// resume a queued upload to make it skip the queue.
queuedRequest.abort()
queuedRequest = this.requests.run(() => {
upload.start()
Expand Down Expand Up @@ -330,7 +331,8 @@ module.exports = class AwsS3Multipart extends BasePlugin {
queuedRequest.abort()
socket.send('pause', {})
} else {
// Resuming an upload should be queued, else you could pause and then resume a queued upload to make it skip the queue.
// Resuming an upload should be queued, else you could pause and then
// resume a queued upload to make it skip the queue.
queuedRequest.abort()
queuedRequest = this.requests.run(() => {
socket.send('resume', {})
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/companion-client/src/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const RequestClient = require('./RequestClient')
const tokenStorage = require('./tokenStorage')

const _getName = (id) => {
const getName = (id) => {
return id.split('-').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ')
}

Expand All @@ -12,7 +12,7 @@ module.exports = class Provider extends RequestClient {
super(uppy, opts)
this.provider = opts.provider
this.id = this.provider
this.name = this.opts.name || _getName(this.id)
this.name = this.opts.name || getName(this.id)
this.pluginId = this.opts.pluginId
this.tokenKey = `companion-${this.pluginId}-auth-token`
this.companionKeysParams = this.opts.companionKeysParams
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/companion-client/src/SearchProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const RequestClient = require('./RequestClient')

const _getName = (id) => {
const getName = (id) => {
return id.split('-').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ')
}

Expand All @@ -11,7 +11,7 @@ module.exports = class SearchProvider extends RequestClient {
super(uppy, opts)
this.provider = opts.provider
this.id = this.provider
this.name = this.opts.name || _getName(this.id)
this.name = this.opts.name || getName(this.id)
this.pluginId = this.opts.pluginId
}

Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/companion/src/server/helpers/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function isIPAddress (address) {
return addressAsV6.isValid() || addressAsV4.isValid()
}

/* eslint-disable max-len */
/**
* Determine if a IP address provided is a private one.
* Return TRUE if it's the case, FALSE otherwise.
Expand All @@ -23,6 +24,7 @@ function isIPAddress (address) {
* @param {string} ipAddress the ip address to validate
* @returns {boolean}
*/
/* eslint-enable max-len */
function isPrivateIP (ipAddress) {
let isPrivate = false
// Build the list of IP prefix for V4 and V6 addresses
Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/companion/src/server/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ const log = (msg, tag, level, id, color, shouldLogStackTrace) => {
msg.stack = maskMessage(msg.stack)
// exclude msg from template string so values such as error objects
// can be well formatted
// eslint-disable-next-line no-console
console.log(color(`companion: ${time} [${level}] ${id}${whitespace}${tag}`), color(msg.stack))
return
}

// exclude msg from template string so values such as error objects
// can be well formatted
// eslint-disable-next-line no-console
console.log(color(`companion: ${time} [${level}] ${id}${whitespace}${tag}`), color(msg))
}

Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/companion/src/server/provider/zoom/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ exports.getRequestPath = (item) => {
} if (item.file_type) {
return `${encodeURIComponent(item.meeting_id)}?recordingId=${encodeURIComponent(item.id)}`
}
// Zoom meeting ids are reused so we need to use the UUID. Also, these UUIDs can contain `/` characters which require double encoding (see https://devforum.zoom.us/t/double-encode-meeting-uuids/23729)
// Zoom meeting ids are reused so we need to use the UUID. Also, these UUIDs can contain `/` characters which require
// double encoding (see https://devforum.zoom.us/t/double-encode-meeting-uuids/23729).
return `${encodeURIComponent(encodeURIComponent(item.uuid))}`
}

Expand Down
Loading

0 comments on commit ef72d5a

Please sign in to comment.