Skip to content

Commit

Permalink
Merge pull request #30 from tobspr-games/dengr1065/eslint-tsc-revamp
Browse files Browse the repository at this point in the history
Redo ESLint and TypeScript configuration
  • Loading branch information
dengr1065 authored Jun 18, 2024
2 parents 878f0e1 + 84350a4 commit 60b2727
Show file tree
Hide file tree
Showing 21 changed files with 404 additions and 431 deletions.
11 changes: 0 additions & 11 deletions .eslintignore

This file was deleted.

26 changes: 0 additions & 26 deletions .eslintrc.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ node_modules/
# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

Expand Down
2 changes: 0 additions & 2 deletions electron/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable quotes,no-undef */

const { app, BrowserWindow, Menu, MenuItem, ipcMain, shell, dialog, session } = require("electron");
const path = require("path");
const url = require("url");
Expand Down
66 changes: 66 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import eslint from "@eslint/js";
import globals from "globals";
import path from "path";
import tseslint from "typescript-eslint";
import { fileURLToPath } from "url";

const baseConfig = tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
// Enable type-aware linting
{
languageOptions: {
parserOptions: {
project: true,
// FIXME: Node.js 21.2.0 introduced import.meta.dirname
tsconfigRootDir: path.dirname(fileURLToPath(import.meta.url)),
},
},
},
// Disable type-aware linting for JS files as it causes issues
{
files: ["*.js"],
...tseslint.configs.disableTypeChecked,
}
);

const nodeConfig = tseslint.config(...baseConfig, {
languageOptions: {
sourceType: "module",
globals: {
...globals.node,
},
},
});

const runtimeConfig = tseslint.config(...baseConfig, {
languageOptions: {
sourceType: "module",
globals: {
...globals.browser,
},
},
rules: {
// Mostly caused by JSDoc imports, so don't annoy with errors but keep
// a reminder!
"@typescript-eslint/no-unused-vars": "warn",
// FIXME: enforce when we're ready to
"prefer-const": "warn",
},
});

// I don't know what the ESLint devs were thinking about. This is just horrible
export default [
{
ignores: ["build/*"],
},
...nodeConfig.map(config => ({
...config,
files: ["*.(ts|js)", "(gulp|electron)/**/*.(ts|js)"],
ignores: ["gulp/preloader/*.js"],
})),
...runtimeConfig.map(config => ({
...config,
files: ["src/**/*.(ts|js)x?"],
})),
];
2 changes: 1 addition & 1 deletion gulp/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function convertJsToTs() {
}

export async function copyTsconfigForHints() {
const src = (await fs.readFile(path.join("..", "src", "js", "tsconfig.json"))).toString();
const src = (await fs.readFile(path.join("..", "src", "tsconfig.json"))).toString();
const baseConfig = JSON.parse(stripJsonComments(src));

baseConfig.allowJs = false;
Expand Down
6 changes: 0 additions & 6 deletions gulp/jsconfig.json

This file was deleted.

59 changes: 0 additions & 59 deletions gulp/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion gulp/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const moduleRules = [
loader: "ts-loader",

options: {
configFile: resolve("../src/js/tsconfig.json"),
configFile: resolve("../src/tsconfig.json"),
onlyCompileBundledFiles: true,
transpileOnly: true,
experimentalWatchApi: true,
Expand Down
2 changes: 1 addition & 1 deletion gulp/webpack.production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const moduleRules = [
loader: "ts-loader",

options: {
configFile: resolve("../src/js/tsconfig.json"),
configFile: resolve("../src/tsconfig.json"),
onlyCompileBundledFiles: true,
transpileOnly: true,
experimentalWatchApi: true,
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "module",
"scripts": {
"gulp": "gulp --cwd gulp",
"lint": "eslint src/js",
"lint": "(eslint . && tsc && tsc -p src) || (tsc && tsc -p src) || tsc -p src",
"prettier-all": "prettier --write src/**/*.* && prettier --write gulp/**/*.*",
"buildTypes": "tsc src/js/application.js --declaration --allowJs --emitDeclarationOnly --skipLibCheck --out types.js",
"package-win32-x64": "gulp --cwd gulp package.standalone-steam.win32-x64",
Expand All @@ -32,15 +32,17 @@
"semver": "^7.3.5"
},
"devDependencies": {
"@eslint/js": "^9.1.1",
"@tsconfig/node-lts": "^20.1.3",
"@tsconfig/strictest": "^2.0.5",
"@types/circular-dependency-plugin": "^5.0.5",
"@types/eslint__js": "^8.42.3",
"@types/filesystem": "^0.0.29",
"@types/gulp": "^4.0.9",
"@types/gulp-htmlmin": "^1.3.32",
"@types/lz-string": "^1.3.34",
"@types/node": "^16.0.0",
"@types/webpack": "^5.28.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"browser-sync": "^2.27.10",
"circular-dependency-plugin": "^5.2.2",
"css-mqpacker": "^7.0.0",
Expand All @@ -49,10 +51,9 @@
"delete-empty": "^3.0.0",
"electron-notarize": "^1.2.1",
"electron-packager": "^15.4.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint": "^9.1.1",
"glob": "^7.1.3",
"globals": "^15.0.0",
"gulp": "^4.0.2",
"gulp-audiosprite": "^1.1.0",
"gulp-cache": "^1.1.3",
Expand Down Expand Up @@ -84,7 +85,8 @@
"strip-json-comments": "^3.0.1",
"terser-webpack-plugin": "^5.3.6",
"ts-loader": "^9.4.2",
"typescript": "^5.0.1-rc",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.1",
"webpack": "^5.75.0",
"webpack-deadcode-plugin": "^0.1.17",
"webpack-stream": "^7.0.0",
Expand Down
3 changes: 0 additions & 3 deletions src/js/core/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,15 @@ export function globalDebug(context, ...args) {
}

export function globalLog(context, ...args) {
// eslint-disable-next-line no-console
logInternal(context, console.log, prepareArgsForLogging(args));
}

export function globalWarn(context, ...args) {
// eslint-disable-next-line no-console
logInternal(context, console.warn, prepareArgsForLogging(args));
}

export function globalError(context, ...args) {
args = prepareArgsForLogging(args);
// eslint-disable-next-line no-console
logInternal(context, console.error, args);
}

Expand Down
2 changes: 0 additions & 2 deletions src/js/core/lzstring.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ function _compress(uncompressed, bitsPerChar, getCharFromInt) {
}

// Flush the last char
// eslint-disable-next-line no-constant-condition
while (true) {
context_data_val = context_data_val << 1;
if (context_data_position == bitsPerChar - 1) {
Expand Down Expand Up @@ -400,7 +399,6 @@ function _decompress(length, resetValue, getNextValue) {
w = c;
result.push(c);

// eslint-disable-next-line no-constant-condition
while (true) {
if (data.index > length) {
return "";
Expand Down
1 change: 0 additions & 1 deletion src/js/core/sprites.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class BaseSprite {
* @param {number} h
*/
draw(context, x, y, w, h) {
// eslint-disable-line no-unused-vars
abstract;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/js/game/entity_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export class EntityManager extends BasicSerializableObject {
}

// Processes the entities to destroy and actually destroys them
/* eslint-disable max-statements */
processDestroyList() {
for (let i = 0; i < this.destroyList.length; ++i) {
const entity = this.destroyList[i];
Expand Down
1 change: 0 additions & 1 deletion src/js/game/root.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
import { Signal } from "../core/signal";
import { RandomNumberGenerator } from "../core/rng";
import { createLogger } from "../core/logging";
Expand Down
50 changes: 0 additions & 50 deletions src/js/tsconfig.json

This file was deleted.

8 changes: 3 additions & 5 deletions src/js/webworkers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": ["../../tsconfig"],
"compilerOptions": {
"lib": ["ES2018", "WebWorker"]
},
"exclude": [],
"extends": "../tsconfig",
"include": ["*.worker.js"]
"lib": ["WebWorker"]
}
}
Loading

0 comments on commit 60b2727

Please sign in to comment.