Skip to content

Commit

Permalink
partial eslintification
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Jan 30, 2021
1 parent d596652 commit e72da8c
Show file tree
Hide file tree
Showing 87 changed files with 1,862 additions and 1,225 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.d.ts
58 changes: 31 additions & 27 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"prettier",
"prettier/@typescript-eslint",
"zotero-plugin",
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/member-ordering": "off",
"max-classes-per-file": "off",
"no-console": "off",
"no-new-func": "off"
}
};
const config = require('zotero-plugin/.eslintrc')

config.rules['@typescript-eslint/consistent-type-definitions'] = 'off'
config.rules['@typescript-eslint/member-ordering'] = 'off'
config.rules['max-classes-per-file'] = 'off'
config.rules['no-console'] = 'error'
config.rules['no-new-func'] = 'off'
config.rules['no-underscore-dangle'] = [ 'error', { "allowAfterThis": true } ]

config.rules['@typescript-eslint/no-unsafe-member-access'] = 'off'
config.rules['@typescript-eslint/no-unsafe-call'] = 'off'
config.rules['@typescript-eslint/prefer-regexp-exec'] = 'off'
config.rules['@typescript-eslint/no-implied-eval'] = 'off'
config.rules['@typescript-eslint/no-unsafe-assignment'] = 'off'
config.rules['@typescript-eslint/restrict-template-expressions'] = 'off'

config.rules['@typescript-eslint/ban-ts-comment'] = 'warn'
config.rules['@typescript-eslint/member-delimiter-style'] = [ 'error', {
multiline: { delimiter: 'none', requireLast: false },
singleline: { delimiter: 'comma', requireLast: false },
}]
config.rules['@typescript-eslint/no-unused-vars'] = [ 'error', { "argsIgnorePattern": "^_" } ]

config.ignorePatterns = [
'webpack.config.ts',
'util/*.ts',
'minitests/*.ts',
'content/minitests/*.ts',
]

module.exports = config
1 change: 1 addition & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
citeproc-js
test
site/themes
64 changes: 37 additions & 27 deletions content/ErrorReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export = new class ErrorReport {
private params: any

private errorlog: {
info: string,
errors: string,
debug: string | string[],
references?: string,
info: string
errors: string
debug: string | string[]
references?: string
db?: string
}

Expand Down Expand Up @@ -72,7 +72,8 @@ export = new class ErrorReport {

document.getElementById('better-bibtex-report-id').value = this.key
document.getElementById('better-bibtex-report-result').hidden = false
} catch (err) {
}
catch (err) {
const ps = Components.classes['@mozilla.org/embedcomp/prompt-service;1'].getService(Components.interfaces.nsIPromptService)
ps.alert(null, Zotero.getString('general.error'), `${err} (${this.key}, references: ${!!this.errorlog.references})`)
if (wizard.rewind) wizard.rewind()
Expand Down Expand Up @@ -110,18 +111,21 @@ export = new class ErrorReport {
private async latest() {
try {
const latest = PACKAGE.xpi.releaseURL.replace('https://github.com/', 'https://api.github.com/repos/').replace(/\/releases\/.*/, '/releases/latest')
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(await (await fetch(latest, { method: 'GET', cache: 'no-cache', redirect: 'follow' })).text()).tag_name.replace('v', '')
} catch (err) {
}
catch (err) {
return null
}
}

private async ping(region) {
private async ping(region: string) {
await fetch(`http://s3.${region}.amazonaws.com${s3.region[region].tld || ''}/ping`, {
method: 'GET',
cache: 'no-cache',
redirect: 'follow',
})
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return { region, ...s3.region[region] }
}

Expand Down Expand Up @@ -163,39 +167,40 @@ export = new class ErrorReport {
const show_latest = document.getElementById('better-bibtex-report-latest')
if (current === latest) {
show_latest.hidden = true
} else {
}
else {
show_latest.value = Zotero.BetterBibTeX.getString('ErrorReport.better-bibtex.latest', { version: latest || '<could not be established>' })
show_latest.hidden = false
}

try {
const region = await Zotero.Promise.any(Object.keys(s3.region).map(this.ping))
const region = await Zotero.Promise.any(Object.keys(s3.region).map(this.ping.bind(this)))
this.bucket = `http://${s3.bucket}-${region.short}.s3-${region.region}.amazonaws.com${region.tld || ''}`
this.key = `${Zotero.Utilities.generateObjectKey()}-${region.short}`
continueButton.disabled = false
continueButton.focus()

} catch (err) {
}
catch (err) {
alert(`No AWS region can be reached: ${err.message}`)
wizard.getButton('cancel').disabled = false
}
}

private preview(lines) {
private preview(lines: string | string[]): string {
if (Array.isArray(lines)) {
let preview = ''
for (const line of lines) {
if (line.startsWith('(4)(+')) continue // DB statements

preview += line + '\n'
if (preview.length > this.previewSize) return preview + ' ...'
preview += `${line}\n`
if (preview.length > this.previewSize) return `${preview} ...`
}

return preview

} else if (lines.length > this.previewSize) {
return lines.substr(0, this.previewSize) + ' ...'

}
else if (lines.length > this.previewSize) {
return `${lines.substr(0, this.previewSize)} ...`
}

return lines
Expand Down Expand Up @@ -248,7 +253,8 @@ export = new class ErrorReport {
})
return

} catch (err) {
}
catch (err) {
log.error('ErrorReport: failed to PUT to', url, attempt)
error = err

Expand All @@ -269,7 +275,8 @@ export = new class ErrorReport {
xhr.onload = function() {
if (this.status >= 200 && this.status < 300) { // tslint:disable-line:no-magic-numbers
resolve(xhr.response)
} else {
}
else {
reject({ status: this.status, statusText: xhr.statusText })
}
}
Expand All @@ -281,8 +288,8 @@ export = new class ErrorReport {
}
*/

private async submit(filename, contentType, data, prefix = '') {
if (data.then) data = await data
private async submit(filename, contentType, data: Promise<string | string[]> | string | string[], prefix = '') {
data = await Promise.resolve(data)

const headers = {
'x-amz-storage-class': 'STANDARD',
Expand All @@ -303,6 +310,7 @@ export = new class ErrorReport {

const debugLogDir = Prefs.get('debugLogDir')
if (debugLogDir) {
if (Array.isArray(data)) data = data.join('\n')
await Zotero.File.putContentsAsync(`${debugLogDir}/${filename}.${ext}`, prefix + data)
return
}
Expand All @@ -317,21 +325,23 @@ export = new class ErrorReport {

if ((chunk.length + line.length) > this.chunkSize) {
if (chunk.length !== 0) chunks.push(chunk)
chunk = line + '\n'
chunk = `${line}\n`

} else {
chunk += line + '\n'
}
else {
chunk += `${line}\n`

}
}
if (chunk.length) chunks.push(chunk)

} else {
chunks = fastChunkString(prefix + data, { size: this.chunkSize })
}
else {
chunks = fastChunkString(`${prefix}${data}`, { size: this.chunkSize })

}

chunks = chunks.map((chunk, n) => ({ n: '.' + (n + 1).toString().padStart(4, '0'), body: chunk })) // eslint-disable-line no-magic-numbers
chunks = chunks.map((chunk, n) => ({ n: `.${(n + 1).toString().padStart(4, '0')}`, body: chunk })) // eslint-disable-line no-magic-numbers
if (chunks.length === 1) chunks[0].n = ''

await Promise.all(chunks.map(chunk => this.put(`${url}${chunk.n}.${ext}`, {
Expand Down
9 changes: 6 additions & 3 deletions content/ExportOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import { patch as $patch$ } from './monkey-patch'
let DOM_OBSERVER = null
let reset = true

$patch$(Zotero_File_Interface_Export, 'init', original => function(options) {
$patch$(Zotero_File_Interface_Export, 'init', original => function(_options) {
for (const translator of window.arguments[0].translators) {
if (translator.label === 'BetterBibTeX JSON') translator.label = 'BetterBibTeX debug JSON'
}
// eslint-disable-next-line prefer-rest-params
original.apply(this, arguments)
})

$patch$(Zotero_File_Interface_Export, 'updateOptions', original => function(options) {
$patch$(Zotero_File_Interface_Export, 'updateOptions', original => function(_options) {
// eslint-disable-next-line prefer-rest-params
original.apply(this, arguments)

const index = document.getElementById('format-menu').selectedIndex
Expand Down Expand Up @@ -55,7 +57,8 @@ function mutex(e) {

if ((e.target.id === exportFileData.id) && exportFileData.checked) {
keepUpdated.checked = false
} else if ((e.target.id === keepUpdated.id) && keepUpdated.checked) {
}
else if ((e.target.id === keepUpdated.id) && keepUpdated.checked) {
exportFileData.checked = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion content/FirstRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare const document: any

export = new class FirstRun {
private prefix = 'better-bibtex-first-run-'
private params: { citekeyFormat: String, dragndrop: boolean }
private params: { citekeyFormat: string, dragndrop: boolean }

public load() {
const wizard = document.getElementById('better-bibtex-first-run')
Expand Down
7 changes: 4 additions & 3 deletions content/ItemPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function display(itemID) {
menuitem = zotero_field_transform_menu.appendChild(document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'menuitem'))
menuitem.setAttribute('id', 'zotero-field-transform-menu-better-sentencecase')
menuitem.setAttribute('label', 'BBT sentence case')
menuitem.addEventListener('command', function(e) { title_sentenceCase.call(document.getBindingParent(this), document.popupNode) }, false)
menuitem.addEventListener('command', function(_e) { title_sentenceCase.call(document.getBindingParent(this), document.popupNode) }, false)
}
}

Expand All @@ -29,7 +29,7 @@ function display(itemID) {

const pin = ' \uD83D\uDCCC'
const label = document.getElementById('better-bibtex-citekey-label')
label.value = label.value.replace(pin, '') + (citekey.pinned ? pin : '')
label.value = `${label.value.replace(pin, '')}${(citekey.pinned ? pin : '')}`
}

let observer = null
Expand Down Expand Up @@ -82,7 +82,8 @@ function unload() {
}
}

$patch$(ZoteroItemPane, 'viewItem', original => async function(item, mode, index) {
$patch$(ZoteroItemPane, 'viewItem', original => async function(item, _mode, _index) {
// eslint-disable-next-line prefer-rest-params
await original.apply(this, arguments)
init()

Expand Down
Loading

0 comments on commit e72da8c

Please sign in to comment.