Fix all eslint errors (#6267)

Fixes all eslint errors - now `npx eslint .` in `app/ide-desktop` should show no errors and no warnings.
Also fixes an incorrect lint rule (the rule to catch early returns (?) did not work properly for `try-catch`)

# Important Notes
This changes quite a few files (unfortunately) so QA should be done to check all affected files
This commit is contained in:
somebody1234 2023-04-24 22:56:26 +10:00 committed by GitHub
parent f3873f9768
commit 3e5a3dc468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 40 additions and 32 deletions

View File

@ -102,7 +102,7 @@ const RESTRICTED_SYNTAXES = [
},
{
selector:
':not(:matches(FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, SwitchStatement, SwitchCase, IfStatement:has(.consequent > :matches(ReturnStatement, ThrowStatement)):has(.alternate :matches(ReturnStatement, ThrowStatement)), TryStatement:has(.block > :matches(ReturnStatement, ThrowStatement)):has(:matches([handler=null], .handler :matches(ReturnStatement, ThrowStatement))):has(:matches([finalizer=null], .finalizer :matches(ReturnStatement, ThrowStatement))))) > * > :matches(ReturnStatement, ThrowStatement)',
':not(:matches(FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, SwitchStatement, SwitchCase, IfStatement:has(.consequent > :matches(ReturnStatement, ThrowStatement)):has(.alternate :matches(ReturnStatement, ThrowStatement)), Program > TryStatement, Program > TryStatement > .handler, TryStatement:has(.block > :matches(ReturnStatement, ThrowStatement)):has(:matches([handler=null], .handler :matches(ReturnStatement, ThrowStatement))), TryStatement:has(.block > :matches(ReturnStatement, ThrowStatement)):has(:matches([handler=null], .handler :matches(ReturnStatement, ThrowStatement))) > .handler)) > * > :matches(ReturnStatement, ThrowStatement)',
message: 'No early returns',
},
{

View File

@ -17,9 +17,9 @@ import yargs from 'yargs'
import * as common from 'enso-common'
import * as paths from './paths.js'
import signArchivesMacOs from './tasks/signArchivesMacOs.js'
import { BUNDLED_PROJECT_EXTENSION, SOURCE_FILE_EXTENSION } from './file-associations.js'
import * as fileAssociations from './file-associations'
import * as paths from './paths'
import signArchivesMacOs from './tasks/signArchivesMacOs'
import BUILD_INFO from '../../build.json' assert { type: 'json' }
@ -157,12 +157,12 @@ export function createElectronBuilderConfig(passedArgs: Arguments): electronBuil
],
fileAssociations: [
{
ext: SOURCE_FILE_EXTENSION,
ext: fileAssociations.SOURCE_FILE_EXTENSION,
name: `${common.PRODUCT_NAME} Source File`,
role: 'Editor',
},
{
ext: BUNDLED_PROJECT_EXTENSION,
ext: fileAssociations.BUNDLED_PROJECT_EXTENSION,
name: `${common.PRODUCT_NAME} Project Bundle`,
role: 'Editor',
},

View File

@ -72,12 +72,13 @@
* {@link URL} to redirect the user to the dashboard, to the page specified in the {@link URL}'s
* `pathname`. */
import * as electron from 'electron'
import opener from 'opener'
import * as fs from 'node:fs'
import * as os from 'node:os'
import * as path from 'node:path'
import * as electron from 'electron'
import opener from 'opener'
import * as common from 'enso-common'
import * as contentConfig from 'enso-content-config'
@ -158,15 +159,15 @@ function initSaveAccessTokenListener() {
/** System agnostic credentials directory home path. */
const ensoCredentialsHomePath = path.join(os.homedir(), ensoCredentialsDirectoryName)
fs.mkdir(ensoCredentialsHomePath, { recursive: true }, err => {
if (err) {
fs.mkdir(ensoCredentialsHomePath, { recursive: true }, error => {
if (error) {
logger.error(`Couldn't create ${ensoCredentialsDirectoryName} directory.`)
} else {
fs.writeFile(
path.join(ensoCredentialsHomePath, ensoCredentialsFileName),
accessToken,
err => {
if (err) {
innerError => {
if (innerError) {
logger.error(`Could not write to ${ensoCredentialsFileName} file.`)
}
}

View File

@ -24,9 +24,10 @@ export function pathOrPanic(args: config.Args): string {
const binExists = fsSync.existsSync(binPath)
if (!binExists) {
throw new Error(`Could not find the project manager binary at ${binPath}.`)
}
} else {
return binPath
}
}
/** Executes the Project Manager with given arguments. */
async function exec(args: config.Args, processArgs: string[]) {

View File

@ -136,16 +136,16 @@ export function onFileOpened(event: Event, path: string) {
export function handleOpenFile(openedFile: string): string {
try {
return project.importProjectFromPath(openedFile)
} catch (e: unknown) {
} catch (error) {
// Since the user has explicitly asked us to open a file, in case of an error, we should
// display a message box with the error details.
let message = `Cannot open file '${openedFile}'.`
message += `\n\nReason:\n${e?.toString() ?? 'Unknown error'}`
if (e instanceof Error && typeof e.stack !== 'undefined') {
message += `\n\nDetails:\n${e.stack}`
message += `\n\nReason:\n${error?.toString() ?? 'Unknown error'}`
if (error instanceof Error && typeof error.stack !== 'undefined') {
message += `\n\nDetails:\n${error.stack}`
}
logger.error(e)
logger.error(error)
electron.dialog.showErrorBox(common.PRODUCT_NAME, message)
throw e
throw error
}
}

View File

@ -281,9 +281,9 @@ class App {
fsSync.writeFileSync(profileOutPath, data)
})
}
electron.ipcMain.on(ipc.Channel.openGpuDebugInfo, _event => {
electron.ipcMain.on(ipc.Channel.openGpuDebugInfo, () => {
if (this.window != null) {
this.window.loadURL('chrome://gpu')
void this.window.loadURL('chrome://gpu')
}
})
electron.ipcMain.on(ipc.Channel.quit, () => {

View File

@ -51,10 +51,11 @@ export function importProjectFromPath(openedPath: string): string {
if (rootPath == null) {
const message = `File '${openedPath}' does not belong to the ${common.PRODUCT_NAME} project.`
throw new Error(message)
}
} else {
return importDirectory(rootPath)
}
}
}
/** Import the project from a bundle.
*
@ -99,8 +100,7 @@ export function importDirectory(rootPath: string): string {
if (fsSync.existsSync(targetDirectory)) {
const message = `Project directory already exists: ${targetDirectory}.`
throw new Error(message)
}
} else {
logger.log(`Copying: '${rootPath}' -> '${targetDirectory}'.`)
fsSync.cpSync(rootPath, targetDirectory, { recursive: true })
// Update the project ID, so we are certain that it is unique. This would be violated, if we imported the same
@ -108,6 +108,7 @@ export function importDirectory(rootPath: string): string {
return updateId(targetDirectory)
}
}
}
// ================
// === Metadata ===

View File

@ -196,6 +196,7 @@ class ArchiveToSign implements Signable {
console.log(
`Successfully repacked ${this.path} to handle signing inner native dependency.`
)
return
} catch (error) {
console.error(
`Could not repackage ${archiveName}. Please check the ${import.meta.url} task to ` +

View File

@ -33,6 +33,7 @@ async function bundle() {
path.resolve(THIS_PATH, 'src', 'index.tsx')
)
await esbuild.build(opts)
return
} catch (error) {
console.error(error)
// The error is being re-thrown.

View File

@ -360,7 +360,6 @@ export function useAuth() {
// === ProtectedLayout ===
// =======================
// eslint-disable-next-line @typescript-eslint/naming-convention
export function ProtectedLayout() {
const { session } = useAuth()
@ -375,7 +374,6 @@ export function ProtectedLayout() {
// === GuestLayout ===
// ===================
// eslint-disable-next-line @typescript-eslint/naming-convention
export function GuestLayout() {
const { session } = useAuth()

View File

@ -11,6 +11,9 @@ import * as platform from 'enso-authentication/src/platform'
const ESBUILD_PATH = '/esbuild'
/** SSE event indicating a build has finished. */
const ESBUILD_EVENT_NAME = 'change'
/** Path to the service worker that resolves all extensionless paths to `/index.html`.
* This service worker is required for client-side routing to work when doing local development. */
const SERVICE_WORKER_PATH = '/serviceWorker.js'
// ===================
// === Live reload ===
@ -20,7 +23,7 @@ if (IS_DEV_MODE) {
new EventSource(ESBUILD_PATH).addEventListener(ESBUILD_EVENT_NAME, () => {
location.reload()
})
void navigator.serviceWorker.register('/serviceWorker.js')
void navigator.serviceWorker.register(SERVICE_WORKER_PATH)
}
// ===================

View File

@ -217,8 +217,10 @@ async function main() {
throw Error(
`Script '${script}' invocation needs to be given an output path either through command line argument or 'ENSO_BUILD_ICONS' environment variable.`
)
}
} else {
await genIcons(outputDir)
return
}
}
await main()