From 6921f9363d0d7ec5d8c05c2fcd0414365bdb613e Mon Sep 17 00:00:00 2001 From: Refringe Date: Mon, 6 May 2024 02:35:06 -0400 Subject: [PATCH] Code Styling Changes - Drops DPrint - Drops Biome - Adds ESList Stylistic - Updates ESLint config to new FlatConfig format - Removed the `dprint.dprint` and `biomejs.biome` VSC extentions from the recommendations list - Updates README to reflect all the above changes TODO: Import sorting & minor fixes after `npm run lint:fix`. Curse you, Alex! --- .gitattributes | 61 ++-------------------- README.md | 60 ++++++++++------------ project/.eslintignore | 4 +- project/.eslintrc.json | 63 ----------------------- project/.vscode/extensions.json | 6 +-- project/Server.code-workspace | 10 ++-- project/biome.json | 69 ------------------------- project/dprint.json | 90 --------------------------------- project/eslint.config.mjs | 81 +++++++++++++++++++++++++++++ project/package.json | 17 +++---- 10 files changed, 130 insertions(+), 331 deletions(-) delete mode 100644 project/.eslintrc.json delete mode 100644 project/biome.json delete mode 100644 project/dprint.json create mode 100644 project/eslint.config.mjs diff --git a/.gitattributes b/.gitattributes index a32b9f86..a03b251e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,62 +1,7 @@ -############################################################################### -# Set default behavior to automatically normalize line endings. -############################################################################### +# Normalize Line Endings * text=auto eol=lf -############################################################################### -# Set default behavior for command prompt diff. -# -# This is need for earlier builds of msysgit that does not have it on by -# default for csharp files. -# Note: This is only used by command line -############################################################################### -#*.cs diff=csharp -############################################################################### -# Set the merge driver for project and solution files -# -# Merging from the command prompt will add diff markers to the files if there -# are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following -# file extensions to fail to load in VS. An alternative would be to treat -# these files as binary and thus will always conflict and require user -# intervention with every merge. To do so, just uncomment the entries below -############################################################################### -#*.sln merge=binary -#*.csproj merge=binary -#*.vbproj merge=binary -#*.vcxproj merge=binary -#*.vcproj merge=binary -#*.dbproj merge=binary -#*.fsproj merge=binary -#*.lsproj merge=binary -#*.wixproj merge=binary -#*.modelproj merge=binary -#*.sqlproj merge=binary -#*.wwaproj merge=binary -############################################################################### -# behavior for image files -# -# image files are treated as binary by default. -############################################################################### -#*.jpg binary -#*.png binary -#*.gif binary -############################################################################### -# diff behavior for common document formats -# -# Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the -# entries below. -############################################################################### -#*.doc diff=astextplain -#*.DOC diff=astextplain -#*.docx diff=astextplain -#*.DOCX diff=astextplain -#*.dot diff=astextplain -#*.DOT diff=astextplain -#*.pdf diff=astextplain -#*.PDF diff=astextplain -#*.rtf diff=astextplain -#*.RTF diff=astextplain + +# LFS File Listing project/assets/database/locations/interchange/looseLoot.json filter=lfs diff=lfs merge=lfs -text project/assets/database/locations/lighthouse/looseLoot.json filter=lfs diff=lfs merge=lfs -text project/assets/database/locations/shoreline/looseLoot.json filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md index de26217d..91d3b0aa 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,7 @@ This project has been built in [Visual Studio Code](https://code.visualstudio.co There are a number of VSC extensions that we recommended for this project. VSC will prompt you to install these when you open the workspace file. If you do not see the prompt, you can install them manually: - [EditorConfig](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) - Editor Settings Synchronization -- [Dprint Code Formatter](https://marketplace.visualstudio.com/items?itemName=dprint.dprint) - Formatting on Save - [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) - Linting for Coding Issues & Naming Conventions -- [Biome](https://marketplace.visualstudio.com/items?itemName=biomejs.biome) - Linting for Coding Standards - [Vitest](https://marketplace.visualstudio.com/items?itemName=vitest.explorer) - Debugging Tests - [SPT ID Highlighter](https://marketplace.visualstudio.com/items?itemName=refringe.spt-id-highlighter) - Converts IDs to Names @@ -54,26 +52,24 @@ To prepare the project for development you will need to: The following commands are available after the initial setup. Run them with `npm run `. -| Command | Description | -|--------------------------|----------------------------------------------------------------------| -| `check:circular` | Check for circular dependencies in the project. | -| `lint` | Lint the project for coding standards. | -| `lint:fix` | Attempt to automatically fix coding standard issues. | -| `style` | Check the project for style/formatting issues. | -| `style:fix` | Attempt to automatically fix style/formatting issues. | -| `test` | Run all tests. | -| `test:watch` | Run tests in watch mode. Tests will re-run when files are changed. | -| `test:coverage` | Run tests and generate a coverage report. | -| `test:ui` | Run tests in UI mode. This will open a browser window to view tests. | -| `build:release` | Build the project for release. | -| `build:debug` | Build the project for debugging. | -| `build:bleeding` | Build the project on the bleeding edge. | -| `build:bleedingmods` | Build the project on the bleeding edge with mods. | -| `run:build` | Run the project in build mode. | -| `run:debug` | Run the project in debug mode. | -| `run:profiler` | Run the project in profiler mode. | -| `gen:types` | Generate types for the project. | -| `gen:docs` | Generate documentation for the project. | +| Command | Description | +|--------------------------|-----------------------------------------------------------------------| +| `check:circular` | Check for circular dependencies in the project. | +| `lint` | Check the project for coding standards and style/formatting issues. | +| `lint:fix` | Automatically fix coding standard issues and style/formatting issues. | +| `test` | Run all tests. | +| `test:watch` | Run tests in watch mode. Tests will re-run when files are changed. | +| `test:coverage` | Run tests and generate a coverage report. | +| `test:ui` | Run tests in UI mode. This will open a browser window to view tests. | +| `build:release` | Build the project for release. | +| `build:debug` | Build the project for debugging. | +| `build:bleeding` | Build the project on the bleeding edge. | +| `build:bleedingmods` | Build the project on the bleeding edge with mods. | +| `run:build` | Run the project in build mode. | +| `run:debug` | Run the project in debug mode. | +| `run:profiler` | Run the project in profiler mode. | +| `gen:types` | Generate types for the project. | +| `gen:docs` | Generate documentation for the project. | ### Debugging @@ -83,35 +79,35 @@ To debug the project in Visual Studio Code, you can select the `Run` tab and the To debug a server mod in Visual Studio Code, you can copy the mod files into the `user/mods` folder and then start the server in [debug mode](#debugging). You should now be able to set breakpoints in the mod's Typescript files and they will be hit when the server runs the mod files. -## Contributing +## Contributing We're really excited that you're interested in contributing! Before submitting your contribution, please consider the following: ### Branchs -- __master__ +- __master__ The default branch used for the latest stable release. This branch is protected and typically is only merges with release branches. -- __3.9.0-DEV__ +- __3.9.0-DEV__ Development for the next minor release of SPT. Minor releases target the latest version of EFT. Late in the minor release cycle the EFT version is frozen for stability to prepare for release. Larger changes to the project structure may be included in minor releases. -- __3.8.1-DEV__ +- __3.8.1-DEV__ Development for the next hotfix release of SPT. Hotfix releases include bug fixes and minor features that do not effect the coding structure of the project. Special care is taken to not break server mod stability. These always target the same version of EFT as the last minor release. ### Pull Request Guidelines -- __Keep Them Small__ +- __Keep Them Small__ If you're fixing a bug, try to keep the changes to the bug fix only. If you're adding a feature, try to keep the changes to the feature only. This will make it easier to review and merge your changes. -- __Perform a Self-Review__ +- __Perform a Self-Review__ Before submitting your changes, review your own code. This will help you catch any mistakes you may have made. -- __Remove Noise__ +- __Remove Noise__ Remove any unnecessary changes to white space, code style formatting, or some text change that has no impact related to the intention of the PR. -- __Create a Meaningful Title__ +- __Create a Meaningful Title__ When creating a PR, make sure the title is meaningful and describes the changes you've made. -- __Write Detailed Commit Messages__ +- __Write Detailed Commit Messages__ Bring out your table manners, speak the Queen's English and be on your best behaviour. ### Style Guide -We use Dprint to enforce a consistent code style. Please run `npm run style` and/or `npm run style:fix` before submitting your changes. This is made easier by using the recommended VSC extensions to automatically format your code whenever you save a file. +We use ESLint Stylistic to enforce a consistent code style. Please run `npm run lint` and/or `npm run lint:fix` before submitting your changes. This is made easier by using the recommended VSC extensions to automatically format your code whenever you save a file. ### Tests diff --git a/project/.eslintignore b/project/.eslintignore index 0761328e..607008c7 100644 --- a/project/.eslintignore +++ b/project/.eslintignore @@ -1,5 +1,5 @@ # Exclude these folders from linting -node_modules +node_modules/ out/ obj/ build/ @@ -12,4 +12,4 @@ user/mods/ *.ico *.jpg *.txt -*.exe \ No newline at end of file +*.exe diff --git a/project/.eslintrc.json b/project/.eslintrc.json deleted file mode 100644 index 72de65ff..00000000 --- a/project/.eslintrc.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "root": true, - "parser": "@typescript-eslint/parser", - "plugins": [ - "@typescript-eslint" - ], - "env": { - "node": true - }, - "extends": [ - "plugin:@typescript-eslint/eslint-recommended" - ], - "rules": { - "brace-style": ["error", "allman"], - "@typescript-eslint/no-namespace": "off", - "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/no-explicit-any": "off", // We use a bunch of these. - "@typescript-eslint/no-unused-vars": "off", // Typescript compiler already checks--Will grey out variable. - "@typescript-eslint/no-var-requires": "error", - "@typescript-eslint/explicit-module-boundary-types": ["error", { "allowArgumentsExplicitlyTypedAsAny": true }], - "@typescript-eslint/naming-convention": ["error", { - "selector": "default", - "format": ["camelCase"], - "leadingUnderscore": "allow" - }, { - "selector": "typeLike", - "format": ["PascalCase"] - }, { - "selector": "objectLiteralProperty", - "format": ["PascalCase", "camelCase", "snake_case"], - "leadingUnderscore": "allow" - }, { - "selector": "typeProperty", - "format": ["PascalCase", "camelCase"], - "leadingUnderscore": "allow" - }, { - "selector": "enumMember", - "format": ["UPPER_CASE"] - }, { - "selector": "property", - "modifiers": ["readonly", "static"], - "format": ["UPPER_CASE"] - }] - }, - "overrides": [{ - "files": [ - "src/loaders/**/*.ts" - ], - "rules": { - "@typescript-eslint/no-var-requires": "off" - } - }, { - "files": [ - "**/vitest.config.ts" - ], - "rules": { - "@typescript-eslint/naming-convention": ["error", { - "selector": "objectLiteralProperty", - "format": null - }] - } - }] -} diff --git a/project/.vscode/extensions.json b/project/.vscode/extensions.json index 49f98cc2..547ba280 100644 --- a/project/.vscode/extensions.json +++ b/project/.vscode/extensions.json @@ -1,10 +1,8 @@ { "recommendations": [ "EditorConfig.EditorConfig", - "dprint.dprint", - "dbaeumer.vscode-eslint", - "biomejs.biome", "vitest.explorer", - "refringe.spt-id-highlighter" + "refringe.spt-id-highlighter", + "dbaeumer.vscode-eslint" ] } diff --git a/project/Server.code-workspace b/project/Server.code-workspace index 5ab13e4e..40e7e4f7 100644 --- a/project/Server.code-workspace +++ b/project/Server.code-workspace @@ -7,9 +7,11 @@ "settings": { "window.title": "SPT-AKI Server", "editor.formatOnSave": true, - "editor.defaultFormatter": "dprint.dprint", - "editor.codeActionsOnSave": [ - "source.organizeImports.biome" - ] + "editor.defaultFormatter": "dbaeumer.vscode-eslint", + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + "eslint.debug": true, + "eslint.experimental.useFlatConfig": true } } diff --git a/project/biome.json b/project/biome.json deleted file mode 100644 index 0577bbda..00000000 --- a/project/biome.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", - "javascript": { - "parser": { - "unsafeParameterDecoratorsEnabled": true - } - }, - "organizeImports": { - "enabled": true - }, - "linter": { - "enabled": true, - "rules": { - "recommended": true, - "style": { - "useImportType": "off", - "noImplicitBoolean": "off", - "noParameterAssign": "warn", - "useTemplate": "warn", - "useSingleVarDeclarator": "warn" - }, - "a11y": { - "useKeyWithClickEvents": "off", - "useValidAnchor": "warn" - }, - "suspicious": { - "noExplicitAny": "off", - "noDoubleEquals": "warn", - "noShadowRestrictedNames": "warn", - "noEmptyInterface": "off" - }, - "performance": { - "noDelete": "off" - }, - "correctness": { - "noUnnecessaryContinue": "warn" - }, - "complexity": { - "noStaticOnlyClass": "off", - "useSimplifiedLogicExpression": "warn", - "useOptionalChain": "warn" - } - } - }, - "formatter": { - "enabled": false - }, - "files": { - "ignore": [ - "**/*.js", - "**/*.json", - "**/*.d.ts", - "**/Dockerfile.*", - "**/.git/**/*", - "**/.vscode/**/*", - "**/node_modules/**/*", - "**/build/**/*", - "**/obj/**/*", - "**/dist/**/*", - "**/user/**/*", - "**/logs/**/*", - "**/assets/**/*", - "**/Aki_Data/**/*", - "**/types/**/*", - "**/tests/__cache__/**/*", - "**/tests/__coverage__/**/*" - ] - } -} diff --git a/project/dprint.json b/project/dprint.json deleted file mode 100644 index 96405138..00000000 --- a/project/dprint.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "incremental": false, - "lineWidth": 120, - "indentWidth": 4, - "newLineKind": "lf", - "useTabs": false, - "typescript": { - "semiColons": "always", - "quoteStyle": "alwaysDouble", - "quoteProps": "asNeeded", - "useBraces": "always", - "bracePosition": "nextLine", - "singleBodyPosition": "maintain", - "nextControlFlowPosition": "nextLine", - "trailingCommas": "onlyMultiLine", - "operatorPosition": "nextLine", - "preferHanging": false, - "preferSingleLine": true, - "arrowFunction.useParentheses": "force", - "binaryExpression.linePerExpression": false, - "memberExpression.linePerExpression": false, - "typeLiteral.separatorKind": "semiColon", - "enumDeclaration.memberSpacing": "newLine", - "spaceAround": false, - "spaceSurroundingProperties": true, - "objectExpression.spaceSurroundingProperties": true, - "objectPattern.spaceSurroundingProperties": true, - "typeLiteral.spaceSurroundingProperties": true, - "binaryExpression.spaceSurroundingBitwiseAndArithmeticOperator": true, - "commentLine.forceSpaceAfterSlashes": true, - "constructor.spaceBeforeParentheses": false, - "constructorType.spaceAfterNewKeyword": false, - "constructSignature.spaceAfterNewKeyword": false, - "doWhileStatement.spaceAfterWhileKeyword": true, - "module.sortImportDeclarations": "maintain", - "module.sortExportDeclarations": "maintain", - "exportDeclaration.sortNamedExports": "maintain", - "importDeclaration.sortNamedImports": "maintain", - "exportDeclaration.spaceSurroundingNamedExports": false, - "forInStatement.spaceAfterForKeyword": true, - "forOfStatement.spaceAfterForKeyword": true, - "forStatement.spaceAfterForKeyword": true, - "forStatement.spaceAfterSemiColons": true, - "functionDeclaration.spaceBeforeParentheses": false, - "functionExpression.spaceBeforeParentheses": false, - "functionExpression.spaceAfterFunctionKeyword": false, - "getAccessor.spaceBeforeParentheses": false, - "ifStatement.spaceAfterIfKeyword": true, - "importDeclaration.spaceSurroundingNamedImports": true, - "method.spaceBeforeParentheses": false, - "setAccessor.spaceBeforeParentheses": false, - "taggedTemplate.spaceBeforeLiteral": false, - "typeAnnotation.spaceBeforeColon": false, - "typeAssertion.spaceBeforeExpression": false, - "whileStatement.spaceAfterWhileKeyword": true - }, - "json": { - "trailingCommas": "never", - "preferSingleLine": false - }, - "markdown": { - "textWrap": "always", - "emphasisKind": "underscores", - "strongKind": "asterisks" - }, - "dockerfile": {}, - "excludes": [ - "**/*.js", - "**/*.d.ts", - "**/*-lock.json", - "**/.git/**/*", - "**/node_modules/**/*", - "**/build/**/*", - "**/obj/**/*", - "**/dist/**/*", - "**/user/**/*", - "**/logs/**/*", - "**/assets/**/*", - "**/Aki_Data/**/*", - "**/types/**/*", - "**/tests/__cache__/**/*", - "**/tests/__coverage__/**/*" - ], - "plugins": [ - "https://plugins.dprint.dev/typescript-0.88.3.wasm", - "https://plugins.dprint.dev/json-0.19.0.wasm", - "https://plugins.dprint.dev/markdown-0.16.2.wasm", - "https://plugins.dprint.dev/dockerfile-0.3.0.wasm" - ] -} diff --git a/project/eslint.config.mjs b/project/eslint.config.mjs new file mode 100644 index 00000000..537b7024 --- /dev/null +++ b/project/eslint.config.mjs @@ -0,0 +1,81 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import tseslint from 'typescript-eslint'; +import stylistic from '@stylistic/eslint-plugin' + +export default tseslint.config( + ...tseslint.configs.strict, + ...tseslint.configs.stylistic, + { + plugins: { + '@stylistic': stylistic + }, + rules: { + "@typescript-eslint/no-explicit-any": 'off', + "@typescript-eslint/no-dynamic-delete": 'off', + "@typescript-eslint/no-unused-vars": 'off', + "@typescript-eslint/no-empty-interface": 'off', + "@typescript-eslint/no-var-requires": "error", + "@typescript-eslint/explicit-module-boundary-types": ["error", { + "allowArgumentsExplicitlyTypedAsAny": true + }], + "@typescript-eslint/naming-convention": ["error", { + "selector": "default", + "format": ["camelCase"], + "leadingUnderscore": "allow" + }, { + "selector": "typeLike", + "format": ["PascalCase"] + }, { + "selector": "objectLiteralProperty", + "format": ["PascalCase", "camelCase", "snake_case"], + "leadingUnderscore": "allow" + }, { + "selector": "typeProperty", + "format": ["PascalCase", "camelCase"], + "leadingUnderscore": "allow" + }, { + "selector": "enumMember", + "format": ["UPPER_CASE"] + }, { + "selector": "property", + "modifiers": ["readonly", "static"], + "format": ["UPPER_CASE"] + }], + "@stylistic/indent": ["error", 4, { "MemberExpression": 1, "SwitchCase": 1 }], + "@stylistic/brace-style": ["error", "allman", { "allowSingleLine": false }], + "@stylistic/linebreak-style": ["error", "unix"], + "@stylistic/max-len": ["error", { + "code": 120, + "tabWidth": 4, + "ignoreComments": true, + "ignoreTrailingComments": true, + "ignoreUrls": true, + "ignoreStrings": true, + "ignoreTemplateLiterals": true, + "ignoreRegExpLiterals": true + }], + "@stylistic/multiline-ternary": ["error", "always-multiline"], + "@stylistic/new-parens": "error", + "@stylistic/newline-per-chained-call": ["error", { "ignoreChainWithDepth": 3 }], + "@stylistic/no-extra-semi": "error", + "@stylistic/no-floating-decimal": "error", + "@stylistic/no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }], + "@stylistic/switch-colon-spacing": "error", + "@stylistic/type-annotation-spacing": "error", + "@stylistic/type-generic-spacing": ["error"], + "@stylistic/type-named-tuple-spacing": ["error"], + "@stylistic/wrap-regex": "error", + "@stylistic/yield-star-spacing": ["error", "both"], + } + }, { + "files": ["src/di/**/*.ts"], + "rules": { + "@typescript-eslint/no-extraneous-class": 'off', + } + }, { + "files": ["src/loaders/**/*.ts"], + "rules": { + "@typescript-eslint/no-var-requires": "off" + } + } +); diff --git a/project/package.json b/project/package.json index 6052b048..a633029e 100644 --- a/project/package.json +++ b/project/package.json @@ -12,10 +12,8 @@ }, "scripts": { "check:circular": "madge --circular --ts-config tsconfig.json --extensions ts ./src/", - "lint": "biome ci src --formatter-enabled=false --max-diagnostics=200", - "lint:fix": "biome check --apply-unsafe --max-diagnostics=200 . && dprint fmt --incremental=false", - "style": "dprint check --incremental=false", - "style:fix": "dprint fmt --incremental=false", + "lint": "eslint src", + "lint:fix": "eslint src --fix", "test": "vitest run", "test:watch": "vitest", "test:coverage": "vitest run --coverage", @@ -32,7 +30,7 @@ }, "dependencies": { "atomically": "~1.7", - "buffer-crc32": "^1.0.0", + "buffer-crc32": "~1.0", "date-fns": "~2.30", "date-fns-tz": "~2.0", "i18n": "~0.15", @@ -51,8 +49,9 @@ "ws": "~8.16" }, "devDependencies": { - "@biomejs/biome": "~1.6", + "@eslint/js": "~9.2", "@pnpm/exe": "8.15.4", + "@stylistic/eslint-plugin": "~1.8", "@swc/cli": "~0.3", "@swc/core": "~1.4", "@types/i18n": "~0.13", @@ -60,14 +59,13 @@ "@types/proper-lockfile": "~4.1", "@types/semver": "~7.5", "@types/ws": "~8.5", - "@typescript-eslint/eslint-plugin": "~7.2", - "@typescript-eslint/parser": "~7.2", + "@typescript-eslint/eslint-plugin": "~7.8", + "@typescript-eslint/parser": "~7.8", "@vitest/coverage-istanbul": "~1.3", "@vitest/ui": "~1.3", "@yao-pkg/pkg": "5.11.5", "@yao-pkg/pkg-fetch": "3.5.9", "cross-env": "~7.0", - "dprint": "~0.45", "eslint": "~8.57", "fs-extra": "~11.2", "gulp": "~4.0", @@ -82,6 +80,7 @@ "tsconfig-paths": "~4.2", "typedoc": "~0.25", "typemoq": "~2.1", + "typescript-eslint": "~7.8", "vitest": "~1.3" }, "targets": {