Skip to content

Commit 0ae1344

Browse files
committed
Clean up lint issues and unused test code
1 parent 0a23194 commit 0ae1344

File tree

10 files changed

+31
-70
lines changed

10 files changed

+31
-70
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-env node */
12
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
23
module.exports = {
34
preset: 'ts-jest',

src/Markdown-it.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import attrs from 'markdown-it-attrs'
22
import md from 'markdown-it'
3+
import type { Token } from 'markdown-it'
34
import blockEmbed from 'markdown-it-block-embed'
45
import multimdTable from 'markdown-it-multimd-table'
56
import taskLists from 'markdown-it-task-lists'
@@ -54,23 +55,26 @@ const note = (markdown, config) => {
5455
}
5556

5657
// tslint:disable-next-line: only-arrow-functions
57-
markdown.renderer.rules.paragraph_open = function (tokens: any[], idx, options, env, self) {
58-
const inlineToken = tokens[idx + 1] // text
58+
markdown.renderer.rules.paragraph_open = function (tokens: Token[], idx, options, env, self) {
59+
const currentToken = tokens[idx]!
60+
const inlineToken = tokens[idx + 1]! // text
5961
if (inlineToken.content.startsWith(notesSeparator)) {
60-
tokens[idx].tag = 'aside'
61-
const classIndex = tokens[idx].attrIndex('class')
62+
currentToken.tag = 'aside'
63+
const classIndex = currentToken.attrIndex('class')
6264

6365
if (classIndex < 0) {
64-
tokens[idx].attrPush(['class', notesClass]) // add new attribute
65-
} else {
66-
tokens[idx].attrs[classIndex][1] = notesClass // replace value of existing attr
66+
currentToken.attrPush(['class', notesClass]) // add new attribute
67+
} else if (currentToken.attrs) {
68+
currentToken.attrs[classIndex][1] = notesClass // replace value of existing attr
6769
}
6870

6971
// remote "note:" from content
70-
tokens[idx + 1].content = inlineToken.content.replace(notesSeparator, '')
71-
tokens[idx + 1].children[0].content = tokens[idx + 1].children[0].content.replace(notesSeparator, '')
72+
inlineToken.content = inlineToken.content.replace(notesSeparator, '')
73+
if (inlineToken.children && inlineToken.children[0]) {
74+
inlineToken.children[0].content = inlineToken.children[0].content.replace(notesSeparator, '')
75+
}
7276

73-
tokens[idx + 2].tag = 'aside'
77+
tokens[idx + 2]!.tag = 'aside'
7478
}
7579
// pass token to default renderer.
7680
return defaultRender(tokens, idx, options, env, self)

src/RevealContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FrontMatterResult } from 'front-matter'
22
import path from 'path'
33
import { isDeepStrictEqual } from 'util'
4-
import { EventEmitter, Position, Range, Selection, TextDocument, TextEditor, TextEditorRevealType, Uri } from 'vscode'
4+
import { EventEmitter, Position, Range, Selection, TextDocument, TextEditor, Uri } from 'vscode'
55
import { Configuration, mergeConfig } from './Configuration'
66
import { Disposable } from './dispose'
77
import { ISlide } from './ISlide'

src/RevealServer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class RevealServer extends Disposable {
130130

131131
// ERROR HANDLER
132132
app.use(function (err, req, res, next) {
133+
void next
133134
context.logger.error(err.stack)
134135
res.status(500).send(err.stack)
135136
})

src/SlideParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Configuration } from './Configuration';
22
import { ISlide } from './ISlide';
33
import { Disposable } from './dispose';
4-
import frontmatter, { FrontMatterResult } from 'front-matter'
4+
import frontmatter from 'front-matter'
55

66
const trimFirstLastEmptyLine = (s: string): string => {
77
let content = s
@@ -42,6 +42,7 @@ export class SlideParser extends Disposable {
4242
}
4343

4444
public parse(text: string, configuration: Configuration, partial = true) {
45+
void partial
4546
const result = frontmatter<Configuration>(text)
4647
const slides = this.#parseSlides(result.body, configuration.separator, configuration.verticalSeparator)
4748
return { frontmatter: result, slides }
@@ -90,4 +91,3 @@ export class SlideParser extends Disposable {
9091

9192
//Singleton
9293
export default new SlideParser()
93-

src/test/UnitTests/MainController.jest.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ test('CurrentContext should be undefined when no editor is pass', () => {
2020
});
2121

2222
test('CurrentContext should be undefined when editor is not markdown', () => {
23-
24-
const editor: TextEditor = {
25-
document: { languageId: 'text', fileName: "test.txt" } as TextDocument,
26-
selection: new Selection(0, 0, 0, 0),
27-
selections: [],
28-
visibleRanges: [],
29-
options: {},
30-
viewColumn: undefined,
31-
edit: jest.fn(),
32-
insertSnippet: jest.fn(),
33-
setDecorations: jest.fn(),
34-
revealRange: jest.fn(),
35-
show: jest.fn(),
36-
hide: jest.fn()
37-
}
38-
3923
const main = new MainController(logger, {} as ExtensionContext, [], {} as Configuration, undefined)
4024
expect(main.currentContext).toBeUndefined()
4125
});
@@ -66,4 +50,4 @@ test('CurrentContext should be create when editor is pass and that is markdown',
6650
expect(main.currentContext?.frontmatter?.attributes).toBeUndefined() // default
6751
});
6852

69-
// switch edito
53+
// switch edito
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import CompletionItemProvider from "../../CompletionItemProvider"
2-
import * as extension from "../../extension"
3-
import MainController from "../../MainController"
4-
import {SlideTreeProvider} from "../../SlideExplorer"
5-
import {StatusBarController} from "../../StatusBarController"
6-
import TextDecorator from "../../TextDecorator"
7-
8-
91
test('NOTHING HERE', () => {
102

113
expect(true).toBeTruthy()
12-
})
4+
})

src/test/UnitTests/logger.jest.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,3 @@ test('Logger should log when level is info', () => {
5656

5757
expect(output).not.toEqual('')
5858
});
59-
60-
// test('Logger should Not log when level is debug', () => {
61-
// let output = ''
62-
// const logger = new Logger((s) => {
63-
// output = s
64-
// }, LogLevel.Debug)
65-
66-
// logger.debug('text1')
67-
68-
// expect(output).not.toEqual('')
69-
// });

src/test/__mocks__/vscode.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class MarkdownString {
6161

6262

6363
export type DocumentSelector = string;
64-
export type CompletionItemProvider = any
64+
export type CompletionItemProvider = unknown
6565
export class Disposable {
6666
//static from(...disposableLikes: { dispose: () => any }[]): Disposable;
6767
//constructor(callOnDispose: () => any);
@@ -105,15 +105,17 @@ export class Range {
105105

106106
export interface Event<T> {
107107

108-
(listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable;
108+
(listener: (e: T) => void, thisArgs?: unknown, disposables?: Disposable[]): Disposable;
109109
}
110110

111111
export class EventEmitter<T> {
112112

113-
#listener: (e: T) => any = (x: T) => null
113+
#listener: (e: T) => void = (_x: T) => {}
114114

115115
public get event() {
116-
return (listener: (ee: T) => any, thisArgs?: any, disposables?: Disposable[]) => {
116+
return (listener: (ee: T) => void, thisArgs?: unknown, disposables?: Disposable[]) => {
117+
void thisArgs
118+
void disposables
117119
this.#listener = listener
118120
};
119121
}
@@ -130,7 +132,7 @@ export class ThemeIcon {
130132
constructor(public readonly id: string, public readonly color?: ThemeColor) { }
131133
}
132134

133-
export interface Command { title: string; command: string; tooltip?: string; arguments?: any[]; }
135+
export interface Command { title: string; command: string; tooltip?: string; arguments?: unknown[]; }
134136
export enum TreeItemCollapsibleState { None = 0, Collapsed = 1, Expanded = 2 }
135137

136138
export class TreeItem {
@@ -226,12 +228,12 @@ export interface TreeDataProvider<T> {
226228

227229
export type ProviderResult<T> = T | undefined | null | Thenable<T | undefined | null>;
228230

229-
export interface CancellationToken { isCancellationRequested: boolean; onCancellationRequested: Event<any>; }
231+
export interface CancellationToken { isCancellationRequested: boolean; onCancellationRequested: Event<unknown>; }
230232

231233
export class Selection extends Range {
232234
//anchor: Position;
233235
//active: Position;
234236
constructor(public anchor: Position, public active: Position) { super(anchor, active) }
235237
//constructor(anchorLine: number, anchorCharacter: number, activeLine: number, activeCharacter: number) { super() }
236238
//isReversed: boolean;
237-
}
239+
}

src/test/suite/extension.test.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,8 @@
33
// You can import and use all API from the 'vscode' module
44
// as well as import your extension to test it
55
import * as vscode from 'vscode';
6-
// import * as myExtension from '../../extension';
7-
8-
// suite('Extension Test Suite', () => {
9-
// vscode.window.showInformationMessage('Start all tests.');
10-
11-
// test('Sample test', () => {
12-
// assert.strictEqual([1, 2, 3].indexOf(5), -1);
13-
// assert.strictEqual([1, 2, 3].indexOf(0), -1);
14-
// });
15-
// });
16-
17-
186
test('Should start extension @integration', async () => {
19-
const testDocument = await vscode.workspace.openTextDocument('../sample.md')
7+
await vscode.workspace.openTextDocument('../sample.md')
208
await sleep(2000)
219

2210
const vscodereveal = vscode.extensions.getExtension('evilz.vscode-reveal')

0 commit comments

Comments
 (0)