Skip to content

Commit

Permalink
Dependency upgrade, upgrade linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
dscalzi committed Aug 21, 2023
1 parent e5f8ba4 commit 0286f51
Show file tree
Hide file tree
Showing 19 changed files with 597 additions and 484 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
.eslintrc.cjs
58 changes: 58 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const { join } = require("path");

module.exports = {
root: true,
plugins: [
'@typescript-eslint'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: [
join(__dirname, 'tsconfig.json'),
join(__dirname, 'tsconfig.test.json')
]
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked'
],
rules: {
semi: 'off',
'@typescript-eslint/semi': [
'error',
'never'
],
quotes: 'off',
'@typescript-eslint/quotes': [
'error',
'single'
],
indent: 'off',
'@typescript-eslint/indent': [
'error',
4
],
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'none',
requireLast: false
},
singleline: {
delimiter: 'comma',
requireLast: false
}
}
],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-function-return-type': ['warn'],
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off'
}
}
43 changes: 0 additions & 43 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions lib/common/distribution/DistributionAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class DistributionAPI {
if(distro == null) {
distro = await this.pullLocal()
} else {
this.writeDistributionToDisk(distro)
await this.writeDistributionToDisk(distro)
}

} else {
Expand Down Expand Up @@ -140,7 +140,7 @@ export class DistributionAPI {
if(await pathExists(path)) {
const raw = await readFile(path, 'utf-8')
try {
return JSON.parse(raw)
return JSON.parse(raw) as Distribution
} catch(error) {
DistributionAPI.log.error(`Malformed distribution file at ${path}`)
return null
Expand Down
4 changes: 2 additions & 2 deletions lib/dl/AssetGaurdTransmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ abstract class BaseTransmitter {

if(additionalEnvVars) {
// Copy and enrich current env
const forkEnv = {
...JSON.parse(JSON.stringify(process.env)),
const forkEnv: NodeJS.ProcessEnv = {
...JSON.parse(JSON.stringify(process.env)) as NodeJS.ProcessEnv,
...additionalEnvVars
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dl/DownloadEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function downloadFile(url: string, path: string, onProgress?: (prog
fileWriterStream = createWriteStream(path)

if(onProgress) {
downloadStream.on('downloadProgress', progress => onProgress(progress))
downloadStream.on('downloadProgress', (progress: Progress) => onProgress(progress))
}

await pipeline(downloadStream, fileWriterStream)
Expand Down
5 changes: 4 additions & 1 deletion lib/dl/distribution/DistributionIndexProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,22 @@ export class DistributionIndexProcessor extends IndexProcessor {
throw new AssetGuardError('No Forge version manifest module found!')
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return await readJson(versionManifstModule.getPath(), 'utf-8')

} else {

const zip = new StreamZip.async({ file: forgeModule.getPath() })

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const data = JSON.parse((await zip.entryData('version.json')).toString('utf8'))
const writePath = getVersionJsonPath(this.commonDir, data.id)
const writePath = getVersionJsonPath(this.commonDir, data.id as string)

await ensureDir(dirname(writePath))
await writeJson(writePath, data)

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return data
}
finally {
Expand Down
10 changes: 5 additions & 5 deletions lib/dl/mojang/MojangIndexProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class MojangIndexProcessor extends IndexProcessor {
} else {
// Attempt to find local index.
if(await pathExists(versionJsonPath)) {
return await readJson(versionJsonPath)
return await readJson(versionJsonPath) as VersionJson
} else {
throw new AssetGuardError(`Unable to load version manifest and ${version} json index does not exist locally.`)
}
Expand All @@ -113,10 +113,10 @@ export class MojangIndexProcessor extends IndexProcessor {
if(hash) {
const bufHash = calculateHashByBuffer(buf, hash.algo)
if(bufHash === hash.value) {
return JSON.parse(buf.toString())
return JSON.parse(buf.toString()) as T
}
} else {
return JSON.parse(buf.toString())
return JSON.parse(buf.toString()) as T
}
}
} catch(error) {
Expand Down Expand Up @@ -217,10 +217,10 @@ export class MojangIndexProcessor extends IndexProcessor {
} else {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const classifier = libEntry.natives[getMojangOS()].replace('${arch}', process.arch.replace('x', ''))
const classifier = libEntry.natives[getMojangOS()].replace('${arch}', process.arch.replace('x', '')) as string
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
artifact = libEntry.downloads.classifiers[classifier]
artifact = libEntry.downloads.classifiers[classifier] as LibraryArtifact
}

const path = join(libDir, artifact.path)
Expand Down
1 change: 1 addition & 0 deletions lib/dl/receivers/ReceiverExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if(!Object.prototype.hasOwnProperty.call(manifest, targetReceiver)) {
}

const receiver = manifest[targetReceiver]()
// eslint-disable-next-line @typescript-eslint/no-misused-promises
process.on('message', async message => {
try {
await receiver.execute(message)
Expand Down
10 changes: 6 additions & 4 deletions lib/java/JavaGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export async function getHotSpotSettings(execPath: string): Promise<HotSpotSetti
if(!Array.isArray(ret[lastProp])) {
ret[lastProp] = [ret[lastProp]]
}
(ret[lastProp] as Array<unknown>).push(prop.trim())
(ret[lastProp] as unknown[]).push(prop.trim())
}
else if(prop.startsWith(' ')) {
const tmp = prop.split('=')
Expand Down Expand Up @@ -527,7 +527,7 @@ export async function latestOpenJDK(major: number, dataDir: string, distribution
export async function latestAdoptium(major: number, dataDir: string): Promise<Asset | null> {

const sanitizedOS = process.platform === Platform.WIN32 ? 'windows' : (process.platform === Platform.DARWIN ? 'mac' : process.platform)
const arch = process.arch === Architecture.ARM64 ? 'aarch64' : Architecture.X64
const arch: string = process.arch === Architecture.ARM64 ? 'aarch64' : Architecture.X64
const url = `https://api.adoptium.net/v3/assets/latest/${major}/hotspot?vendor=eclipse`

try {
Expand Down Expand Up @@ -879,6 +879,7 @@ export class Win32RegistryJavaDiscoverer implements JavaDiscoverer {

const candidates = new Set<string>()

// eslint-disable-next-line @typescript-eslint/prefer-for-of
for(let i=0; i<regKeys.length; i++){
const key = new Registry({
hive: Registry.HKLM,
Expand Down Expand Up @@ -909,13 +910,14 @@ export class Win32RegistryJavaDiscoverer implements JavaDiscoverer {

let numDone = 0

// eslint-disable-next-line @typescript-eslint/prefer-for-of
for(let j=0; j<javaVers.length; j++){
const javaVer = javaVers[j]
const vKey = javaVer.key.substring(javaVer.key.lastIndexOf('\\')+1).trim()

let major = -1
if(vKey.length > 0) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
if(isNaN(vKey as any)) {
// Should be a semver key.
major = parseJavaRuntimeVersion(vKey)?.major ?? -1
Expand Down Expand Up @@ -1068,7 +1070,7 @@ export async function win32DriveMounts(): Promise<string[]> {
return ['C:\\']
}

return JSON.parse(stdout)
return JSON.parse(stdout) as string[]
}

export async function getPathsOnAllDrivesWin32(paths: string[]): Promise<string[]> {
Expand Down
2 changes: 1 addition & 1 deletion lib/microsoft/rest/MicrosoftResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function decipherErrorCode(body: any): MicrosoftErrorCode {

if(body) {
if(body.XErr) {
const xErr: number = body.XErr
const xErr: number = body.XErr as number
switch(xErr) {
case MicrosoftErrorCode.NO_XBOX_ACCOUNT:
return MicrosoftErrorCode.NO_XBOX_ACCOUNT
Expand Down
4 changes: 2 additions & 2 deletions lib/mojang/net/Protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export class ClientBoundPacket {

let value = ''

for (let i=0; i<data.length; i++) {
value += String.fromCharCode(data[i])
for (const charCode of data) {
value += String.fromCharCode(charCode)
}

return value
Expand Down
2 changes: 1 addition & 1 deletion lib/mojang/net/ServerStatusAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export async function getServerStatus(protocol: number, hostname: string, port =
const result = inboundPacket.readString()

try {
const parsed: ServerStatus = JSON.parse(result)
const parsed = JSON.parse(result) as ServerStatus
socket.end()
resolve(unifyStatusResponse(parsed))
} catch(err) {
Expand Down
14 changes: 7 additions & 7 deletions lib/mojang/rest/MojangRestAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export interface Session {
}
user?: {
id: string
properties: Array<{
properties: {
name: string
value: string
}>
}[]
}
}

Expand Down Expand Up @@ -229,9 +229,9 @@ export class MojangRestAPI {
MojangRestAPI.expectSpecificSuccess('Mojang Status', 200, res.statusCode)

for(const status of res.body) {
for(let i=0; i<MojangRestAPI.statuses.length; i++) {
if(MojangRestAPI.statuses[i].service === status.slug) {
MojangRestAPI.statuses[i].status = status.status === 'up' ? MojangStatusColor.GREEN : MojangStatusColor.RED
for(const mojStatus of MojangRestAPI.statuses) {
if(mojStatus.service === status.slug) {
mojStatus.status = status.status === 'up' ? MojangStatusColor.GREEN : MojangStatusColor.RED
break
}
}
Expand All @@ -245,8 +245,8 @@ export class MojangRestAPI {
} catch(error) {

return MojangRestAPI.handleGotError('Mojang Status', error as RequestError, () => {
for(let i=0; i<MojangRestAPI.statuses.length; i++){
MojangRestAPI.statuses[i].status = MojangStatusColor.GREY
for(const status of MojangRestAPI.statuses){
status.status = MojangStatusColor.GREY
}
return MojangRestAPI.statuses
})
Expand Down
4 changes: 3 additions & 1 deletion lib/util/LoggerUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export class LoggerUtil {
format.printf(info => {
if(info[SPLAT]) {
if(info[SPLAT].length === 1 && info[SPLAT][0] instanceof Error) {
const err = info[SPLAT][0] as Error
const err: Error = info[SPLAT][0]
if(info.message.length > err.message.length && info.message.endsWith(err.message)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
info.message = info.message.substring(0, info.message.length-err.message.length)
}
} else if(info[SPLAT].length > 0) {
Expand All @@ -24,6 +25,7 @@ export class LoggerUtil {
if(typeof it === 'object' && it != null) {
return inspect(it, false, null, true)
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return it
}).join(' ')
}
Expand Down
Loading

0 comments on commit 0286f51

Please sign in to comment.