From 75c0d9f3bc2ab86da6d1e12567303ce664c0758a Mon Sep 17 00:00:00 2001 From: Francisco Alejandro Garcia Cebada <93944312+frgarc@users.noreply.github.com> Date: Thu, 9 May 2024 15:49:05 -0700 Subject: [PATCH] Adding linting check for core-build-task (#28) * - Adding basic linting to core-build-tasks * Change files * - Dummy change * - Fixing prettier config * - Reverting readme file changes * - Using gitattributes file instead. * - Using endOfLine auto again * - Fixing nit for the task --- .vscode/settings.json | 11 + ...-268ae585-2ff5-4e08-8d7a-de34c01ca869.json | 7 + ...-4ca66802-83ea-472e-b2ea-b8ba47e0bcb0.json | 7 + libraries/math/package.json | 3 +- .../math/src/vector3/coreHelpers.test.ts | 4 +- libraries/math/src/vector3/coreHelpers.ts | 11 +- .../math/src/vector3/vectorWrapper.test.ts | 2 +- libraries/math/src/vector3/vectorWrapper.ts | 3 +- package-lock.json | 211 +++++++++++++----- prettier.config.js | 2 +- tools/core-build-tasks/eslint.config.mjs | 21 ++ tools/core-build-tasks/just.config.ts | 6 +- tools/core-build-tasks/package.json | 5 +- tools/core-build-tasks/src/tasks/coreLint.ts | 11 +- .../helpers/getGameDeploymentRootPaths.ts | 4 +- 15 files changed, 230 insertions(+), 78 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 change/@minecraft-core-build-tasks-268ae585-2ff5-4e08-8d7a-de34c01ca869.json create mode 100644 change/@minecraft-math-4ca66802-83ea-472e-b2ea-b8ba47e0bcb0.json create mode 100644 tools/core-build-tasks/eslint.config.mjs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a6b8c01 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "eslint.experimental.useFlatConfig": true, + "eslint.workingDirectories": [ + { + "pattern": "./libraries/*/" + }, + { + "pattern": "./tools/*/" + } + ] +} \ No newline at end of file diff --git a/change/@minecraft-core-build-tasks-268ae585-2ff5-4e08-8d7a-de34c01ca869.json b/change/@minecraft-core-build-tasks-268ae585-2ff5-4e08-8d7a-de34c01ca869.json new file mode 100644 index 0000000..5fcda28 --- /dev/null +++ b/change/@minecraft-core-build-tasks-268ae585-2ff5-4e08-8d7a-de34c01ca869.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "- Adding basic linting to core-build-tasks", + "packageName": "@minecraft/core-build-tasks", + "email": "frgarc@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@minecraft-math-4ca66802-83ea-472e-b2ea-b8ba47e0bcb0.json b/change/@minecraft-math-4ca66802-83ea-472e-b2ea-b8ba47e0bcb0.json new file mode 100644 index 0000000..2703c49 --- /dev/null +++ b/change/@minecraft-math-4ca66802-83ea-472e-b2ea-b8ba47e0bcb0.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "Enabling prettier check", + "packageName": "@minecraft/math", + "email": "frgarc@microsoft.com", + "dependentChangeType": "none" +} diff --git a/libraries/math/package.json b/libraries/math/package.json index dc74517..0428abc 100644 --- a/libraries/math/package.json +++ b/libraries/math/package.json @@ -36,6 +36,7 @@ "@minecraft/core-build-tasks": "*", "@minecraft/tsconfig": "*", "just-scripts": "^2.2.1", + "prettier": "^2.8.2", "vitest": "^0.34.6" } -} +} \ No newline at end of file diff --git a/libraries/math/src/vector3/coreHelpers.test.ts b/libraries/math/src/vector3/coreHelpers.test.ts index c3e6466..1d854d5 100644 --- a/libraries/math/src/vector3/coreHelpers.test.ts +++ b/libraries/math/src/vector3/coreHelpers.test.ts @@ -178,9 +178,9 @@ describe('Vector3 operations', () => { it('calculates the lerp halfway between two vectors', () => { const result: Vector3 = Vector3Utils.lerp(v1, v2, 0.5); - expect(result).toEqual({ x: 2.5, y: 3.5, z: 4.5}); + expect(result).toEqual({ x: 2.5, y: 3.5, z: 4.5 }); }); - + it('calculates the slerp halfway between two vectors', () => { const vecA: Vector3 = { x: 1, y: 0, z: 0 }; const vecB: Vector3 = { x: 0, y: -1, z: 0 }; diff --git a/libraries/math/src/vector3/coreHelpers.ts b/libraries/math/src/vector3/coreHelpers.ts index cb4932c..ff83ed4 100644 --- a/libraries/math/src/vector3/coreHelpers.ts +++ b/libraries/math/src/vector3/coreHelpers.ts @@ -125,7 +125,7 @@ export class Vector3Utils { limits?: { min?: Partial; max?: Partial; - }, + } ): Vector3 { return { x: clampNumber(v.x, limits?.min?.x ?? Number.MIN_SAFE_INTEGER, limits?.max?.x ?? Number.MAX_SAFE_INTEGER), @@ -154,10 +154,10 @@ export class Vector3Utils { */ static slerp(a: Vector3, b: Vector3, t: number): Vector3 { const theta = Math.acos(Vector3Utils.dot(a, b)); - const sinTheta = Math.sin(theta); - const ta = Math.sin((1.0 - t) * theta) / sinTheta; - const tb = Math.sin(t * theta) / sinTheta; - return Vector3Utils.add(Vector3Utils.scale(a, ta), Vector3Utils.scale(b, tb)); + const sinTheta = Math.sin(theta); + const ta = Math.sin((1.0 - t) * theta) / sinTheta; + const tb = Math.sin(t * theta) / sinTheta; + return Vector3Utils.add(Vector3Utils.scale(a, ta), Vector3Utils.scale(b, tb)); } } @@ -279,4 +279,3 @@ export const VECTOR3_NORTH: Vector3 = { x: 0, y: 0, z: 1 }; * @public */ export const VECTOR3_SOUTH: Vector3 = { x: 0, y: 0, z: -1 }; - diff --git a/libraries/math/src/vector3/vectorWrapper.test.ts b/libraries/math/src/vector3/vectorWrapper.test.ts index a95dd70..a95d9e0 100644 --- a/libraries/math/src/vector3/vectorWrapper.test.ts +++ b/libraries/math/src/vector3/vectorWrapper.test.ts @@ -170,7 +170,7 @@ describe('Vector3Builder', () => { const resultB = vectorA.lerp(vectorB, ratio); expect(resultA).toEqual(resultB); }); - + it('should be able compute the slerp halfway between two vectors with the same result as the coreHelpers function', () => { const vectorA = new Vector3Builder(5, 6, 3); const vectorB = new Vector3Builder(4, 2, 6); diff --git a/libraries/math/src/vector3/vectorWrapper.ts b/libraries/math/src/vector3/vectorWrapper.ts index 5e1e309..d3512bd 100644 --- a/libraries/math/src/vector3/vectorWrapper.ts +++ b/libraries/math/src/vector3/vectorWrapper.ts @@ -150,7 +150,6 @@ export class Vector3Builder implements Vector3 { return this.assign(Vector3Utils.clamp(this, limits)); } - /** * lerp * @@ -165,7 +164,7 @@ export class Vector3Builder implements Vector3 { * * Constructs a new vector using spherical linear interpolation on each component from two vectors. */ - slerp(vec: Vector3, t: number): this { + slerp(vec: Vector3, t: number): this { return this.assign(Vector3Utils.slerp(this, vec, t)); } } diff --git a/package-lock.json b/package-lock.json index 84bf611..1758397 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,12 +36,28 @@ "@minecraft/server": "^1.6.0", "@minecraft/tsconfig": "*", "just-scripts": "^2.2.1", + "prettier": "^2.8.2", "vitest": "^0.34.6" }, "peerDependencies": { "@minecraft/server": "^1.6.0" } }, + "libraries/math/node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -1240,6 +1256,137 @@ "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.4.tgz", "integrity": "sha512-XiMNdWPwW270PixfVRUd5cEI/0pu5TsmJtHcHZC6wMEAWFJXfOYd0Pj4P///9EnrGyyMmyaaoagEk67fNFQtbg==" }, + "node_modules/@typescript-eslint/parser": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.8.0.tgz", + "integrity": "sha512-KgKQly1pv0l4ltcftP59uQZCi4HUYswCLbTqVZEJu7uLX8CTLyswqMLqLN+2QFz4jCptqWVV4SB7vdxcH2+0kQ==", + "dependencies": { + "@typescript-eslint/scope-manager": "7.8.0", + "@typescript-eslint/types": "7.8.0", + "@typescript-eslint/typescript-estree": "7.8.0", + "@typescript-eslint/visitor-keys": "7.8.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.8.0.tgz", + "integrity": "sha512-viEmZ1LmwsGcnr85gIq+FCYI7nO90DVbE37/ll51hjv9aG+YZMb4WDE2fyWpUR4O/UrhGRpYXK/XajcGTk2B8g==", + "dependencies": { + "@typescript-eslint/types": "7.8.0", + "@typescript-eslint/visitor-keys": "7.8.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/types": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.8.0.tgz", + "integrity": "sha512-wf0peJ+ZGlcH+2ZS23aJbOv+ztjeeP8uQ9GgwMJGVLx/Nj9CJt17GWgWWoSmoRVKAX2X+7fzEnAjxdvK2gqCLw==", + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.8.0.tgz", + "integrity": "sha512-5pfUCOwK5yjPaJQNy44prjCwtr981dO8Qo9J9PwYXZ0MosgAbfEMB008dJ5sNo3+/BN6ytBPuSvXUg9SAqB0dg==", + "dependencies": { + "@typescript-eslint/types": "7.8.0", + "@typescript-eslint/visitor-keys": "7.8.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { + "version": "7.6.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.1.tgz", + "integrity": "sha512-f/vbBsu+fOiYt+lmwZV0rVwJScl46HppnOA1ZvIuBWKOTlllpyJ3bfVax76/OrhCH38dyxoDIA8K7uB963IYgA==", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.8.0.tgz", + "integrity": "sha512-q4/gibTNBQNA0lGyYQCmWRS5D15n8rXh4QjK3KV+MBPlTYHpfBUT3D3PaPR/HeNiI9W6R7FvlkcGhNyAoP+caA==", + "dependencies": { + "@typescript-eslint/types": "7.8.0", + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", @@ -4983,11 +5130,11 @@ "dev": true }, "node_modules/ts-api-utils": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.0.3.tgz", - "integrity": "sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", + "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", "engines": { - "node": ">=16.13.0" + "node": ">=16" }, "peerDependencies": { "typescript": ">=4.2.0" @@ -5785,6 +5932,8 @@ "devDependencies": { "@types/node": "^14.0.0 || ^16.0.0 || ^18.0.0", "@types/rimraf": "^3.0.2", + "@typescript-eslint/parser": "^7.2.0", + "eslint": "^8.53.0", "ts-node": "^10.9.1", "tsconfig": "*", "typescript": "^5.2.2", @@ -6243,33 +6392,6 @@ } } }, - "tools/eslint-config-minecraft-scripting/node_modules/@typescript-eslint/parser": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.2.0.tgz", - "integrity": "sha512-5FKsVcHTk6TafQKQbuIVkXq58Fnbkd2wDL4LB7AURN7RUOu1utVP+G8+6u3ZhEroW3DF6hyo3ZEXxgKgp4KeCg==", - "dependencies": { - "@typescript-eslint/scope-manager": "7.2.0", - "@typescript-eslint/types": "7.2.0", - "@typescript-eslint/typescript-estree": "7.2.0", - "@typescript-eslint/visitor-keys": "7.2.0", - "debug": "^4.3.4" - }, - "engines": { - "node": "^16.0.0 || >=18.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "tools/eslint-config-minecraft-scripting/node_modules/@typescript-eslint/scope-manager": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.2.0.tgz", @@ -6463,33 +6585,6 @@ } } }, - "tools/eslint-plugin-minecraft-linting/node_modules/@typescript-eslint/parser": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.2.0.tgz", - "integrity": "sha512-5FKsVcHTk6TafQKQbuIVkXq58Fnbkd2wDL4LB7AURN7RUOu1utVP+G8+6u3ZhEroW3DF6hyo3ZEXxgKgp4KeCg==", - "dependencies": { - "@typescript-eslint/scope-manager": "7.2.0", - "@typescript-eslint/types": "7.2.0", - "@typescript-eslint/typescript-estree": "7.2.0", - "@typescript-eslint/visitor-keys": "7.2.0", - "debug": "^4.3.4" - }, - "engines": { - "node": "^16.0.0 || >=18.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "tools/eslint-plugin-minecraft-linting/node_modules/@typescript-eslint/scope-manager": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.2.0.tgz", diff --git a/prettier.config.js b/prettier.config.js index f08b831..811adf5 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,7 +1,7 @@ module.exports = { arrowParens: 'avoid', bracketSpacing: true, - endOfLine: 'crlf', + endOfLine: 'auto', printWidth: 120, singleQuote: true, tabWidth: 4, diff --git a/tools/core-build-tasks/eslint.config.mjs b/tools/core-build-tasks/eslint.config.mjs new file mode 100644 index 0000000..16a3cfa --- /dev/null +++ b/tools/core-build-tasks/eslint.config.mjs @@ -0,0 +1,21 @@ +import globals from 'globals'; +import tsParser from '@typescript-eslint/parser'; + +export default [ + { + files: ['**/*.{ts,tsx,js,jsx}', '*.ts'], + languageOptions: { + parser: tsParser, + parserOptions: { + ecmaVersion: 'latest', + project: './tsconfig.json', + }, + globals: { + ...globals.node, + }, + }, + rules: { + eqeqeq: ['error', 'always'], + }, + }, +]; diff --git a/tools/core-build-tasks/just.config.ts b/tools/core-build-tasks/just.config.ts index 1e11438..bc2f92c 100644 --- a/tools/core-build-tasks/just.config.ts +++ b/tools/core-build-tasks/just.config.ts @@ -1,7 +1,11 @@ -import { task, tscTask } from 'just-scripts'; +import { argv, task, tscTask } from 'just-scripts'; import { cleanTask } from './src/tasks/clean'; +import { coreLint } from './src/tasks/coreLint'; import { vitestTask } from './src/tasks/vitest'; +// Lint +task('lint', coreLint(['src/**/*.ts'], argv().fix)); + // Build task('build-tools', tscTask()); diff --git a/tools/core-build-tasks/package.json b/tools/core-build-tasks/package.json index 362bbf9..df7ca2d 100644 --- a/tools/core-build-tasks/package.json +++ b/tools/core-build-tasks/package.json @@ -19,6 +19,7 @@ "scripts": { "build-tools": "just-scripts build-tools", "clean-tools": "just-scripts clean-tools", + "lint": "just-scripts lint", "test": "just-scripts test" }, "files": [ @@ -38,9 +39,11 @@ "devDependencies": { "@types/node": "^14.0.0 || ^16.0.0 || ^18.0.0", "@types/rimraf": "^3.0.2", + "@typescript-eslint/parser": "^7.2.0", + "eslint": "^8.53.0", "ts-node": "^10.9.1", "tsconfig": "*", "typescript": "^5.2.2", "webpack": "^5.86.0" } -} +} \ No newline at end of file diff --git a/tools/core-build-tasks/src/tasks/coreLint.ts b/tools/core-build-tasks/src/tasks/coreLint.ts index a5c4b71..816ccc5 100644 --- a/tools/core-build-tasks/src/tasks/coreLint.ts +++ b/tools/core-build-tasks/src/tasks/coreLint.ts @@ -31,9 +31,14 @@ function eslintTask(files: string[], fix?: boolean): TaskFunction { process.env['ESLINT_USE_FLAT_CONFIG'] = FLAT_CONFIG_FILES.some(file => configFilePath.endsWith(file)) ? 'true' : 'false'; - const cmd = ['eslint', ...files, '--config', `"${configFilePath}"`, ...(fix ? ['--fix'] : []), '--color'].join( - ' ' - ); + const cmd = [ + 'eslint', + ...files, + '--config', + `"${configFilePath}"`, + ...(fix ? ['--fix'] : []), + '--color', + ].join(' '); logger.info(`Running command: ${cmd}`); return execSync(cmd, { stdio: 'inherit' }); } diff --git a/tools/core-build-tasks/src/tasks/helpers/getGameDeploymentRootPaths.ts b/tools/core-build-tasks/src/tasks/helpers/getGameDeploymentRootPaths.ts index 35edec8..56ec08d 100644 --- a/tools/core-build-tasks/src/tasks/helpers/getGameDeploymentRootPaths.ts +++ b/tools/core-build-tasks/src/tasks/helpers/getGameDeploymentRootPaths.ts @@ -37,7 +37,7 @@ export function getTargetWorldPath(): string { } const projectName = getOrThrowFromProcess('PROJECT_NAME'); - const worldsFolderName = product == MinecraftProduct.Custom ? 'worlds' : 'minecraftWorlds'; - const activeWorldFolderName = product == MinecraftProduct.Custom ? 'Bedrock level' : `${projectName}world`; + const worldsFolderName = product === MinecraftProduct.Custom ? 'worlds' : 'minecraftWorlds'; + const activeWorldFolderName = product === MinecraftProduct.Custom ? 'Bedrock level' : `${projectName}world`; return path.join(deploymentPath, worldsFolderName, activeWorldFolderName); }