Skip to content

fix(lint): adjust eslint settings and fix warnings #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,44 @@
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/naming-convention": [
"warn",
{
"selector": "default",
"format": ["camelCase", "snake_case"], // protocol messages use snake_case
"leadingUnderscore": "allow"
},
{
"selector": "enumMember",
"format": ["PascalCase"],
"leadingUnderscore": "allow"
},
{
"selector": "variable",
"format": ["UPPER_CASE", "PascalCase"], // TODO: remove PascalCase uses
"modifiers": ["global", "const"]
},
{
"selector": "typeLike",
"format": ["PascalCase"]
}
],
"@typescript-eslint/no-explicit-any": "off", // TODO: enable when messages are typed
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/semi": ["warn", "always"],
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn"
// indent 4 spaces
"indent": ["warn", 4, { "SwitchCase": 1 }],
"no-throw-literal": "warn",
// turn off base rules as they can report incorrect errors
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
Copy link

@frgarc frgarc Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add some others that we have implemented at PE repo:

'unicorn/no-null': ['error', { checkStrictEquality: true }],
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],

},
"ignorePatterns": [
"**/*.d.ts"
Expand Down
44 changes: 22 additions & 22 deletions src/config-provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright (C) Microsoft Corporation. All rights reserved.

import * as vscode from 'vscode';
Expand All @@ -7,26 +6,27 @@ import * as vscode from 'vscode';
// Custom fields specified in package.json.
//
export class ConfigProvider implements vscode.DebugConfigurationProvider {
resolveDebugConfiguration(
folder: vscode.WorkspaceFolder | undefined,
config: vscode.DebugConfiguration
): vscode.ProviderResult<vscode.DebugConfiguration> {
// set some defaults to allow attach without a launch.json
if (!config.type) {
config.type = 'minecraft-js';
}
if (!config.request) {
config.request = 'attach';
}
if (!config.name) {
config.name = 'Attach to Minecraft';
}
if (!config.localRoot) {
config.localRoot = '${workspaceFolder}/scripts/';
}
if (!config.port) {
config.inputPort = '${command:PromptForPort}'; // prompt user for port
}

resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {

// set some defaults to allow attach without a launch.json
if (!config.type) {
config.type = 'minecraft-js';
}
if (!config.request) {
config.request = 'attach';
}
if (!config.name) {
config.name = 'Attach to Minecraft';
}
if (!config.localRoot) {
config.localRoot = "${workspaceFolder}/scripts/";
}
if (!config.port) {
config.inputPort = "${command:PromptForPort}"; // prompt user for port
}

return config;
}
return config;
}
}
14 changes: 5 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ReplayStatsProvider } from './stats/replay-stats-provider';

// called when extension is activated
//
export function activate(context: vscode.ExtensionContext) {
export function activate(context: vscode.ExtensionContext): void {
const liveStatsProvider = new StatsProvider('Live', 'minecraftDiagnosticsLive');
const eventEmitter: EventEmitter = new EventEmitter();

Expand All @@ -24,7 +24,7 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('minecraft-js', configProvider));

// register a debug adapter descriptor factory for 'minecraft-js', this factory creates the DebugSession
let descriptorFactory = new ServerDebugAdapterFactory(homeViewProvider, liveStatsProvider, eventEmitter);
const descriptorFactory = new ServerDebugAdapterFactory(homeViewProvider, liveStatsProvider, eventEmitter);
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory('minecraft-js', descriptorFactory));
if ('dispose' in descriptorFactory) {
context.subscriptions.push(descriptorFactory);
Expand All @@ -51,7 +51,7 @@ export function activate(context: vscode.ExtensionContext) {
// Create a command to allow keyboard shortcuts to run Minecraft commands
const runMinecraftCommand = vscode.commands.registerCommand(
'minecraft-debugger.runMinecraftCommand',
(...args: any[]) => {
(...args: unknown[]) => {
if (args.length === 0) {
vscode.window.showErrorMessage('No command provided.');
return;
Expand Down Expand Up @@ -79,8 +79,8 @@ export function activate(context: vscode.ExtensionContext) {
canSelectMany: false,
openLabel: 'Open',
filters: {
'MC Stats Files': ['mcstats'],
'All Files': ['*'],
'MC Stats Files': ['mcstats'], // eslint-disable-line @typescript-eslint/naming-convention
'All Files': ['*'], // eslint-disable-line @typescript-eslint/naming-convention
},
});
if (!fileUri || fileUri.length === 0) {
Expand All @@ -101,7 +101,3 @@ export function activate(context: vscode.ExtensionContext) {
replayDiagnosticsCommand
);
}

// called when extension is deactivated
//
export function deactivate() {}
33 changes: 17 additions & 16 deletions src/message-stream-parser.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@

// Copyright (C) Microsoft Corporation. All rights reserved.

// eslint-disable-next-line @typescript-eslint/no-var-requires
const Parser = require('stream-parser');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Transform = require('stream').Transform;

// Data transform attached to socket.
// Parses messages to json as they arrive from debugee,
// then raises them as events for consumption by the DA.
//
export class MessageStreamParser extends Transform {
constructor() {
super();
this._bytes(9, this.onLength);
}
constructor() {
super();
this._bytes(9, this.onLength);
}

private onLength(buffer: Buffer) {
let length = parseInt(buffer.toString(), 16);
this.emit('length', length);
this._bytes(length, this.onMessage);
}
private onLength(buffer: Buffer) {
const length = parseInt(buffer.toString(), 16);
this.emit('length', length);
this._bytes(length, this.onMessage);
}

private onMessage(buffer: Buffer) {
let json = JSON.parse(buffer.toString());
this.emit('message', json);
this._bytes(9, this.onLength);
}
private onMessage(buffer: Buffer) {
const json = JSON.parse(buffer.toString());
this.emit('message', json);
this._bytes(9, this.onLength);
}
}

Parser(MessageStreamParser.prototype);
Parser(MessageStreamParser.prototype);
8 changes: 2 additions & 6 deletions src/panels/home-view-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class HomeViewProvider implements vscode.WebviewViewProvider {
this._eventEmitter = eventEmitter;
}

public setDebuggerStatus(isConnected: boolean, minecraftCapabilities: MinecraftCapabilities) {
public setDebuggerStatus(isConnected: boolean, minecraftCapabilities: MinecraftCapabilities): void {
this._view?.webview.postMessage({
type: 'debugger-status',
isConnected: isConnected,
Expand All @@ -33,11 +33,7 @@ export class HomeViewProvider implements vscode.WebviewViewProvider {
this._eventEmitter.emit('request-debugger-status');
}

public resolveWebviewView(
webviewView: vscode.WebviewView,
_context: vscode.WebviewViewResolveContext,
_token: vscode.CancellationToken
) {
public resolveWebviewView(webviewView: vscode.WebviewView): void {
this._view = webviewView;

this._view.webview.options = {
Expand Down
4 changes: 2 additions & 2 deletions src/panels/minecraft-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class MinecraftDiagnosticsPanel {
this._statsTracker.addStatListener(this._statsCallback);
}

public static render(extensionUri: Uri, statsTracker: StatsProvider) {
public static render(extensionUri: Uri, statsTracker: StatsProvider): void {
const statsTrackerId = statsTracker.uniqueId;
const existingPanel = MinecraftDiagnosticsPanel.activeDiagnosticsPanels.find(
panel => panel._statsTracker.uniqueId === statsTrackerId
Expand All @@ -126,7 +126,7 @@ export class MinecraftDiagnosticsPanel {
}
}

public dispose() {
public dispose(): void {
if (this._statsCallback !== undefined) {
this._statsTracker.removeStatListener(this._statsCallback);
this._statsCallback = undefined;
Expand Down
7 changes: 2 additions & 5 deletions src/server-debug-adapter-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ export class ServerDebugAdapterFactory implements vscode.DebugAdapterDescriptorF
this._eventEmitter = eventEmitter;
}

createDebugAdapterDescriptor(
_session: vscode.DebugSession,
_executable: vscode.DebugAdapterExecutable | undefined
): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
createDebugAdapterDescriptor(): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
if (!this.server) {
// start listening on a random port
this.server = Net.createServer(socket => {
Expand All @@ -38,7 +35,7 @@ export class ServerDebugAdapterFactory implements vscode.DebugAdapterDescriptorF
return new vscode.DebugAdapterServer((this.server.address() as Net.AddressInfo).port);
}

dispose() {
dispose(): void {
if (this.server) {
this.server.close();
}
Expand Down
Loading