Skip to content

Commit

Permalink
chore: enable @typescript-eslint/recommended-requiring-type-checking (#…
Browse files Browse the repository at this point in the history
…5715)

Not feasible to fix all 800+ errors. So, some rules were disabled.
  • Loading branch information
develar committed Mar 15, 2021
1 parent a879ba7 commit e6bc232
Show file tree
Hide file tree
Showing 38 changed files with 99 additions and 86 deletions.
16 changes: 15 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
],
parserOptions: {
project: ["./packages/*/tsconfig.json", "./test/tsconfig.json"]
},
rules: {
semi: "off",
"prettier/prettier": process.env.CI ? "error" : "warn",
Expand All @@ -16,7 +25,12 @@ module.exports = {
],
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-constant-condition": "off",
"@typescript-eslint/no-var-requires": "off",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/asar/asar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export async function readAsar(archive: string): Promise<AsarFilesystem> {
await close(fd)
}

const headerPickle = createFromBuffer(headerBuf!)
const headerPickle = createFromBuffer(headerBuf)
const header = headerPickle.createIterator().readString()
return new AsarFilesystem(archive, JSON.parse(header), size)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/binDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function getBinFromUrl(name: string, version: string, checksum: string):

export function getBin(name: string, url?: string | null, checksum?: string | null): Promise<string> {
// Old cache is ignored if cache environment variable changes
const cacheName = process.env.ELECTRON_BUILDER_CACHE + name
const cacheName = `${process.env.ELECTRON_BUILDER_CACHE}${name}`
let promise = versionToPromise.get(cacheName) // if rejected, we will try to download again

if (promise != null) {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/codeSign/macCodeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const bundledCertKeychainAdded = new Lazy<void>(async () => {

function getCacheDirectory(): string {
const env = process.env.ELECTRON_BUILDER_CACHE
return isEmptyOrSpaces(env) ? path.join(homedir(), "Library", "Caches", "electron-builder") : path.resolve(env!)
return isEmptyOrSpaces(env) ? path.join(homedir(), "Library", "Caches", "electron-builder") : path.resolve(env)
}

function listUserKeychains(): Promise<Array<string>> {
Expand Down Expand Up @@ -323,7 +323,7 @@ export function findIdentity(certType: CertType, qualifier?: string | null, keyc
return Promise.resolve(null)
}
} else {
identity = identity!.trim()
identity = identity.trim()
for (const prefix of appleCertificatePrefixes) {
checkPrefix(identity, prefix)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/electron/electronMac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa
Object.assign(appPlist, plistContent[8])
}

const buildMetadata = packager.config!
const buildMetadata = packager.config

/**
* Configure bundleIdentifier for the generic Electron Helper process
Expand Down
7 changes: 2 additions & 5 deletions packages/app-builder-lib/src/electron/electronVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function computeElectronVersion(projectDir: string, projectMetadata
return result
}

const dependency = findFromPackageMetadata(await projectMetadata!.value)
const dependency = findFromPackageMetadata(await projectMetadata.value)
if (dependency?.name === "electron-nightly") {
log.info("You are using a nightly version of electron, be warned that those builds are highly unstable.")
const feedXml = await httpExecutor.request({
Expand All @@ -72,10 +72,7 @@ export async function computeElectronVersion(projectDir: string, projectMetadata
})
const feed = parseXml(feedXml!)
const latestRelease = feed.element("entry", false, `No published versions on GitHub`)
const v = latestRelease
.element("link")
.attribute("href")
.match(/\/tag\/v?([^/]+)$/)![1]
const v = /\/tag\/v?([^/]+)$/.exec(latestRelease.element("link").attribute("href"))![1]
return v.startsWith("v") ? v.substring(1) : v
} else if (dependency?.version === "latest") {
log.warn('Electron version is set to "latest", but it is recommended to set it to some more restricted version range.')
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/fileMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export function getNodeModuleFileMatcher(
matcher.addPattern(pattern)
}
} else {
const fileSet = pattern as FileSet
const fileSet = pattern
if (fileSet.from == null || fileSet.from === ".") {
for (const p of asArray(fileSet.filter)) {
matcher.addPattern(p)
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
https://github.com/electron-userland/electron-builder/issues/5383
*/
},
identity: identity!,
identity: identity,
type,
platform: isMas ? "mas" : "darwin",
version: this.config.electronVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function getEffectiveOptions(options: CommonWindowsInstallerConfiguration
}
menuCategory = sanitizeFileName(companyName)
} else {
menuCategory = (options.menuCategory as string)
menuCategory = options.menuCategory
.split(/[/\\]/)
.map(it => sanitizeFileName(it))
.join("\\")
Expand All @@ -75,7 +75,7 @@ export function getEffectiveOptions(options: CommonWindowsInstallerConfiguration
isPerMachine: options.perMachine === true,
isAssisted: options.oneClick === false,

shortcutName: isEmptyOrSpaces(options.shortcutName) ? appInfo.sanitizedProductName : packager.expandMacro(options.shortcutName!),
shortcutName: isEmptyOrSpaces(options.shortcutName) ? appInfo.sanitizedProductName : packager.expandMacro(options.shortcutName),
isCreateDesktopShortcut: convertToDesktopShortcutCreationPolicy(options.createDesktopShortcut),
isCreateStartMenuShortcut: options.createStartMenuShortcut !== false,
menuCategory,
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export class Packager {

private async createHelper(platform: Platform): Promise<PlatformPackager<any>> {
if (this.options.platformPackagerFactory != null) {
return this.options.platformPackagerFactory!(this, platform)
return this.options.platformPackagerFactory(this, platform)
}

switch (platform) {
Expand Down Expand Up @@ -537,7 +537,7 @@ function createOutDirIfNeed(targetList: Array<Target>, createdOutDirs: Set<strin
continue
}

const outDir = (target as Target).outDir
const outDir = target.outDir
if (!createdOutDirs.has(outDir)) {
ourDirs.add(outDir)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
log.info({ reason: "CSC_KEY_PASSWORD is not defined" }, "empty password will be used for code signing")
return ""
} else {
return password!.trim()
return password.trim()
}
}

Expand Down Expand Up @@ -412,8 +412,8 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return Promise.resolve()
}

async getIconPath(): Promise<string | null> {
return null
getIconPath(): Promise<string | null> {
return Promise.resolve(null)
}

private async computeAsarOptions(customBuildOptions: DC): Promise<AsarOptions | null> {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/publish/s3/s3Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class S3Publisher extends BaseS3Publisher {
}

protected getBucketName(): string {
return this.info.bucket!
return this.info.bucket
}

protected configureS3Options(args: Array<string>): void {
Expand Down
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/publish/s3/spacesPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class SpacesPublisher extends BaseS3Publisher {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
static async checkAndResolveOptions(options: SpacesOptions, channelFromAppVersion: string | null, errorIfCannot: boolean) {
static checkAndResolveOptions(options: SpacesOptions, channelFromAppVersion: string | null, errorIfCannot: boolean) {
if (options.name == null) {
throw new InvalidConfigurationError(`Please specify "name" for "spaces" publish provider (see https://www.electron.build/configuration/publish#spacesoptions)`)
}
Expand All @@ -22,6 +22,7 @@ export default class SpacesPublisher extends BaseS3Publisher {
if (options.channel == null && channelFromAppVersion != null) {
options.channel = channelFromAppVersion
}
return Promise.resolve()
}

protected getBucketName(): string {
Expand Down
6 changes: 3 additions & 3 deletions packages/app-builder-lib/src/publish/updateInfoBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function createUpdateInfoTasks(event: ArtifactCreated, _publishConf

const outDir = event.target!.outDir
const version = packager.appInfo.version
const sha2 = new Lazy<string>(() => hashFile(event.file!, "sha256", "hex"))
const sha2 = new Lazy<string>(() => hashFile(event.file, "sha256", "hex"))
const isMac = packager.platform === Platform.MAC
const createdFiles = new Set<string>()
const sharedInfo = await createUpdateInfo(version, event, await getReleaseInfo(packager))
Expand Down Expand Up @@ -170,8 +170,8 @@ export async function createUpdateInfoTasks(event: ArtifactCreated, _publishConf

async function createUpdateInfo(version: string, event: ArtifactCreated, releaseInfo: ReleaseInfo): Promise<UpdateInfo> {
const customUpdateInfo = event.updateInfo
const url = path.basename(event.file!)
const sha512 = (customUpdateInfo == null ? null : customUpdateInfo.sha512) || (await hashFile(event.file!))
const url = path.basename(event.file)
const sha512 = (customUpdateInfo == null ? null : customUpdateInfo.sha512) || (await hashFile(event.file))
const files = [{ url, sha512 }]
const result: UpdateInfo = {
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/remoteBuilder/builder-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function doBuild(data: BuildTask): Promise<void> {
packager.stageDirPathCustomizer = (target, packager, arch) => {
// snap creates a lot of files and so, we cannot use tmpfs to avoid out of memory error
const parentDir = target.name === "snap" && !(target as SnapTarget).isUseTemplateApp ? projectOutDir : projectDir
return parentDir + path.sep + `__${target.name}-${Arch[arch]}`
return `${parentDir}${path.sep}__${target.name}-${Arch[arch]}`
}

// _build method expects final effective configuration - packager.options.config is ignored
Expand All @@ -85,7 +85,7 @@ async function doBuild(data: BuildTask): Promise<void> {
onNodeModuleFile: null,
directories: {
output: projectOutDir,
buildResources: projectDir + path.sep + info.buildResourceDirName,
buildResources: `${projectDir}${path.sep}${info.buildResourceDirName}`,
},
},
info.metadata,
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class LinuxTargetHelper {
return file
}

async computeDesktopEntry(targetSpecificOptions: LinuxTargetSpecificOptions, exec?: string, extra?: { [key: string]: string }): Promise<string> {
computeDesktopEntry(targetSpecificOptions: LinuxTargetSpecificOptions, exec?: string, extra?: { [key: string]: string }): Promise<string> {
if (exec != null && exec.length === 0) {
throw new Error("Specified exec is empty")
}
Expand Down Expand Up @@ -175,7 +175,7 @@ export class LinuxTargetHelper {
data += `\n${name}=${desktopMeta[name]}`
}
data += "\n"
return data
return Promise.resolve(data)
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export class NsisTarget extends Target {
}
}

async build(appOutDir: string, arch: Arch) {
build(appOutDir: string, arch: Arch) {
this.archs.set(arch, appOutDir)
return Promise.resolve()
}

get isBuildDifferentialAware() {
Expand Down Expand Up @@ -219,7 +220,7 @@ export class NsisTarget extends Target {

const archiveInfo = (await exec(path7za, ["l", file])).trim()
// after adding blockmap data will be "Warnings: 1" in the end of output
const match = archiveInfo.match(/(\d+)\s+\d+\s+\d+\s+files/)
const match = /(\d+)\s+\d+\s+\d+\s+files/.exec(archiveInfo)
if (match == null) {
log.warn({ output: archiveInfo }, "cannot compute size of app package")
} else {
Expand Down Expand Up @@ -345,7 +346,7 @@ export class NsisTarget extends Target {
try {
UninstallerReader.exec(installerPath, uninstallerPath)
} catch (error) {
log.warn("packager.vm is used: " + error.message)
log.warn(`packager.vm is used: ${error.message}`)

const vm = await packager.vm.value
await vm.exec(installerPath, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class NsisScriptGenerator {
}

macro(name: string, lines: Array<string> | NsisScriptGenerator) {
this.lines.push(`!macro ${name}`, ` ${(Array.isArray(lines) ? lines : (lines as NsisScriptGenerator).lines).join("\n ")}`, `!macroend\n`)
this.lines.push(`!macro ${name}`, ` ${(Array.isArray(lines) ? lines : lines.lines).join("\n ")}`, `!macroend\n`)
}

file(outputName: string | null, file: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/targets/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class PkgTarget extends Target {
propertyListOutputFile,
]

use(this.options.installLocation || "/Applications", it => args.push("--install-location", it!))
use(this.options.installLocation || "/Applications", it => args.push("--install-location", it))
if (options.scripts != null) {
args.push("--scripts", path.resolve(this.packager.info.buildResourcesDir, options.scripts))
} else if (options.scripts !== null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function normalizeFiles(configuration: Configuration, name: "files" | "extraFile
}
value[i] = item
} else if (Array.isArray(item)) {
throw new Error(`${name} configuration is invalid, nested array not expected for index ${i}: ` + item)
throw new Error(`${name} configuration is invalid, nested array not expected for index ${i}: ${item}`)
}

// make sure that merge logic is not complex - unify different presentations
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/util/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getLicenseAssets(fileNames: Array<string>, packager: PlatformPac
return aW === bW ? a.localeCompare(b) : aW - bW
})
.map(file => {
let lang = file.match(/_([^.]+)\./)![1]
let lang = /_([^.]+)\./.exec(file)![1]
let langWithRegion
if (lang.includes("_")) {
langWithRegion = lang
Expand Down
16 changes: 8 additions & 8 deletions packages/app-builder-lib/src/util/normalizePackageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const check = [
return true
}
if (!semver.valid(data.version, loose)) {
throw new Error('Invalid version: "' + data.version + '"')
throw new Error(`Invalid version: "${data.version}"`)
}
data.version = semver.clean(data.version, loose)
return true
Expand Down Expand Up @@ -224,7 +224,7 @@ function isValidScopedPackageName(spec: string): boolean {
}

function isCorrectlyEncodedName(spec: string): boolean {
return !spec.match(/[/@\s+%:]/) && spec === encodeURIComponent(spec)
return !/[/@\s+%:]/.test(spec) && spec === encodeURIComponent(spec)
}

function ensureValidName(name: string): void {
Expand Down Expand Up @@ -257,19 +257,19 @@ function unParsePerson(person: any): string {
}
const name = person.name || ""
const u = person.url || person.web
const url = u ? " (" + u + ")" : ""
const url = u ? ` (${u})` : ""
const e = person.email || person.mail
const email = e ? " <" + e + ">" : ""
return name + email + url
const email = e ? ` <${e}>` : ""
return `${name}${email}${url}`
}

function parsePerson(person: any) {
if (typeof person !== "string") {
return person
}
const name = person.match(/^([^(<]+)/)
const url = person.match(/\(([^)]+)\)/)
const email = person.match(/<([^>]+)>/)
const name = /^([^(<]+)/.exec(person)
const url = /\(([^)]+)\)/.exec(person)
const email = /<([^>]+)>/.exec(person)
const obj: any = {}
if (name && name[0].trim()) {
obj.name = name[0].trim()
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/util/repositoryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ async function getGitUrlFromGitConfig(projectDir: string): Promise<string | null
const i = conf.indexOf('[remote "origin"]')
if (i !== -1) {
let u = conf[i + 1]
if (!u.match(/^\s*url =/)) {
if (!/^\s*url =/.exec(u)) {
u = conf[i + 2]
}

if (u.match(/^\s*url =/)) {
if (/^\s*url =/.exec(u)) {
return u.replace(/^\s*url = /, "")
}
}
Expand Down
Loading

0 comments on commit e6bc232

Please sign in to comment.