Skip to content

Commit 098734f

Browse files
authored
Feature/add eslint (#635)
* Adding eslint and jest plugin * Fixing linting changing * Automatic fixes * Fixing linting issues * More linting fixes and tests
1 parent 43248f7 commit 098734f

File tree

113 files changed

+1872
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1872
-573
lines changed

.github/workflows/publish-to-vscode.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
- name: 📋 Test
5454
run: npm run test
5555

56+
- name: 🔍 Linting
57+
run: npm run lint
58+
5659
publish:
5760
if: ${{ needs.test.result == 'success' && needs.universal.result == 'success' }}
5861
runs-on: ubuntu-latest

.github/workflows/pull-request.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- name: 🛠️ Build
3838
run: npm run compile
3939

40+
- name: 🔍 Linting
41+
run: npm run lint
42+
4043
- name: 📦 Package test
4144
run: |
4245
npx vsce package

.github/workflows/unit-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: 📋 Test
3535
run: npm run test
3636

37+
- name: 🔍 Linting
38+
run: npm run lint
39+
3740
- name: 📦 Package test
3841
run: |
3942
npx vsce package

.vscode/extensions.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
44

55
// List of extensions which should be recommended for users of this workspace.
6-
"recommendations": []
6+
"recommendations": [
7+
"orta.vscode-jest",
8+
"dbaeumer.vscode-eslint"
9+
]
710
}

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
"mocha.requires": ["ts-node/register", "chai"],
2424
"mocha.env": {
2525
"TS_NODE_COMPILER_OPTIONS": "{\"module\":\"commonjs\",\"declaration\":true,\"noImplicitAny\":false,\"removeComments\":false,\"noLib\":false,\"emitDecoratorMetadata\":true,\"experimentalDecorators\":true,\"target\":\"es6\",\"sourceMap\":false,\"resolveJsonModule\":true,\"esModuleInterop\":true,\"moduleResolution\":\"node\",\"lib\":[\"dom\",\"es2017\"],\"types\":[\"chai\",\"chai-as-promised\",\"chai-http\",\"convict\",\"cors\",\"helmet\",\"mocha\",\"mongoose\",\"morgan\",\"node\",\"winston\"]}"
26-
}
26+
},
27+
28+
"eslint.workingDirectories": [{ "mode": "auto" }],
29+
"eslint.run": "onSave",
30+
"eslint.lintTask.enable": true
2731
}

client/jest.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ const config: Config = {
149149
// testLocationInResults: false,
150150

151151
// The glob patterns Jest uses to detect test files
152-
// testMatch: [
153-
// "**/__tests__/**/*.[jt]s?(x)",
154-
// "**/?(*.)+(spec|test).[tj]s?(x)"
155-
// ],
152+
testMatch: [
153+
"**/__tests__/**/*.[jt]s?(x)",
154+
"**/?(*.)+(spec|test).[tj]s?(x)"
155+
],
156156

157157
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
158158
// testPathIgnorePatterns: [

client/src/code/character.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export namespace Character {
1414

1515
/** */
1616
export function IsLetter(char: string): boolean {
17-
var code = char.charCodeAt(0);
17+
const code = char.charCodeAt(0);
1818

1919
if (code >= Character_a && code <= Character_z) return true;
2020
if (code >= Character_A && code <= Character_Z) return true;
@@ -32,7 +32,7 @@ export namespace Character {
3232

3333
/** */
3434
export function IsNumber(char: string): boolean {
35-
var code = char.charCodeAt(0);
35+
const code = char.charCodeAt(0);
3636

3737
if (code >= Character_0 && code <= Character_9) return true;
3838

client/src/code/document-location.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function resolve(text: string | { getText(): string }, path: string): num
105105
const s = path.split(/[\\/]/);
106106
let index = 0;
107107

108-
for (var I = 0; I < s.length; I++) {
108+
for (let I = 0; I < s.length; I++) {
109109
const elem = s[I];
110110

111111
if (!Number.isInteger(elem) && elem !== "") {

client/src/commands/create-templates.ts

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,24 @@ export function activate(context: ExtensionContext): void {
3333

3434
//General
3535
createCommandWithID(context, Commands.Create.General.Entity, "Create Entity", EntityID);
36-
createCommand(context, Commands.Create.General.Languages, "Create Languages");
37-
createCommand(context, Commands.Create.General.Manifests, "Create Manifests");
36+
createCommand(context, Commands.Create.General.Languages);
37+
createCommand(context, Commands.Create.General.Manifests);
3838

3939
//Project
4040
createCommandWithID(context, Commands.Create.Project.WorldProject, "Create World, BP, RP project", ProjectID);
4141
createCommandWithID(context, Commands.Create.Project.Resourcepack, "Create RP", ProjectID);
4242
createCommandWithID(context, Commands.Create.Project.Behaviorpack, "Create BP", ProjectID);
4343

4444
//Behavior pack
45-
createCommand(context, Commands.Create.Behaviorpack.Languages, "Create language files");
46-
createCommand(context, Commands.Create.Behaviorpack.Manifests, "Create manifest");
47-
48-
createCommandWithID(context, Commands.Create.Behaviorpack.Animation_Controller, "Create animation controller", AnimationControllerID);
45+
createCommand(context, Commands.Create.Behaviorpack.Languages);
46+
createCommand(context, Commands.Create.Behaviorpack.Manifests);
47+
48+
createCommandWithID(
49+
context,
50+
Commands.Create.Behaviorpack.Animation_Controller,
51+
"Create animation controller",
52+
AnimationControllerID
53+
);
4954
createCommandWithID(context, Commands.Create.Behaviorpack.Animation, "Create animation", AnimationID);
5055
createCommandWithID(context, Commands.Create.Behaviorpack.Block, "Create block", BlockID);
5156
createCommandWithID(context, Commands.Create.Behaviorpack.Dialogue, "Create dialogue", DialogueID);
@@ -58,34 +63,49 @@ export function activate(context: ExtensionContext): void {
5863
createCommandWithID(context, Commands.Create.Behaviorpack.Volume, "Create volume", VolumeID);
5964

6065
//Resource pack
61-
createCommand(context, Commands.Create.Resourcepack.Biomes_Client, "Create biomesclient file");
62-
createCommand(context, Commands.Create.Resourcepack.Blocks, "Create the blocks file");
63-
createCommand(context, Commands.Create.Resourcepack.Flipbook_Textures, "Create flipbook_textures file");
64-
createCommand(context, Commands.Create.Resourcepack.Item_Texture, "Create item tereate item texture file");
65-
createCommand(context, Commands.Create.Resourcepack.Languages, "Create lanreate language file");
66-
createCommand(context, Commands.Create.Resourcepack.Manifests, "Creatreate all manifest");
67-
createCommand(context, Commands.Create.Resourcepack.Music_Definitions, "Create the music definireate the music definitions file");
68-
createCommand(context, Commands.Create.Resourcepack.Sound_Definitions, "Create the sound definireate the sound definitions file");
69-
createCommand(context, Commands.Create.Resourcepack.Sounds, "Create the sreate the sounds file");
70-
createCommand(context, Commands.Create.Resourcepack.Terrain_Texture, "Create the terrain texture file");
71-
createCommand(context, Commands.Create.Resourcepack.Texture_List, "Create texturelist");
72-
73-
createCommandWithID(context, Commands.Create.Resourcepack.Animation_Controller, "Create animation controllers files", AnimationControllerID);
66+
createCommand(context, Commands.Create.Resourcepack.Biomes_Client);
67+
createCommand(context, Commands.Create.Resourcepack.Blocks);
68+
createCommand(context, Commands.Create.Resourcepack.Flipbook_Textures);
69+
createCommand(context, Commands.Create.Resourcepack.Item_Texture);
70+
createCommand(context, Commands.Create.Resourcepack.Languages);
71+
createCommand(context, Commands.Create.Resourcepack.Manifests);
72+
createCommand(context, Commands.Create.Resourcepack.Music_Definitions);
73+
createCommand(context, Commands.Create.Resourcepack.Sound_Definitions);
74+
createCommand(context, Commands.Create.Resourcepack.Sounds);
75+
createCommand(context, Commands.Create.Resourcepack.Terrain_Texture);
76+
createCommand(context, Commands.Create.Resourcepack.Texture_List);
77+
78+
createCommandWithID(
79+
context,
80+
Commands.Create.Resourcepack.Animation_Controller,
81+
"Create animation controllers files",
82+
AnimationControllerID
83+
);
7484
createCommandWithID(context, Commands.Create.Resourcepack.Animation, "Create animations files", AnimationID);
7585
createCommandWithID(context, Commands.Create.Resourcepack.Attachable, "Create attachable files", AttachableID);
76-
createCommandWithID(context, Commands.Create.Resourcepack.BlockCulling, "Create the block culling rule file", BlockCullingRuleID)
86+
createCommandWithID(
87+
context,
88+
Commands.Create.Resourcepack.BlockCulling,
89+
"Create the block culling rule file",
90+
BlockCullingRuleID
91+
);
7792
createCommandWithID(context, Commands.Create.Resourcepack.Entity, "Create entities files", EntityID);
7893
createCommandWithID(context, Commands.Create.Resourcepack.Fog, "Create fog file", FogID);
7994
createCommandWithID(context, Commands.Create.Resourcepack.Model, "Create reate model file", ModelID);
8095
createCommandWithID(context, Commands.Create.Resourcepack.Particle, "Create particle file", ParticleID);
81-
createCommandWithID(context, Commands.Create.Resourcepack.Render_Controller, "Create render_controller file", RenderControllerID);
96+
createCommandWithID(
97+
context,
98+
Commands.Create.Resourcepack.Render_Controller,
99+
"Create render_controller file",
100+
RenderControllerID
101+
);
82102

83103
//World
84-
createCommand(context, Commands.Create.World.Languages, "Create language files");
85-
createCommand(context, Commands.Create.World.Manifests, "Create manifest");
104+
createCommand(context, Commands.Create.World.Languages);
105+
createCommand(context, Commands.Create.World.Manifests);
86106
}
87107

88-
function createCommand(context: ExtensionContext, command: string, title: string) {
108+
function createCommand(context: ExtensionContext, command: string) {
89109
context.subscriptions.push(
90110
commands.registerCommand(command, (arg: any[]) => {
91111
onCommandComplete(command, arg);

client/src/commands/languages.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export function activate(context: ExtensionContext): void {
77
context.subscriptions.push(commands.registerCommand(Commands.AddLanguageFile, addAll));
88
}
99

10-
function addAll(args: any): any {
10+
function addAll(): any {
1111
const ed = window.activeTextEditor;
1212

1313
if (!ed) return;
14-
const Current = ed.document.uri.path;
15-
const Params: ExecuteCommandParams = {
14+
const current = ed.document.uri.path;
15+
const params: ExecuteCommandParams = {
1616
command: Commands.AddLanguageFile,
17-
arguments: [Current],
17+
arguments: [current],
1818
};
1919

20-
return Manager.Client.sendRequest(ExecuteCommandRequest.type, Params);
20+
return Manager.Client.sendRequest(ExecuteCommandRequest.type, params);
2121
}

client/src/commands/open-lastest.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function activate(context: ExtensionContext): void {
88
context.subscriptions.push(commands.registerCommand(Commands.Errors.OpenLastest, openLastestError));
99
}
1010

11-
function openLastestError(args: any): void {
11+
function openLastestError(): void {
1212
try {
1313
let APPDATA = process.env.APPDATA;
1414

@@ -33,7 +33,7 @@ function openLastestError(args: any): void {
3333
}
3434
}
3535
} catch (error) {
36-
handleError(error);
36+
window.showErrorMessage("error retrieving errors", JSON.stringify(error));
3737
}
3838
}
3939

@@ -68,6 +68,3 @@ function findLastestLog(folder: string): void {
6868
window.showInformationMessage("Couldn't find content logs");
6969
}
7070
}
71-
function handleError(error: unknown) {
72-
throw new Error("Function not implemented.");
73-
}

client/src/commands/show-docs.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { commands, ExtensionContext, FileType, ProgressLocation, Uri, window, workspace } from "vscode";
22
import { Commands } from "@blockception/shared";
3-
import { Console } from '../console/console';
3+
import { Console } from "../console/console";
44

55
import path from "path";
66

77
export function activate(context: ExtensionContext): void {
8-
async function showDocs(args: any) {
8+
async function showDocs() {
99
const base = context.storageUri || context.globalStorageUri;
1010
const storage_path = path.join(base.fsPath, "docs");
1111
const command = new ShowDocsCommand(storage_path);
@@ -141,7 +141,7 @@ class ShowDocsCommand {
141141

142142
return diff <= day_diff_2;
143143
} catch (err) {
144-
Console.errror(`Failed to read file ${filepath}`, )
144+
Console.errror(`Failed to read file ${filepath}`, err);
145145
}
146146

147147
return false;
@@ -234,7 +234,7 @@ class ShowDocsCommand {
234234
// Open the markdown preview
235235
await commands.executeCommand("markdown.showPreview", uri);
236236
} catch (err) {
237-
window.showErrorMessage("Failed to open docs", filepath);
237+
window.showErrorMessage("Failed to open docs", filepath, JSON.stringify(err));
238238
}
239239
}
240240
}
@@ -256,4 +256,4 @@ namespace Sidebar {
256256
export function is(item: any): item is Sidebar {
257257
return item && item.items && Array.isArray(item.items);
258258
}
259-
}
259+
}

client/src/commands/show-vanilla-file.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { GithubFiles } from "bc-minecraft-bedrock-vanilla-data/lib/src/Lib/Vanil
44
import path from "path";
55

66
export function activate(context: ExtensionContext): void {
7-
async function showVanillaFile(args: any) {
7+
async function showVanillaFile() {
88
const base = context.storageUri || context.globalStorageUri;
99
const storage_path = path.join(base.fsPath, "vanilla");
1010
const command = new ShowVanillaFileCommand(storage_path);
@@ -55,6 +55,7 @@ class ShowVanillaFileCommand {
5555

5656
return diff <= day_diff_2;
5757
} catch (err) {
58+
console.log("trouble during checking of file", err);
5859
return false;
5960
}
6061
}
@@ -115,7 +116,7 @@ class ShowVanillaFileCommand {
115116
const doc = await workspace.openTextDocument(Uri.file(filepath));
116117
await window.showTextDocument(doc);
117118
} catch (err) {
118-
window.showErrorMessage("Failed to open vanilla file", filepath);
119+
window.showErrorMessage("Failed to open vanilla file", filepath, JSON.stringify(err));
119120
}
120121
}
121122
}

eslint.config.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import eslint from "@eslint/js";
2+
import tseslint from "typescript-eslint";
3+
4+
export default tseslint.config(
5+
{
6+
files: ["**/*.ts"],
7+
ignores: [
8+
"client/out/**/*",
9+
"shared/out/**/*",
10+
"server/out/**/*",
11+
"node_modules/**/*",
12+
"minecraft-bedrock-schemas/**/*",
13+
],
14+
extends: [eslint.configs.recommended, ...tseslint.configs.recommended],
15+
plugins: {
16+
jest: {},
17+
},
18+
},
19+
{
20+
rules: {
21+
"@typescript-eslint/no-namespace": "off",
22+
"@typescript-eslint/no-explicit-any": "off",
23+
"no-case-declarations": "off",
24+
},
25+
}
26+
);

0 commit comments

Comments
 (0)