Skip to content

Commit

Permalink
Switch from ESLint & Prettier to Biome (#690)
Browse files Browse the repository at this point in the history
* Switch from ESLint & Prettier to Biome

* Use recommended rules by Biome

* fixup! Switch from ESLint & Prettier to Biome

* Enable noAssignInExpressions

* Enable noForEach

* Remove prettier

* Pull files to ignore from .gitignore

* Enable noUndeclaredVariables

* Keep some migrated settings that make sense

* Update lib/index.test-d.ts

Co-authored-by: Kevin van Zonneveld <[email protected]>

* Enable warnings instead of disabling the rules altogether

---------

Co-authored-by: Kevin van Zonneveld <[email protected]>
  • Loading branch information
Acconut and kvz committed May 28, 2024
1 parent a8dc0b6 commit b147b53
Show file tree
Hide file tree
Showing 44 changed files with 269 additions and 1,791 deletions.
9 changes: 0 additions & 9 deletions .eslintignore

This file was deleted.

83 changes: 0 additions & 83 deletions .eslintrc

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.eslintcache
.vscode/settings.json
node_modules
demos/reactnative/.expo
Expand Down
4 changes: 0 additions & 4 deletions .prettierignore

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierrc.json

This file was deleted.

10 changes: 5 additions & 5 deletions .vscode/tus-js-client.code-workspace
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"folders": [
{
"path": "..",
},
"path": ".."
}
],
"settings": {
"workbench.colorCustomizations": {
"titleBar.activeForeground": "#cecece",
"titleBar.activeBackground": "#45b39d",
},
},
"titleBar.activeBackground": "#45b39d"
}
}
}
88 changes: 88 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"style": {
"noParameterAssign": "warn",
"noDefaultExport": "warn",
"useCollapsedElseIf": "error"
},
"suspicious": {
"noExplicitAny": "warn",
"useAwait": "error"
},
"correctness": {
"noNewSymbol": "error",
"noUndeclaredVariables": "error",
"noUnusedVariables": "error"
}
}
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingComma": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"overrides": [
{
"include": ["lib/node/**"],
"linter": {
"rules": {
"style": {
"noRestrictedGlobals": {
"level": "error",
"options": {
"deniedGlobals": ["__filename", "__dirname", "exports", "module", "require"]
}
}
}
}
}
},
{
"include": ["test/**"],
"javascript": {
"globals": [
"jasmine",
"describe",
"expect",
"expectAsync",
"beforeEach",
"afterEach",
"it",
"spyOn"
]
}
},
{
"include": ["demos/browser/**", "demos/cordova/**"],
"javascript": { "globals": ["tus", "Camera"] }
}
]
}
13 changes: 4 additions & 9 deletions demos/browser/demo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* global tus */
/* eslint-disable no-console, no-alert */

'use strict'

let upload = null
let uploadIsRunning = false
const toggleBtn = document.querySelector('#toggle-btn')
Expand Down Expand Up @@ -33,7 +28,7 @@ function askToResumeUpload(previousUploads, currentUpload) {
'\nEnter the corresponding number to resume an upload or press Cancel to start a new upload'

const answer = prompt(text)
const index = parseInt(answer, 10)
const index = Number.parseInt(answer, 10)

if (!Number.isNaN(index) && previousUploads[index]) {
currentUpload.resumeFromPreviousUpload(previousUploads[index])
Expand All @@ -50,12 +45,12 @@ function startUpload() {
}

const endpoint = endpointInput.value
let chunkSize = parseInt(chunkInput.value, 10)
let chunkSize = Number.parseInt(chunkInput.value, 10)
if (Number.isNaN(chunkSize)) {
chunkSize = Infinity
chunkSize = Number.POSITIVE_INFINITY
}

let parallelUploads = parseInt(parallelInput.value, 10)
let parallelUploads = Number.parseInt(parallelInput.value, 10)
if (Number.isNaN(parallelUploads)) {
parallelUploads = 1
}
Expand Down
13 changes: 5 additions & 8 deletions demos/browser/video.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* global tus */
/* eslint-disable no-console, no-alert */

'use strict'

let stopRecording = null
let upload = null
const recordBtn = document.querySelector('#record-btn')
Expand Down Expand Up @@ -33,9 +28,9 @@ recordBtn.addEventListener('click', (e) => {

function startUpload(file) {
const endpoint = endpointInput.value
let chunkSize = parseInt(chunkInput.value, 10)
let chunkSize = Number.parseInt(chunkInput.value, 10)
if (Number.isNaN(chunkSize)) {
chunkSize = Infinity
chunkSize = Number.POSITIVE_INFINITY
}

const options = {
Expand Down Expand Up @@ -132,7 +127,9 @@ function startStreamUpload() {
startUpload(readableRecorder)

stopRecording = () => {
stream.getTracks().forEach((t) => t.stop())
for (const t of stream.getTracks()) {
t.stop()
}
mr.stop()
stopRecording = null
}
Expand Down
6 changes: 2 additions & 4 deletions demos/cordova/hooks/before_prepare/copy_tus_files.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env node

'use strict'

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

const rootDir = path.join(__dirname, '..', '..')
const tusJsPath = path.join(rootDir, '..', '..', 'dist', 'tus.js')
Expand Down
4 changes: 1 addition & 3 deletions demos/cordova/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"cordova-plugin-file": {},
"cordova-plugin-whitelist": {}
},
"platforms": [
"android"
]
"platforms": ["android"]
}
}
5 changes: 0 additions & 5 deletions demos/cordova/www/js/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* global tus Camera */
/* eslint-disable no-alert */

'use strict'

let upload = null
let uploadIsRunning = false
let file = null
Expand Down
6 changes: 1 addition & 5 deletions demos/nodejs/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/* eslint-disable no-console */

'use strict'

const fs = require('fs')
const fs = require('node:fs')
const tus = require('../..')

const path = `${__dirname}/../../README.md`
Expand Down
6 changes: 2 additions & 4 deletions demos/reactnative/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable no-console */

import React from 'react'
import { StyleSheet, Text, View, Button, Image, Linking } from 'react-native'
import { ImagePicker, Permissions } from 'expo'
import React from 'react'
import { Button, Image, Linking, StyleSheet, Text, View } from 'react-native'
import * as tus from 'tus-js-client'

const styles = StyleSheet.create({
Expand Down
1 change: 0 additions & 1 deletion lib/browser/fileSignature.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function reactNativeFingerprint(file, options) {
}

function hashCode(str) {
/* eslint-disable no-bitwise */
// from https://stackoverflow.com/a/8831937/151666
let hash = 0
if (str.length === 0) {
Expand Down
1 change: 0 additions & 1 deletion lib/browser/httpStack.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-classes-per-file */
export default class XHRHttpStack {
createRequest(method, url) {
return new Request(method, url)
Expand Down
10 changes: 5 additions & 5 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import BaseUpload from '../upload.js'
import NoopUrlStorage from '../noopUrlStorage.js'
import { enableDebugLog } from '../logger.js'
import DetailedError from '../error.js'
import { enableDebugLog } from '../logger.js'
import NoopUrlStorage from '../noopUrlStorage.js'
import BaseUpload from '../upload.js'

import { canStoreURLs, WebStorageUrlStorage } from './urlStorage.js'
import DefaultHttpStack from './httpStack.js'
import FileReader from './fileReader.js'
import fingerprint from './fileSignature.js'
import DefaultHttpStack from './httpStack.js'
import { WebStorageUrlStorage, canStoreURLs } from './urlStorage.js'

const defaultOptions = {
...BaseUpload.defaultOptions,
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/urlStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class WebStorageUrlStorage {
upload.urlStorageKey = key

results.push(upload)
} catch (e) {
} catch (_e) {
// The JSON parse error is intentionally ignored here, so a malformed
// entry in the storage cannot prevent an upload.
}
Expand Down
Loading

0 comments on commit b147b53

Please sign in to comment.