Skip to content

Commit

Permalink
feat(eslint): add rules
Browse files Browse the repository at this point in the history
chore: format

Signed-off-by: kash / Hytus <[email protected]>
  • Loading branch information
KashEight committed Oct 25, 2023
1 parent f851f26 commit f0324c1
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 62 deletions.
15 changes: 11 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"plugins": ["import", "unused-imports"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
"project": "./tsconfig.eslint.json"
},
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
Expand Down Expand Up @@ -44,7 +44,14 @@
"@typescript-eslint/no-redundant-type-constituents": "off",
// for eslint-plugin-unused-imports
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "error"
},
"ignorePatterns": ["webpack.*", "forge.config.ts"]
"unused-imports/no-unused-imports": "error",
// import rules
"import/order": [
"error",
{
"newlines-between": "always",
"alphabetize": { "order": "asc", "caseInsensitive": true }
}
]
}
}
53 changes: 29 additions & 24 deletions forge.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { ForgeConfig } from '@electron-forge/shared-types'

import { MakerSquirrel } from '@electron-forge/maker-squirrel'
import { MakerZIP } from '@electron-forge/maker-zip'
import { WebpackPlugin } from "@electron-forge/plugin-webpack"
import { MakerSquirrel } from "@electron-forge/maker-squirrel"
import { MakerZIP } from "@electron-forge/maker-zip"
import { AutoUnpackNativesPlugin } from "@electron-forge/plugin-auto-unpack-natives"
import { mainConfig } from './webpack.main.config'
import { rendererConfig } from './webpack.renderer.config'
import { WebpackPlugin } from "@electron-forge/plugin-webpack"
import type { ForgeConfig } from "@electron-forge/shared-types"

import { mainConfig } from "./webpack.main.config"
import { rendererConfig } from "./webpack.renderer.config"

const config: ForgeConfig = {
packagerConfig: {
Expand All @@ -15,38 +16,42 @@ const config: ForgeConfig = {
makers: [
// Only Windows supported for now
// We can add darwin/linux later for Wine/Proton users
new MakerSquirrel(), new MakerZIP()
new MakerSquirrel(),
new MakerZIP(),
],
plugins: [
new AutoUnpackNativesPlugin({}),
new WebpackPlugin({
devContentSecurityPolicy: 'default-src \'self\' \'unsafe-inline\' data:; script-src \'self\' \'unsafe-eval\' \'unsafe-inline\' data:',
devContentSecurityPolicy:
"default-src 'self' 'unsafe-inline' data:; script-src 'self' 'unsafe-eval' 'unsafe-inline' data:",
mainConfig: mainConfig,
renderer: {
config: rendererConfig,
entryPoints: [{
html: "./src/assets/index.html",
js: "./src/assets/index.js",
name: "main_window",
preload: {
js: "./src/preload.ts"
}
}]
entryPoints: [
{
html: "./src/assets/index.html",
js: "./src/assets/index.js",
name: "main_window",
preload: {
js: "./src/preload.ts",
},
},
],
},
})
}),
],
publishers: [
{
name: '@electron-forge/publisher-github',
name: "@electron-forge/publisher-github",
config: {
repository: {
owner: 'MoolahModding',
name: 'MoolahModLauncher'
owner: "MoolahModding",
name: "MoolahModLauncher",
},
prerelease: true
}
}
]
prerelease: true,
},
},
],
}

export default config
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "run-p lint:*",
"lint:eslint": "eslint \"src/**/*.{js,ts,tsx}\"",
"lint:prettier": "prettier --check \"src/**/*.{js,ts,tsx}\"",
"format": "run-p format:*",
"format:eslint": "eslint \"src/**/*.{js,ts,tsx}\" --fix",
"format:prettier": "prettier --write \"src/**/*.{js,ts,tsx}\"",
"lint": "run-p \"lint:*\"",
"lint:eslint-src": "eslint \"src/**/*.{js,ts,tsx}\"",
"lint:eslint-config": "eslint \"./*.{js,ts}\"",
"lint:prettier-src": "prettier --check \"src/**/*.{js,ts,tsx}\"",
"lint:prettier-conifg": "prettier --check \"./*.{js,ts}\"",
"format": "run-p \"format:*\"",
"format:eslint-src": "eslint \"src/**/*.{js,ts,tsx}\" --fix",
"format:eslint-config": "eslint \"./*.{js,ts}\" --fix",
"format:prettier-src": "prettier --write \"src/**/*.{js,ts,tsx}\"",
"format:prettier-config": "prettier --write \"./*.{js,ts}\"",
"typecheck": "tsc --noEmit"
},
"repository": {
Expand Down
6 changes: 5 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { existsSync, writeFileSync, readFileSync } from "node:fs"
import path from "node:path"
import { exit } from "node:process"

import type { ConfigType } from "./types/config"

type ConfigKey = keyof ConfigType
Expand Down Expand Up @@ -45,7 +46,10 @@ class ConfigInternal {
if (existsSync(confPath)) {
try {
const configFile = readFileSync(confPath)
return new ConfigInternal(JSON.parse(configFile.toString()) as ConfigType, confPath) // TODO: safe parse JSON
return new ConfigInternal(
JSON.parse(configFile.toString()) as ConfigType,
confPath
) // TODO: safe parse JSON
} catch (err) {
console.error(err)
exit(1)
Expand Down
6 changes: 4 additions & 2 deletions src/filewatcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { WebContents } from "electron"
import path from "node:path"
import { getModsDirectory } from "./config"

import chokidar from "chokidar"
import type { WebContents } from "electron"

import { getModsDirectory } from "./config"

const watchPath = path.join(getModsDirectory())
const watcher = chokidar.watch(watchPath)
Expand Down
1 change: 1 addition & 0 deletions src/installedlistpopulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
readFileSync,
} from "node:fs"
import path from "node:path"

import { getModsDirectory } from "./config"

// TODO: refactor
Expand Down
3 changes: 2 additions & 1 deletion src/installlocators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from "node:fs"
import path from "node:path"
import regedit from "winreg"

import drivelist from "drivelist"
import regedit from "winreg"

// TODO: refactor

Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { exit } from "node:process"
import { app, BrowserWindow, dialog, ipcMain, shell } from "electron"
import { exit } from "node:process"

// import filewatcher from './filewatcher'
import { installAllPackages } from "./mod_installer"
import { config } from "./config"
import { resolveInstall } from "./installlocators"
import { installAllPackages } from "./mod_installer"
import { installShellExtension, uninstallShellExtension } from "./setup_win32"
import { config } from "./config"

// TODO: refactor

Expand Down
8 changes: 5 additions & 3 deletions src/mod_installer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { dialog, app } from "electron"
import path from "node:path"

import AdmZip from "adm-zip"
import fs from "fs-extra"
import path from "node:path"
import toposort from "toposort"
import { globSync } from "glob"
import toposort from "toposort"

import { config, getModsDirectory } from "./config"
import { dialog, app } from "electron"


// TODO: refactor, add types

Expand Down
2 changes: 1 addition & 1 deletion src/mod_updater.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentModVersionByMWS } from "./providers/modworkshop"
import { getLatestModVersionByGitHub } from "./providers/githubreleases"
import { getCurrentModVersionByMWS } from "./providers/modworkshop"

// TODO: refactor

Expand Down
7 changes: 7 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*",
"./*.ts",
]
}
8 changes: 4 additions & 4 deletions webpack.main.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const mainConfig: Configuration = {
rules: commonRules,
},
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
extensions: [".js", ".ts", ".jsx", ".tsx", ".css", ".json"],
},
// ! prevent `UnhandledSchemeError` ref: https://github.com/webpack/webpack/issues/13290
externals: {
"node:fs": {},
"node:process": {},
"node:path": {}
}
"node:path": {},
},
}

export { mainConfig }
export { mainConfig }
2 changes: 1 addition & 1 deletion webpack.plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin"
import type { WebpackPluginInstance } from "webpack"

const commonPlugins: WebpackPluginInstance[] = [
new ForkTsCheckerWebpackPlugin()
new ForkTsCheckerWebpackPlugin(),
]

export { commonPlugins }
13 changes: 7 additions & 6 deletions webpack.renderer.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Configuration } from "webpack"
import { rendererRules } from "./webpack.rules"
import type { Configuration } from "webpack"

import { commonPlugins } from "./webpack.plugins"
import { rendererRules } from "./webpack.rules"

const rendererConfig: Configuration = {
// XXX: should add `optimization` key for production?
Expand All @@ -10,14 +11,14 @@ const rendererConfig: Configuration = {
},
plugins: commonPlugins,
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css'],
extensions: [".js", ".ts", ".jsx", ".tsx", ".css"],
},
// ! prevent `UnhandledSchemeError` ref: https://github.com/webpack/webpack/issues/13290
externals: {
"node:fs": {},
"node:process": {},
"node:path": {}
}
"node:path": {},
},
}

export { rendererConfig }
export { rendererConfig }
12 changes: 6 additions & 6 deletions webpack.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ type RuleOptions = Required<ModuleOptions>["rules"]
const commonRules: RuleOptions = [
{
test: /native_modules[/\\].+\.node$/,
use: 'node-loader',
use: "node-loader",
},
{
test: /[/\\]node_modules[/\\].+\.(m?js|node)$/,
parser: { amd: false },
use: {
loader: '@vercel/webpack-asset-relocator-loader',
loader: "@vercel/webpack-asset-relocator-loader",
options: {
outputAssetBase: 'native_modules',
outputAssetBase: "native_modules",
},
},
},
Expand All @@ -22,7 +22,7 @@ const commonRules: RuleOptions = [
test: /\.tsx?$/,
exclude: /(node_modules|\.webpack)/,
use: {
loader: 'ts-loader',
loader: "ts-loader",
options: {
transpileOnly: true,
},
Expand All @@ -34,8 +34,8 @@ const rendererAdditionalRules: RuleSetRule[] = [
{
// XXX: should use `MiniCssExtractPlugin.loader` in production?
test: /\.css$/,
use: ['style-loader', 'css-loader'],
}
use: ["style-loader", "css-loader"],
},
]

const rendererRules: RuleOptions = [...commonRules, ...rendererAdditionalRules]
Expand Down

0 comments on commit f0324c1

Please sign in to comment.