Skip to content

Commit

Permalink
👕 lint
Browse files Browse the repository at this point in the history
  • Loading branch information
philschatz committed Dec 6, 2023
1 parent f00f609 commit 8099313
Show file tree
Hide file tree
Showing 55 changed files with 242 additions and 237 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/cypress.config.ts
/client/src/webview-js/cnxml-preview/cnxml-preview.js
/client/src/webview-js/toc-editor/toc-editor.jsx
2 changes: 1 addition & 1 deletion client/specs/book-tocs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@jest/globals'

import { BookRootNode, BookToc, ClientTocNode, TocNodeKind } from '../../common/src/toc'
import { BookRootNode, type BookToc, type ClientTocNode, TocNodeKind } from '../../common/src/toc'
import { TocsTreeProvider } from '../src/book-tocs'

const testTocPage: ClientTocNode = {
Expand Down
20 changes: 10 additions & 10 deletions client/specs/cnxml-preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import mockfs from 'mock-fs'
import { DOMParser, XMLSerializer } from 'xmldom'
import { CnxmlPreviewPanel, rawTextHtml, tagElementsWithLineNumbers } from '../src/panel-cnxml-preview'

import vscode, { TextDocument, Uri } from 'vscode'
import vscode, { type TextDocument, type Uri } from 'vscode'
import * as utils from '../src/utils' // Used for dependency mocking in tests
import { EMPTY_BOOKS_AND_ORPHANS } from '../../common/src/requests'
import { join } from 'path'
import { ExtensionEvents } from '../src/panel'
import { LanguageClient } from 'vscode-languageclient/node'
import { type ExtensionEvents } from '../src/panel'
import { type LanguageClient } from 'vscode-languageclient/node'
import { PanelStateMessageType } from '../../common/src/webview-constants'
import { readFileSync } from 'fs'

Expand All @@ -37,7 +37,7 @@ function expectValue<T>(v: T | null | undefined) {

function makeDocument(uri: Uri, content: string) {
const document: vscode.TextDocument = {
uri: uri,
uri,
languageId: 'xml',
lineAt: () => ({ text: 'fakedata2' }),
positionAt: () => -123,
Expand Down Expand Up @@ -104,8 +104,8 @@ describe('cnxml-preview', () => {
const fakeEditor: vscode.TextEditor = {
document: {
lineAt: () => ({ text: 'fakedata' }),
languageId: languageId,
uri: uri
languageId,
uri
},
// used by panel-cnxml-preview scrollToRangeStartOfEditor
visibleRanges: [
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('cnxml-preview', () => {
})

it('rebinds to resource in the active editor', async () => {
const panel = new CnxmlPreviewPanel({ bookTocs: EMPTY_BOOKS_AND_ORPHANS, resourceRootDir, client: createMockClient(), events: events })
const panel = new CnxmlPreviewPanel({ bookTocs: EMPTY_BOOKS_AND_ORPHANS, resourceRootDir, client: createMockClient(), events })
const postMessage = sinon.spy(panel, 'postMessage')
expect((panel as any).resourceBinding).toBe(null)

Expand Down Expand Up @@ -178,12 +178,12 @@ describe('cnxml-preview', () => {
join(resourceRootDir, 'cnxml-to-html5.xsl'),
'utf-8'
)
expect(postMessage.calledWith({ type: PanelStateMessageType.Response, state: { xml: xmlExpectedSecond, xsl: xsl } })).toBe(true)
expect(postMessage.calledWith({ type: PanelStateMessageType.Response, state: { xml: xmlExpectedSecond, xsl } })).toBe(true)
expect((panel as any).resourceBinding.fsPath).toBe(resourceSecond.fsPath)
})

it('only rebinds to cnxml', async () => {
const panel = new CnxmlPreviewPanel({ bookTocs: EMPTY_BOOKS_AND_ORPHANS, resourceRootDir, client: createMockClient(), events: events })
const panel = new CnxmlPreviewPanel({ bookTocs: EMPTY_BOOKS_AND_ORPHANS, resourceRootDir, client: createMockClient(), events })
const postMessage = sinon.spy(panel, 'postMessage')

const documentFirst = await vscode.workspace.openTextDocument(resourceFirst)
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('cnxml-preview', () => {
function revealRange(textEditor: vscode.TextEditor, range: vscode.Range, strategy: vscode.TextEditorRevealType) {
(textEditor as any).visibleRanges = [range]
const evt: vscode.TextEditorVisibleRangesChangeEvent = {
textEditor: textEditor,
textEditor,
visibleRanges: [range]
}
odctevr.getCalls().forEach(c => c.firstArg(evt))
Expand Down
4 changes: 2 additions & 2 deletions client/specs/disposable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import vscode from 'vscode'
import SinonRoot from 'sinon'
import 'source-map-support/register'
import { rawTextHtml } from '../src/panel-cnxml-preview'
import { LanguageClient } from 'vscode-languageclient/node'
import { type LanguageClient } from 'vscode-languageclient/node'
import { EMPTY_BOOKS_AND_ORPHANS } from '../../common/src/requests'
import { Disposer, ExtensionEvents, ExtensionHostContext, Panel } from '../src/panel'
import { Disposer, type ExtensionEvents, type ExtensionHostContext, Panel } from '../src/panel'

// Test runs in out/client/src/test/suite, not src/client/src/test/suite
const TEST_OUT_DIR = path.join(__dirname, '../../')
Expand Down
20 changes: 10 additions & 10 deletions client/specs/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { expect } from '@jest/globals'
import mockfs from 'mock-fs'

import { activate, deactivate, forwardOnDidChangeWorkspaceFolders, setLanguageServerLauncher, setResourceRootDir } from '../src/extension'
import { Extension, ExtensionContext, WebviewPanel } from 'vscode'
import { type Extension, type ExtensionContext, type WebviewPanel } from 'vscode'
import * as vscode from 'vscode'
import * as utils from '../src/utils' // Used for dependency mocking in tests
import Sinon from 'sinon'
import { LanguageClient } from 'vscode-languageclient/node'
import { type LanguageClient } from 'vscode-languageclient/node'
import { OpenstaxCommand } from '../src/extension-types'
import { TocEditorPanel } from '../src/panel-toc-editor'
import { BooksAndOrphans, ExtensionServerNotification } from '../../common/src/requests'
import { PanelManager } from '../src/panel'
import { CnxmlPreviewPanel } from '../src/panel-cnxml-preview'
import { type TocEditorPanel } from '../src/panel-toc-editor'
import { type BooksAndOrphans, ExtensionServerNotification } from '../../common/src/requests'
import { type PanelManager } from '../src/panel'
import { type CnxmlPreviewPanel } from '../src/panel-cnxml-preview'
import * as pushContent from '../src/push-content'

describe('Extension', () => {
const sinon = Sinon.createSandbox()
beforeEach(async () => sinon.stub(pushContent, 'setDefaultGitConfig').resolves())
afterEach(async () => sinon.restore())
afterEach(async () => { sinon.restore() })
it('forwardOnDidChangeWorkspaceFolders sends a request to the language server', async function () {
const stub = sinon.stub()
const client = { sendRequest: stub } as unknown as LanguageClient
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('Extension', () => {
const extensionContext = {
asAbsolutePath: (p: string) => join(__dirname, '..', '..', p)
} as unknown as ExtensionContext
afterEach(async () => await deactivate())
afterEach(async () => { await deactivate() })
it('Starts up', async function () {
await expect(activate(extensionContext)).resolves.toBeTruthy()
})
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('Extension', () => {
}
mockfs(fs)
})
afterEach(() => mockfs.restore())
afterEach(() => { mockfs.restore() })

// Copy-pasta
const extensionContext = {
Expand All @@ -101,7 +101,7 @@ describe('Extension', () => {
sinon.stub(utils, 'getRootPathUri').returns(vscode.Uri.file(fakeWorkspacePath))
setResourceRootDir(fakeResourceRootDir)
})
afterEach(async () => await deactivate())
afterEach(async () => { await deactivate() })

it('show cnxml preview with no file open', async () => {
expect(vscode.window.activeTextEditor).toBeUndefined()
Expand Down
4 changes: 2 additions & 2 deletions client/specs/generate-readme.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@jest/globals'
import Sinon from 'sinon'
import * as vscode from 'vscode'
import { LanguageClient } from 'vscode-languageclient/node'
import { type LanguageClient } from 'vscode-languageclient/node'
import { ExtensionServerRequest } from '../../common/src/requests'
import { setLanguageServerLauncher } from '../src/extension'
import { readmeGenerator } from '../src/generate-readme'
Expand All @@ -10,7 +10,7 @@ import * as utils from '../src/utils'
describe('Request readme generated', () => {
const sinon = Sinon.createSandbox()

afterEach(() => sinon.restore())
afterEach(() => { sinon.restore() })

it('uses correct request type and uri', async () => {
const fakeWorkspacePath = vscode.Uri.file('/a/b/c/d')
Expand Down
4 changes: 2 additions & 2 deletions client/specs/image-upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import mockfs from 'mock-fs'

import vscode from 'vscode'
import * as utils from '../src/utils' // Used for dependency mocking in tests
import { LanguageClient } from 'vscode-languageclient/node'
import { type LanguageClient } from 'vscode-languageclient/node'
import { EMPTY_BOOKS_AND_ORPHANS } from '../../common/src/requests'
import { ExtensionEvents } from '../src/panel'
import { type ExtensionEvents } from '../src/panel'
import { ImageManagerPanel } from '../src/panel-image-manager'

const actualResourceRootDir = join(__dirname, '../static')
Expand Down
32 changes: 16 additions & 16 deletions client/specs/panel-toc-editor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { join } from 'path'
import { expect } from '@jest/globals'
import SinonRoot, { SinonStub } from 'sinon'
import SinonRoot, { type SinonStub } from 'sinon'

import vscode, { Disposable, Event, EventEmitter, Uri, ViewColumn, WebviewPanel } from 'vscode'
import { BookRootNode, BookToc, TocNodeKind, TocModificationKind } from '../../common/src/toc'
import vscode, { Disposable, type Event, EventEmitter, Uri, ViewColumn, type WebviewPanel } from 'vscode'
import { BookRootNode, type BookToc, TocNodeKind, TocModificationKind } from '../../common/src/toc'
import * as utils from '../src/utils' // Used for dependency mocking in tests
import { TocItemIcon, TocTreeItem, TocTreesProvider, toggleTocTreesFilteringHandler } from '../src/toc-trees-provider'
import { PanelIncomingMessage, TocEditorPanel } from '../src/panel-toc-editor'
import { LanguageClient } from 'vscode-languageclient/node'
import { type PanelIncomingMessage, TocEditorPanel } from '../src/panel-toc-editor'
import { type LanguageClient } from 'vscode-languageclient/node'
import { EMPTY_BOOKS_AND_ORPHANS, ExtensionServerRequest } from '../../common/src/requests'
import { ExtensionEvents, ExtensionHostContext } from '../src/panel'
import { BookOrTocNode, TocsTreeProvider } from '../src/book-tocs'
import { PanelStateMessage, PanelStateMessageType } from '../../common/src/webview-constants'
import { type ExtensionEvents, type ExtensionHostContext } from '../src/panel'
import { type BookOrTocNode, type TocsTreeProvider } from '../src/book-tocs'
import { type PanelStateMessage, PanelStateMessageType } from '../../common/src/webview-constants'

const TEST_OUT_DIR = join(__dirname, '../src')
const resourceRootDir = TEST_OUT_DIR
Expand All @@ -33,7 +33,7 @@ const createMockClient = () => {
type ExtractEventGeneric<GenericEvent> = GenericEvent extends Event<infer X> ? X : never
type ExtensionEventEmitters = { [key in keyof ExtensionEvents]: EventEmitter<ExtractEventGeneric<ExtensionEvents[key]>> }
const createMockEvents = (): { emitters: ExtensionEventEmitters, events: ExtensionEvents } => {
const onDidChangeWatchedFilesEmitter: EventEmitter<undefined> = new EventEmitter()
const onDidChangeWatchedFilesEmitter = new EventEmitter<undefined>()
const emitters = {
onDidChangeWatchedFiles: onDidChangeWatchedFilesEmitter
}
Expand All @@ -45,7 +45,7 @@ const createMockEvents = (): { emitters: ExtensionEventEmitters, events: Extensi

describe('Toc Editor', () => {
const sinon = SinonRoot.createSandbox()
afterEach(() => sinon.restore())
afterEach(() => { sinon.restore() })
it('TocTreesProvider returns expected TocTreeItems', async () => {
const fakeTreeBooks: BookToc[] = []
fakeTreeBooks.push(
Expand Down Expand Up @@ -174,10 +174,10 @@ describe('Toc Editor', () => {
sendRequestMock.onCall(0).resolves(null)
sendRequestMock.onCall(1).resolves(fakeTreeBooks)

expect(await tocTreesProvider.getChildren(undefined)).toMatchSnapshot()
expect(await tocTreesProvider.getChildren(undefined)).toMatchSnapshot()
expect(tocTreesProvider.getChildren(undefined)).toMatchSnapshot()
expect(tocTreesProvider.getChildren(undefined)).toMatchSnapshot()
expect(book1Item).toMatchSnapshot()
expect(await tocTreesProvider.getChildren(book2Item)).toMatchSnapshot()
expect(tocTreesProvider.getChildren(book2Item)).toMatchSnapshot()
expect(tocTreesProvider.getTreeItem(book2Item)).toMatchSnapshot()
expect(await tocTreesProvider.getParent(book2Item)).toMatchSnapshot()
expect(await tocTreesProvider.getParent(module3Item)).toMatchSnapshot()
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('Toc Editor', () => {
expect(getMessage().title).toBe('new_title')
})
it('disposes', () => {
expect(() => p.dispose()).not.toThrow()
expect(() => { p.dispose() }).not.toThrow()
})
it('sends a message to Webview when a fileChanged event is emitted', () => {
expect(postMessageStub.callCount).toBe(0)
Expand Down Expand Up @@ -298,8 +298,8 @@ describe('Toc Editor', () => {
expect(postMessageStub.callCount).toBe(1)
expect(postMessageStub.firstCall.args).toMatchSnapshot()
})
it('does not send a message to Webview when panel is disposed', async () => {
await expect(p.refreshPanel({} as unknown as WebviewPanel, client)).rejects
it('does not send a message to Webview when panel is disposed', () => {
expect(p.refreshPanel({} as unknown as WebviewPanel, client)).rejects // eslint-disable-line @typescript-eslint/no-unused-expressions
})
it('refreshes when server watched file changes', async () => {
const refreshStub = sinon.stub(p, 'refreshPanel')
Expand Down
6 changes: 3 additions & 3 deletions client/specs/panel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Sinon from 'sinon'
import { expect } from '@jest/globals'
import { Disposer, ExtensionHostContext, Panel, PanelManager } from '../src/panel'
import { Disposable, WebviewPanel } from 'vscode'
import { Disposer, type ExtensionHostContext, Panel, PanelManager } from '../src/panel'
import { Disposable, type WebviewPanel } from 'vscode'

describe('panel', () => {
const sinon = Sinon.createSandbox()
Expand All @@ -27,7 +27,7 @@ describe('panel', () => {
async handleMessage(message: boolean) {}
}

afterEach(() => sinon.restore())
afterEach(() => { sinon.restore() })

it('handles onDidDispose', () => {
const panel = new TestPanel()
Expand Down
22 changes: 12 additions & 10 deletions client/specs/push-content.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Sinon from 'sinon'
import * as pushContent from '../src/push-content'
import * as utils from '../src/utils'
import { Repository, Change, Status, CommitOptions, GitExtension, GitErrorCodes, Branch, RepositoryState } from '../src/git-api/git.d'
import { type Repository, type Change, Status, type CommitOptions, type GitExtension, GitErrorCodes, type Branch, type RepositoryState } from '../src/git-api/git.d'
import vscode from 'vscode'
import { expect } from '@jest/globals'
import { Substitute } from '@fluffy-spoon/substitute'
import { ExtensionHostContext } from '../src/panel'
import { type ExtensionHostContext } from '../src/panel'
import { DiagnosticSource, ExtensionServerRequest } from '../../common/src/requests'

const makeCaptureMessage = (messages: string[]): (message: string) => Promise<string | undefined> => {
Expand All @@ -29,7 +29,7 @@ describe('Push Button Test Suite', () => {
.resolves(new Map<string, Array<[vscode.Uri, vscode.Diagnostic]>>())
sinon.stub(utils, 'getRootPathUri').returns(vscode.Uri.file('test'))
})
afterEach(() => sinon.restore())
afterEach(() => { sinon.restore() })
const commitOptions: CommitOptions = { all: true }
const sendRequestMock = sinon.stub()
const mockHostContext: ExtensionHostContext = {
Expand Down Expand Up @@ -316,7 +316,7 @@ describe('Push Button Test Suite', () => {

describe('tests with sinon', () => {
const sinon = Sinon.createSandbox()
afterEach(async () => sinon.restore())
afterEach(async () => { sinon.restore() })
beforeEach(() => {
sinon.stub(utils, 'getRootPathUri').returns(vscode.Uri.file('test'))
})
Expand Down Expand Up @@ -360,7 +360,7 @@ describe('tests with sinon', () => {
vscode.Uri.file('/c.xhtml')
].map((uri, i) => ({
originalUri: uri,
uri: uri,
uri,
renameUri: undefined,
status: i === 0 ? Status.DELETED : Status.MODIFIED
}))
Expand All @@ -374,10 +374,10 @@ describe('tests with sinon', () => {
const toOpen = await pushContent.getDocumentsToOpen(pushContent.DocumentsToOpen.modified)
changesToReturn
.filter(c => c.status !== Status.DELETED)
.forEach(c => expect(toOpen.has(c.uri.toString())).toBe(true))
.forEach(c => { expect(toOpen.has(c.uri.toString())).toBe(true) })
changesToReturn
.filter(c => c.status === Status.DELETED)
.forEach(c => expect(toOpen.has(c.uri.toString())).toBe(false))
.forEach(c => { expect(toOpen.has(c.uri.toString())).toBe(false) })
expect(toOpen.size === 2)
})
})
Expand Down Expand Up @@ -428,9 +428,11 @@ describe('tests with sinon', () => {
const getDocumentsToOpenStub = sinon.stub(pushContent, 'getDocumentsToOpen')
const showTextDocumentStub = sinon.stub(vscode.window, 'showTextDocument')
.callsFake((uri: vscode.Uri, options?: vscode.TextDocumentShowOptions): Thenable<vscode.TextEditor> => {
return new Promise((resolve, reject) => resolve(
{ document: { uri: uri } as any as vscode.TextDocument } as any as vscode.TextEditor
))
return new Promise((resolve, reject) => {
resolve(
{ document: { uri } as any as vscode.TextDocument } as any as vscode.TextEditor
)
})
})
const executeCommandStub = sinon.stub(vscode.commands, 'executeCommand').resolves()
const getDiagnosticsStub = sinon.stub(vscode.languages, 'getDiagnostics')
Expand Down
4 changes: 2 additions & 2 deletions client/specs/requests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect } from '@jest/globals'

describe('ensureIds', () => {
const sinon = Sinon.createSandbox()
afterEach(() => sinon.restore())
afterEach(() => { sinon.restore() })

it('runs and yields a response', async () => {
const client = {
Expand All @@ -17,7 +17,7 @@ describe('ensureIds', () => {

describe('generateReadme', () => {
const sinon = Sinon.createSandbox()
afterEach(() => sinon.restore())
afterEach(() => { sinon.restore() })

it('runs and yields a response', async () => {
const client = {
Expand Down
Loading

0 comments on commit 8099313

Please sign in to comment.