Code Styling Changes (!326)

- Drops DPrint
- Drops Biome
- Adds ESList Stylistic
- Adds ESLint Import Plugin
- Updates ESLint Config
- Removed dprint.dprint and biomejs.biome VSC extentions from recommendations
- Updates README to reflect all the above changes
- Updates workflow files
    - Removes style action
    - Updates messaging on lint action
This commit is contained in:
Refringe 2024-05-08 01:35:59 +00:00
commit 45bf159bb8
12 changed files with 129 additions and 351 deletions

61
.gitattributes vendored
View File

@ -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

View File

@ -53,6 +53,7 @@ jobs:
- name: Fix Instructions
if: failure() && steps.run-tests.outcome == 'failure'
run: |
echo -e "Code linting has failed. The linter has been configured to look for coding errors, defects, and questionable patterns. Please look into resolving these errors. The linter may be able to resolve some of these issues automatically. You can launch the automatic fixer by running the following command from within the 'project' directory. Anything not resolved by running this command must be resolved manually.\n\nnpm run lint:fix\n"
echo -e "Code linting has failed. The linter has been configured to look for coding errors, defects, questionable patterns, and code formatting issues. Please look into resolving these errors. The linter may be able to resolve some of these issues automatically. You can launch the automatic fixer by running the following command from within the 'project' directory. Anything not resolved by running this command must be resolved manually.\n\nnpm run lint:fix\n"
echo -e "To automatically format code on-save in your IDE, please install the recommended VSCode plugins listed within the 'project/Server.code-workspace' file.\n"
echo -e "Consistency is professionalism.™"
shell: bash

View File

@ -1,59 +0,0 @@
name: Check Code Style
on:
push:
branches: '*'
pull_request:
branches: '*'
jobs:
dprint:
runs-on: ubuntu-latest
container:
image: refringe/spt-build-node:1.0.7
steps:
- name: Clone
run: |
rm -rf /workspace/SPT-AKI/Build/server
git clone https://dev.sp-tarkov.com/${GITHUB_REPOSITORY}.git --branch master /workspace/SPT-AKI/Build/server
cd /workspace/SPT-AKI/Build/server
git checkout ${GITHUB_SHA}
shell: bash
- name: Pull LFS Files
run: |
cd /workspace/SPT-AKI/Build/server
git lfs pull
git lfs ls-files
shell: bash
- name: Cache NPM Dependencies
id: cache-npm-dependencies
uses: actions/cache@v4
with:
path: /workspace/SPT-AKI/Build/server/project/node_modules
key: npm-dependencies-${{ hashFiles('/workspace/SPT-AKI/Build/server/project/package.json') }}
- name: Install NPM Dependencies
if: steps.cache-npm-dependencies.outputs.cache-hit != 'true'
run: |
cd /workspace/SPT-AKI/Build/server/project
rm -rf node_modules
npm install
shell: bash
- name: Check Code Style
id: check-code-style
run: |
cd /workspace/SPT-AKI/Build/server/project
npm run style
shell: bash
- name: Fix Instructions
if: failure() && steps.check-code-style.outcome == 'failure'
run: |
echo -e "The code style check has failed. To fix this, please ensure your code adheres to the project's style guidelines. You can automatically format the project code by running the following command from within the 'project' directory.\n\nnpm run style:fix\n"
echo -e "To automatically format code on-save in your IDE, please install the recommended VSCode plugins listed within the 'project/Server.code-workspace' file.\n"
echo -e "Thank you for keeping our house clean. ♥"
shell: bash

View File

@ -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
@ -55,12 +53,10 @@ 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>`.
| 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. |
| `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. |
@ -111,7 +107,7 @@ We're really excited that you're interested in contributing! Before submitting y
### 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

View File

@ -7,3 +7,6 @@ charset = utf-8
indent_style = space
indent_size = 4
max_line_length = 120
[*.md]
trim_trailing_whitespace = false

View File

@ -1,5 +1,5 @@
# Exclude these folders from linting
node_modules
node_modules/
out/
obj/
build/

View File

@ -1,23 +1,34 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"env": {
"node": true
},
"extends": [
"plugin:@typescript-eslint/eslint-recommended"
"plugin:@typescript-eslint/recommended",
"plugin:@stylistic/recommended-extends",
"plugin:import/recommended",
"plugin:import/typescript"
],
"plugins": [
"@typescript-eslint",
"@stylistic",
"import"
],
"settings": {
"import/resolver": {
"typescript": {
"project": "tsconfig.json"
},
"node": {
"extensions": [".ts", ".mjs"]
}
}
},
"rules": {
"brace-style": ["error", "allman"],
"@typescript-eslint/no-namespace": "off",
"@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-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/explicit-module-boundary-types": ["error", {
"allowArgumentsExplicitlyTypedAsAny": true
}],
"@typescript-eslint/naming-convention": ["error", {
"selector": "default",
"format": ["camelCase"],
@ -40,24 +51,63 @@
"selector": "property",
"modifiers": ["readonly", "static"],
"format": ["UPPER_CASE"]
}],
"@stylistic/indent": ["error", 4, { "MemberExpression": 1, "SwitchCase": 1 }],
"@stylistic/brace-style": ["error", "allman", { "allowSingleLine": false }],
"@stylistic/semi": ["error", "always"],
"@stylistic/quotes": ["error", "double", { "avoidEscape": true }],
"@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/no-extra-parens": ["error", "all"],
"@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"],
"import/order": ["error", {
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
"pathGroups": [
{
"pattern": "tsyringe",
"group": "builtin",
"position": "before"
}
],
"newlines-between": "never",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}]
},
"overrides": [{
"files": [
"src/loaders/**/*.ts"
],
"overrides": [
{
"files": ["src/di/**/*.ts"],
"rules": {
"@typescript-eslint/no-extraneous-class": "off"
}
},
{
"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
}]
}
}]
]
}

View File

@ -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"
]
}

View File

@ -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": false
}
}

View File

@ -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__/**/*"
]
}
}

View File

@ -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"
]
}

View File

@ -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,15 +59,16 @@
"@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",
"eslint-import-resolver-typescript": "~3.6",
"eslint-plugin-import": "~2.29",
"fs-extra": "~11.2",
"gulp": "~4.0",
"gulp-decompress": "~3.0",
@ -82,6 +82,7 @@
"tsconfig-paths": "~4.2",
"typedoc": "~0.25",
"typemoq": "~2.1",
"typescript-eslint": "~7.8",
"vitest": "~1.3"
},
"targets": {