Skip to content

Commit

Permalink
Eslint airbnb transloadit (#95)
Browse files Browse the repository at this point in the history
* extend eslint airbnb and refactor to respect rules

* fix remaining lint issues

* fix buggy tests

* Add a test for totalBytes in uploadProgress

(not yet implemented for isResumable=false)

* Move out eslint #90

https://github.com/transloadit/eslint-config-transloadit

* upgrade to newest eslint-config-transloadit version
  • Loading branch information
mifi authored Feb 17, 2021
1 parent 8df4138 commit 0534c1c
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 170 deletions.
35 changes: 1 addition & 34 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
// Selectively include rules from airbnb https://github.com/transloadit/node-sdk/issues/90
// eslint-disable-next-line import/no-extraneous-dependencies
const airbnbRulesImports = require('eslint-config-airbnb-base/rules/imports').rules

module.exports = {
extends: 'standard',
env : {
es6 : true,
jest: true,
node: true,
},
rules: {
// See https://github.com/transloadit/node-sdk/issues/93
'import/no-extraneous-dependencies': airbnbRulesImports['import/no-extraneous-dependencies'],
'no-multi-spaces' : 0,
'comma-dangle' : [
'error',
'always-multiline',
],
'key-spacing': [
'error',
{
multiLine: {
beforeColon: false,
afterColon : true,
},
align: {
beforeColon: false,
afterColon : true,
on : 'colon',
mode : 'strict',
},
},
],
},
extends: 'transloadit',
}
5 changes: 5 additions & 0 deletions examples/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'no-console': 0,
},
}
8 changes: 4 additions & 4 deletions examples/face_detect_download.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// This example will take an image and find a face and crop out the face.
// Then it will download the result as a file in the current directory
// See https://transloadit.com/demos/artificial-intelligence/detect-faces-in-images/
//
// You'll likely just want to `require('transloadit')`, but we're requiring the local
// variant here for easier testing:
const Transloadit = require('../src/Transloadit')

const got = require('got')
const { createWriteStream } = require('fs')

// You'll likely just want to `require('transloadit')`, but we're requiring the local
// variant here for easier testing:
const Transloadit = require('../src/Transloadit')

const transloadit = new Transloadit({
authKey : process.env.TRANSLOADIT_KEY,
authSecret: process.env.TRANSLOADIT_SECRET,
Expand Down
2 changes: 2 additions & 0 deletions examples/fetch_costs_of_all_assemblies_in_timeframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ const todate = '2020-12-31 15:30:01';
let lastCount
do {
console.log('Processing page', params.page)
// eslint-disable-next-line no-await-in-loop
const { count, items } = await transloadit.listAssemblies(params)
lastCount = count
params.page++

// eslint-disable-next-line no-await-in-loop,no-loop-func
await pMap(items, async (assembly) => {
const assemblyFull = await transloadit.getAssembly(assembly.id)
// console.log(assemblyFull.assembly_id)
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
"into-stream": "^6.0.0",
"is-stream": "^2.0.0",
"lodash": "^4.17.20",
"p-map": "^4.0.0",
"tus-js-client": "^2.2.0"
},
"devDependencies": {
"@types/jest": "^26.0.19",
"badge-maker": "^3.3.0",
"eslint": "^7.18.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-standard": "^16.0.2",
"eslint-config-transloadit": "^1.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"fakefile": "^0.0.9",
"jest": "^26.6.3",
"localtunnel": "^2.0.0",
Expand Down
9 changes: 6 additions & 3 deletions src/PaginationStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class PaginationStream extends stream.Readable {
async _read () {
if (this._items.length > 0) {
this._itemsRead++
return process.nextTick(() => this.push(this._items.pop()))
process.nextTick(() => this.push(this._items.pop()))
return
}

if (this._nitems != null && this._itemsRead >= this._nitems) {
return process.nextTick(() => this.push(null))
process.nextTick(() => this.push(null))
return
}

try {
Expand All @@ -26,7 +28,8 @@ class PaginationStream extends stream.Readable {
this._items = Array.from(items)
this._items.reverse()

return this._read()
this._read()
return
} catch (err) {
this.emit('error', err)
}
Expand Down
Loading

0 comments on commit 0534c1c

Please sign in to comment.