enable BE prefer-const eslint rule

pull/12/head
Dario Piotrowicz 2023-01-04 15:41:26 +01:00
rodzic e8a5595163
commit d44d1e6103
7 zmienionych plików z 17 dodań i 19 usunięć

Wyświetl plik

@ -12,6 +12,7 @@ module.exports = {
plugins: ['@typescript-eslint'], plugins: ['@typescript-eslint'],
root: true, root: true,
rules: { rules: {
'prefer-const': 'error',
'no-var': 'error', 'no-var': 'error',
/* /*
Note: the following rules have been set to off so that linting Note: the following rules have been set to off so that linting
@ -25,7 +26,6 @@ module.exports = {
'@typescript-eslint/restrict-plus-operands': 'off', '@typescript-eslint/restrict-plus-operands': 'off',
'no-constant-condition': 'off', 'no-constant-condition': 'off',
'@typescript-eslint/await-thenable': 'off', '@typescript-eslint/await-thenable': 'off',
'prefer-const': 'off',
'@typescript-eslint/require-await': 'off', '@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-template-expressions': 'off', '@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/no-misused-promises': 'off', '@typescript-eslint/no-misused-promises': 'off',

Wyświetl plik

@ -64,7 +64,7 @@ const base64URLDecode = (s: string) => {
} }
const asciiToUint8Array = (s: string) => { const asciiToUint8Array = (s: string) => {
let chars = [] const chars = []
for (let i = 0; i < s.length; ++i) { for (let i = 0; i < s.length; ++i) {
chars.push(s.charCodeAt(i)) chars.push(s.charCodeAt(i))
} }

Wyświetl plik

@ -14,7 +14,7 @@ const headers = {
export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Actor, activity: Activity) { export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Actor, activity: Activity) {
const body = JSON.stringify(activity) const body = JSON.stringify(activity)
console.log({ body }) console.log({ body })
let req = new Request(to.inbox, { const req = new Request(to.inbox, {
method: 'POST', method: 'POST',
body, body,
headers, headers,

Wyświetl plik

@ -20,7 +20,7 @@ export async function signRequest(request: Request, key: CryptoKey, keyId: URL):
request.headers.set('Host', url.host) request.headers.set('Host', url.host)
} }
let components = ['@request-target', 'host'] const components = ['@request-target', 'host']
if (request.method == 'POST') { if (request.method == 'POST') {
components.push('digest') components.push('digest')
} }

Wyświetl plik

@ -5,12 +5,12 @@ import { HEADER, HttpSignatureError, InvalidAlgorithmError, validateAlgorithm }
///--- Globals ///--- Globals
let State = { const State = {
New: 0, New: 0,
Params: 1, Params: 1,
} }
let ParamsState = { const ParamsState = {
Name: 0, Name: 0,
Quote: 1, Quote: 1,
Value: 2, Value: 2,
@ -125,10 +125,10 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
headers = options.headers headers = options.headers
} }
let authz = request.headers.get(HEADER.AUTH) || request.headers.get(HEADER.SIG) const authz = request.headers.get(HEADER.AUTH) || request.headers.get(HEADER.SIG)
if (!authz) { if (!authz) {
let errHeader = HEADER.AUTH + ' or ' + HEADER.SIG const errHeader = HEADER.AUTH + ' or ' + HEADER.SIG
throw new MissingHeaderError('no ' + errHeader + ' header ' + 'present in the request') throw new MissingHeaderError('no ' + errHeader + ' header ' + 'present in the request')
} }
@ -141,14 +141,14 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
let tmpName = '' let tmpName = ''
let tmpValue = '' let tmpValue = ''
let parsed = { const parsed = {
scheme: authz === request.headers.get(HEADER.SIG) ? 'Signature' : '', scheme: authz === request.headers.get(HEADER.SIG) ? 'Signature' : '',
params: {}, params: {},
signingString: '', signingString: '',
} }
for (i = 0; i < authz.length; i++) { for (i = 0; i < authz.length; i++) {
let c = authz.charAt(i) const c = authz.charAt(i)
let code = c.charCodeAt(0) let code = c.charCodeAt(0)
switch (Number(state)) { switch (Number(state)) {
@ -268,7 +268,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
// Build the signingString // Build the signingString
for (i = 0; i < parsed.params.headers.length; i++) { for (i = 0; i < parsed.params.headers.length; i++) {
let h = parsed.params.headers[i].toLowerCase() const h = parsed.params.headers[i].toLowerCase()
parsed.params.headers[i] = h parsed.params.headers[i] = h
if (h === 'request-line') { if (h === 'request-line') {
@ -290,7 +290,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
} else if (h === '(algorithm)') { } else if (h === '(algorithm)') {
parsed.signingString += '(algorithm): ' + parsed.params.algorithm parsed.signingString += '(algorithm): ' + parsed.params.algorithm
} else if (h === '(opaque)') { } else if (h === '(opaque)') {
let opaque = parsed.params.opaque const opaque = parsed.params.opaque
if (opaque === undefined) { if (opaque === undefined) {
throw new MissingHeaderError('opaque param was not in the ' + authzHeaderName + ' header') throw new MissingHeaderError('opaque param was not in the ' + authzHeaderName + ' header')
} }
@ -300,7 +300,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
} else if (h === '(expires)') { } else if (h === '(expires)') {
parsed.signingString += '(expires): ' + parsed.params.expires parsed.signingString += '(expires): ' + parsed.params.expires
} else { } else {
let value = request.headers.get(h) const value = request.headers.get(h)
if (value === null) throw new MissingHeaderError(h + ' was not in the request') if (value === null) throw new MissingHeaderError(h + ' was not in the request')
parsed.signingString += h + ': ' + value parsed.signingString += h + ': ' + value
} }
@ -317,7 +317,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
} else { } else {
date = new Date(request.headers.date) date = new Date(request.headers.date)
} }
let now = new Date() const now = new Date()
skew = Math.abs(now.getTime() - date.getTime()) skew = Math.abs(now.getTime() - date.getTime())
if (skew > options.clockSkew * 1000) { if (skew > options.clockSkew * 1000) {
@ -341,7 +341,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
} }
if (parsed.params.expires) { if (parsed.params.expires) {
let expiredSince = Math.floor(Date.now() / 1000) - parsed.params.expires const expiredSince = Math.floor(Date.now() / 1000) - parsed.params.expires
if (expiredSince > options.clockSkew) { if (expiredSince > options.clockSkew) {
throw new ExpiredRequestError( throw new ExpiredRequestError(
'Request expired with skew ' + expiredSince + 's greater than allowed ' + options.clockSkew + 's' 'Request expired with skew ' + expiredSince + 's greater than allowed ' + options.clockSkew + 's'

Wyświetl plik

@ -31,7 +31,7 @@ export class InvalidAlgorithmError extends HttpSignatureError {
* @returns {[string, string]} * @returns {[string, string]}
*/ */
export function validateAlgorithm(algorithm: string, publicKeyType?: string): [string, string] { export function validateAlgorithm(algorithm: string, publicKeyType?: string): [string, string] {
var alg = algorithm.toLowerCase().split('-') const alg = algorithm.toLowerCase().split('-')
if (alg[0] === 'hs2019') { if (alg[0] === 'hs2019') {
return publicKeyType !== undefined ? validateAlgorithm(publicKeyType + '-sha256') : ['hs2019', 'sha256'] return publicKeyType !== undefined ? validateAlgorithm(publicKeyType + '-sha256') : ['hs2019', 'sha256']

Wyświetl plik

@ -66,9 +66,7 @@ describe('utils', () => {
}) })
test('URL to handle', async () => { test('URL to handle', async () => {
let res const res = urlToHandle(new URL('https://host.org/users/foobar'))
res = urlToHandle(new URL('https://host.org/users/foobar'))
assert.equal(res, 'foobar@host.org') assert.equal(res, 'foobar@host.org')
}) })
}) })