Skip to content

Commit

Permalink
Migrate from tslint to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
jlandersen committed May 16, 2020
1 parent 35d4216 commit da932a2
Show file tree
Hide file tree
Showing 25 changed files with 1,014 additions and 181 deletions.
8 changes: 3 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
"out": false
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
"out": true
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
}
11 changes: 9 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"script": "webpack:dev",
"problemMatcher": ["$tsc-watch"],
"isBackground": true,
"presentation": {
"reveal": "never"
Expand All @@ -15,6 +15,13 @@
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "lint",
"problemMatcher": "$eslint-stylish",
"label": "npm: lint",
"detail": "eslint -c .eslintrc.js --ext .ts src"
}
]
}
978 changes: 913 additions & 65 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@
},
"scripts": {
"vscode:prepublish": "webpack --mode production",
"lint": "eslint -c .eslintrc.js --ext .ts src",
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"test-compile": "tsc -p ./",
"webpack:dev": "webpack --mode development --watch",
"pretest": "npm run test-compile",
"test": "node ./out/test/runTest.js"
"test": "node ./out/test/runTest.js",
"test:compile": "tsc -p ./"
},
"dependencies": {
"glob": "^7.1.6",
Expand All @@ -230,13 +231,16 @@
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/js-yaml": "^3.12.3",
"@types/js-yaml": "^3.12.4",
"@types/mocha": "^5.2.7",
"@types/node": "^10.17.21",
"@types/vscode": "^1.37.0",
"@types/vscode": "^1.45.1",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/eslint-plugin-tslint": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"eslint": "^7.0.0",
"mocha": "^6.2.3",
"ts-loader": "^6.2.2",
"tslint": "^5.20.1",
"typescript": "^3.9.2",
"vscode-test": "^1.3.0",
"webpack": "^4.43.0",
Expand Down
23 changes: 11 additions & 12 deletions src/client/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface RecordReceivedEvent {

interface ConsumerChangedStatusEvent {
uri: vscode.Uri;
status: "created" | "rebalancing" | "rebalanced";
status: "created" | "rebalancing" | "rebalanced";
}

interface ConsumerCollectionChangedEvent {
Expand Down Expand Up @@ -54,7 +54,7 @@ class Consumer implements vscode.Disposable {
* Starts a new consumer group that subscribes to the provided topic.
* Received messages and/or errors are emitted via events.
*/
start() {
start(): void {
this.client = new ConsumerGroup({
kafkaHost: this.options.kafkaHost,
fromOffset: this.options.fromOffset,
Expand Down Expand Up @@ -89,7 +89,7 @@ class Consumer implements vscode.Disposable {
});
}

private parseUri(uri: vscode.Uri): { topic: string, partition?: string} {
private parseUri(uri: vscode.Uri): { topic: string; partition?: string} {
const [topic, partition] = uri.path.split("/");

return {
Expand All @@ -98,10 +98,11 @@ class Consumer implements vscode.Disposable {
};
}

dispose() {
dispose(): void {
if (this.client) {
this.client.close(true, (error) => {
// TODO: Handle error
console.error(error);
});
}

Expand All @@ -115,7 +116,7 @@ class Consumer implements vscode.Disposable {
*/
export class ConsumerCollection implements vscode.Disposable {
private static instance: ConsumerCollection;
private consumers: { [id: string]: Consumer; } = {};
private consumers: { [id: string]: Consumer } = {};
private disposables: vscode.Disposable[] = [];

private onDidChangeCollectionEmitter = new vscode.EventEmitter<ConsumerCollectionChangedEvent>();
Expand All @@ -131,7 +132,7 @@ export class ConsumerCollection implements vscode.Disposable {
/**
* Creates a new consumer for a provided uri.
*/
create(uri: vscode.Uri) {
create(uri: vscode.Uri): Consumer {
const consumer = new Consumer(uri);
this.consumers[uri.toString()] = consumer;
consumer.start();
Expand Down Expand Up @@ -172,7 +173,7 @@ export class ConsumerCollection implements vscode.Disposable {
/**
* Closes an existing consumer if exists.
*/
close(uri: vscode.Uri) {
close(uri: vscode.Uri): void {
const consumer = this.get(uri);

if (consumer === null) {
Expand All @@ -192,23 +193,21 @@ export class ConsumerCollection implements vscode.Disposable {
return this.consumers.hasOwnProperty(uri.toString());
}

dispose() {
dispose(): void {
this.disposeConsumers();
this.disposables.forEach((d) => d.dispose());
this.onDidChangeCollectionEmitter.dispose();
}

disposeConsumers() {
disposeConsumers(): void {
Object.keys(this.consumers).forEach((key) => {
this.consumers[key].dispose();
});

this.consumers = {};

this.onDidChangeCollectionEmitter.fire();
}

static getInstance() {
static getInstance(): ConsumerCollection {
if (!ConsumerCollection.instance) {
ConsumerCollection.instance = new ConsumerCollection();
}
Expand Down
11 changes: 6 additions & 5 deletions src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tslint:disable-next-line:no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const kafka = require("kafka-node");

import { Disposable } from "vscode";
Expand Down Expand Up @@ -82,7 +82,7 @@ export class Client implements Disposable {
this.sasl = options.sasl;
}

canConnect() {
canConnect(): boolean {
return this.host !== "";
}

Expand All @@ -105,6 +105,7 @@ export class Client implements Disposable {
this.kafkaAdminClient = new kafka.Admin(this.kafkaClient);
this.kafkaAdminClient.on("error", (error: any) => {
// Ignore this, connection error is handled using kafkaClient error event
console.error(error);
});

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -200,15 +201,15 @@ export class Client implements Disposable {
});
}

refresh(options: Settings) {
refresh(options: Settings): void {
this.dispose();

this.host = options.host;
this.sasl = options.sasl;
this.kafkaClient = null;
}

dispose() {
dispose(): void {
if (this.kafkaClient) {
this.kafkaClient.close();
}
Expand All @@ -219,7 +220,7 @@ export class Client implements Disposable {
this.kafkaKeyedProducerClient = null;
}

private parseMetadataResponse(response: any[]): { topics: Topic[], brokers: Broker[] } {
private parseMetadataResponse(response: any[]): { topics: Topic[]; brokers: Broker[] } {
return {
brokers: this.parseBrokers(response[0], response[1].clusterMetadata),
topics: this.parseTopics(response[1].metadata),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class DumpBrokerMetadataCommandHandler {
constructor(private client: Client, private outputChannelProvider: OutputChannelProvider) {
}

async execute(broker?: BrokerItem) {
async execute(broker?: BrokerItem): Promise<void> {
let brokerToDump: Broker | undefined = broker ? broker.broker : await pickBroker(this.client);

if (!brokerToDump) {
Expand All @@ -30,7 +30,7 @@ export class DumpClusterMetadataCommandHandler {
constructor(private client: Client, private outputChannelProvider: OutputChannelProvider) {
}

async execute() {
async execute(): Promise<void> {
const data = this.client.getBrokers().map((broker) => {
// Delete extension specific property
const sanitized = Object.assign({}, broker);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/consumers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class StartConsumerCommandHandler {
constructor(private client: Client) {
}

async execute(startConsumerCommand?: StartConsumerCommand) {
async execute(startConsumerCommand?: StartConsumerCommand): Promise<void> {
if (!startConsumerCommand) {
const topic = await pickTopic(this.client);

Expand Down Expand Up @@ -49,7 +49,7 @@ export class StartConsumerCommandHandler {
export class ToggleConsumerCommandHandler {
private consumerCollection = ConsumerCollection.getInstance();

async execute() {
async execute(): Promise<void> {
if (!vscode.window.activeTextEditor) {
return;
}
Expand Down Expand Up @@ -86,7 +86,7 @@ export class ListConsumersCommandHandler {
},
];

async execute() {
async execute(): Promise<void> {
const consumers = this.consumerCollection.getAll();
const consumerQuickPickItems = consumers.map((c) => {
return {
Expand Down Expand Up @@ -118,7 +118,7 @@ export class ListConsumersCommandHandler {
}
}

private async openDocument(uri: vscode.Uri) {
private async openDocument(uri: vscode.Uri): Promise<void> {
let document: vscode.TextDocument | undefined;

// First we check if the document is already open, in which case we just show it
Expand Down
4 changes: 3 additions & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as vscode from "vscode";

import { Client } from "../client";

export const waitUntilConnected = async (client: Client, handler: () => Promise<any>) => {
type Handler = () => Promise<any>;

export const waitUntilConnected = async (client: Client, handler: Handler): Promise<any> => {
if (!client.canConnect()) {
vscode.window.showInformationMessage("No kafka host configured");
return;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/producers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ProduceRecordCommandHandler {
constructor(private client: Client, private channelProvider: OutputChannelProvider) {
}

async execute(document: vscode.TextDocument, range: vscode.Range, times: number) {
async execute(document: vscode.TextDocument, range: vscode.Range, times: number): Promise<void> {
const channel = this.channelProvider.getChannel("Kafka Producer Log");
const { topic, key, value } = this.parseDocumentRange(document, range);
const messages = [...Array(times).keys()].map(() => value);
Expand Down Expand Up @@ -51,7 +51,7 @@ export class ProduceRecordCommandHandler {
});
}

private parseDocumentRange(document: vscode.TextDocument, range: vscode.Range) {
private parseDocumentRange(document: vscode.TextDocument, range: vscode.Range): { topic?: string; key?: string; value: string } {
let topic;
let key;
let value = "";
Expand Down
6 changes: 3 additions & 3 deletions src/commands/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class CreateTopicCommandHandler {
constructor(private client: Client, private explorer: KafkaExplorer) {
}

private validatePositiveNumber(value?: string) {
private validatePositiveNumber(value?: string): string | undefined {
if (!value) {
return "Must be a positive number";
}
Expand All @@ -22,7 +22,7 @@ export class CreateTopicCommandHandler {
}
}

async execute() {
async execute(): Promise<void> {
const topic = await vscode.window.showInputBox({ placeHolder: "Topic name" });

if (!topic) {
Expand Down Expand Up @@ -74,7 +74,7 @@ export class DumpTopicMetadataCommandHandler {
constructor(private client: Client, private outputChannelProvider: OutputChannelProvider) {
}

async execute(topic?: TopicItem) {
async execute(topic?: TopicItem): Promise<void> {
const topicToDump: Topic | undefined = topic ? topic.topic : await pickTopic(this.client);

if (!topicToDump) {
Expand Down
20 changes: 11 additions & 9 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@ import { Context } from "./context";

export const imagesPath = "images";

const getDarkLightPath = (fileName: string) => {
type DarkLightPath = { light: string; dark: string}

const getDarkLightPath = (fileName: string): DarkLightPath => {
return {
light: Context.current.asAbsolutePath(path.join(imagesPath, "light", fileName)),
dark: Context.current.asAbsolutePath(path.join(imagesPath, "dark", fileName)),
};
};

const getIconPath = (fileName: string) => {
return Context.current.asAbsolutePath(path.join(imagesPath, fileName));
const getIconPath = (fileName: string): string => {
return Context.current.asAbsolutePath(path.join(imagesPath, fileName));
};

export class Icons {
public static get Server() {
public static get Server(): DarkLightPath {
return getDarkLightPath("server.svg");
}

public static get ServerConnected() {
public static get ServerConnected(): DarkLightPath {
return getDarkLightPath("server-connected.svg");
}

public static get Topic() {
public static get Topic(): DarkLightPath {
return getDarkLightPath("topic.svg");
}

public static get Group() {
public static get Group(): DarkLightPath {
return getDarkLightPath("group.svg");
}

public static get Warning() {
public static get Warning(): string {
return getIconPath("warning.svg");
}

public static get Information() {
public static get Information(): DarkLightPath {
return getDarkLightPath("information.svg");
}
}
4 changes: 2 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { ExtensionContext } from "vscode";
export class Context {
private static _current: ExtensionContext;

static register(extensionExtension: ExtensionContext) {
static register(extensionExtension: ExtensionContext): void {
this._current = extensionExtension;
}

static get current() {
static get current(): ExtensionContext {
return this._current;
}
}
Loading

0 comments on commit da932a2

Please sign in to comment.