Skip to content

Commit

Permalink
Enable eslint for all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Jun 21, 2022
1 parent d4c3a4a commit 1ecb666
Show file tree
Hide file tree
Showing 26 changed files with 206 additions and 205 deletions.
10 changes: 8 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = {
},
extends: 'standard',
globals: {
Thenable: 'readonly'
},
parser: '@typescript-eslint/parser',
parserOptions: {
Expand All @@ -29,6 +28,13 @@ module.exports = {
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': ['error'],
'no-useless-constructor': 'warn',
'no-void': 'warn'
'no-void': 'warn',
// Following recommendation:
// https://typescript-eslint.io/docs/linting/troubleshooting/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
'no-undef': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['warn', {
argsIgnorePattern: '^_'
}]
}
};
2 changes: 1 addition & 1 deletion packages/examples/browser-lsp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"scripts": {
"clean": "npx shx rm -fr dist tsconfig.tsbuildinfo",
"lint": "echo 'No linting yet'",
"lint": "eslint src --ext .ts",
"compile": "tsc",
"watch": "tsc -w",
"copy:monacoworkers": "shx mkdir -p dist && shx cp -r ../../../node_modules/monaco-editor-workers/dist/workers/editorWorker* ./dist",
Expand Down
8 changes: 4 additions & 4 deletions packages/examples/browser-lsp/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import 'monaco-editor/esm/vs/editor/standalone/browser/toggleHighContrast/toggle
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';

import { buildWorkerDefinition } from 'monaco-editor-workers';
buildWorkerDefinition('dist', new URL('', window.location.href).href, false);

import { MonacoLanguageClient, CloseAction, ErrorAction, MonacoServices, MessageTransports } from 'monaco-languageclient';
import { BrowserMessageReader, BrowserMessageWriter } from 'vscode-languageserver-protocol/browser';
buildWorkerDefinition('dist', new URL('', window.location.href).href, false);

// register Monaco languages
monaco.languages.register({
Expand All @@ -38,17 +38,17 @@ const editorText = `
#00ff00 (green)
#0000ff (blue)
`;
monaco.editor.create(document.getElementById("container")!, {
monaco.editor.create(document.getElementById('container')!, {
model: monaco.editor.createModel(editorText, 'plaintext', monaco.Uri.parse('inmemory://model.txt')),
glyphMargin: true,
lightbulb: {
enabled: true
}
});

function createLanguageClient(transports: MessageTransports): MonacoLanguageClient {
function createLanguageClient (transports: MessageTransports): MonacoLanguageClient {
return new MonacoLanguageClient({
name: "Sample Language Client",
name: 'Sample Language Client',
clientOptions: {
// use a language id as a document selector
documentSelector: [{ language: 'plaintext' }],
Expand Down
28 changes: 13 additions & 15 deletions packages/examples/browser-lsp/src/serverWorker.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* ---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*-------------------------------------------------------------------------------------------- */

// This is an example copied as is from here:
// https://github.com/microsoft/vscode-extension-samples/blob/main/lsp-web-extension-sample/server/src/browserServerMain.ts
// the only addition is the following line:
declare const self: DedicatedWorkerGlobalScope;

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { createConnection, BrowserMessageReader, BrowserMessageWriter } from 'vscode-languageserver/browser';

import { Color, ColorInformation, Range, InitializeParams, InitializeResult, ServerCapabilities, TextDocuments, ColorPresentation, TextEdit, TextDocumentIdentifier } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';

declare const self: DedicatedWorkerGlobalScope;

console.log('running server lsp-web-extension-sample');

Expand Down Expand Up @@ -42,10 +42,9 @@ connection.onColorPresentation(params => getColorPresentation(params.color, para
// Listen on the connection
connection.listen();


const colorRegExp = /#([0-9A-Fa-f]{6})/g;

function getColorInformation(textDocument: TextDocumentIdentifier) {
function getColorInformation (textDocument: TextDocumentIdentifier) {
const colorInfos: ColorInformation[] = [];

const document = documents.get(textDocument.uri);
Expand All @@ -67,22 +66,21 @@ function getColorInformation(textDocument: TextDocumentIdentifier) {
return colorInfos;
}

function getColorPresentation(color: Color, range: Range) {
function getColorPresentation (color: Color, range: Range) {
const result: ColorPresentation[] = [];
const red256 = Math.round(color.red * 255), green256 = Math.round(color.green * 255), blue256 = Math.round(color.blue * 255);
const red256 = Math.round(color.red * 255); const green256 = Math.round(color.green * 255); const blue256 = Math.round(color.blue * 255);

function toTwoDigitHex(n: number): string {
function toTwoDigitHex (n: number): string {
const r = n.toString(16);
return r.length !== 2 ? '0' + r : r;
}

const label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}`;
result.push({ label: label, textEdit: TextEdit.replace(range, label) });
result.push({ label, textEdit: TextEdit.replace(range, label) });

return result;
}


const enum CharCode {
Digit0 = 48,
Digit9 = 57,
Expand All @@ -94,7 +92,7 @@ const enum CharCode {
f = 102,
}

function parseHexDigit(charCode: CharCode): number {
function parseHexDigit (charCode: CharCode): number {
if (charCode >= CharCode.Digit0 && charCode <= CharCode.Digit9) {
return charCode - CharCode.Digit0;
}
Expand All @@ -107,7 +105,7 @@ function parseHexDigit(charCode: CharCode): number {
return 0;
}

function parseColor(content: string, offset: number): Color {
function parseColor (content: string, offset: number): Color {
const r = (16 * parseHexDigit(content.charCodeAt(offset + 1)) + parseHexDigit(content.charCodeAt(offset + 2))) / 255;
const g = (16 * parseHexDigit(content.charCodeAt(offset + 3)) + parseHexDigit(content.charCodeAt(offset + 4))) / 255;
const b = (16 * parseHexDigit(content.charCodeAt(offset + 5)) + parseHexDigit(content.charCodeAt(offset + 6))) / 255;
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/browser-old/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"clean": "npx shx rm -fr dist tsconfig.tsbuildinfo",
"lint": "echo 'No linting yet'",
"lint": "eslint src --ext .ts",
"compile": "tsc",
"watch": "tsc -w",
"copy:monacoworkers": "shx mkdir -p dist && shx cp -r ../../../node_modules/monaco-editor-workers/dist/workers/editorWorker* ./dist",
Expand Down
36 changes: 18 additions & 18 deletions packages/examples/browser-old/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,50 @@ import 'monaco-editor/esm/vs/editor/standalone/browser/toggleHighContrast/toggle
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';

import { buildWorkerDefinition } from 'monaco-editor-workers';
buildWorkerDefinition('dist', new URL('', window.location.href).href, false);

import { getLanguageService, TextDocument } from "vscode-json-languageservice";
import { getLanguageService, TextDocument } from 'vscode-json-languageservice';
import { MonacoToProtocolConverter, ProtocolToMonacoConverter } from 'monaco-languageclient';
buildWorkerDefinition('dist', new URL('', window.location.href).href, false);

const LANGUAGE_ID = 'json';
const MODEL_URI = 'inmemory://model.json'
const MODEL_URI = 'inmemory://model.json';
const MONACO_URI = monaco.Uri.parse(MODEL_URI);

// register the JSON language with Monaco
monaco.languages.register({
id: LANGUAGE_ID,
extensions: ['.json', '.bowerrc', '.jshintrc', '.jscsrc', '.eslintrc', '.babelrc'],
aliases: ['JSON', 'json'],
mimetypes: ['application/json'],
mimetypes: ['application/json']
});

// create the Monaco editor
const value = `{
"$schema": "http://json.schemastore.org/coffeelint",
"line_endings": "unix"
}`;
monaco.editor.create(document.getElementById("container")!, {
monaco.editor.create(document.getElementById('container')!, {
model: monaco.editor.createModel(value, LANGUAGE_ID, MONACO_URI),
glyphMargin: true,
lightbulb: {
enabled: true
}
});

function getModel(): monaco.editor.IModel {
function getModel (): monaco.editor.IModel {
return monaco.editor.getModel(MONACO_URI) as monaco.editor.IModel;
}

function createDocument(model: monaco.editor.IReadOnlyModel) {
function createDocument (model: monaco.editor.IReadOnlyModel) {
return TextDocument.create(MODEL_URI, model.getLanguageId(), model.getVersionId(), model.getValue());
}

function resolveSchema(url: string): Promise<string> {
function resolveSchema (url: string): Promise<string> {
const promise = new Promise<string>((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onload = () => resolve(xhr.responseText);
xhr.onerror = () => reject(xhr.statusText);
xhr.open("GET", url, true);
xhr.open('GET', url, true);
xhr.send();
});
return promise;
Expand All @@ -77,7 +77,7 @@ const jsonService = getLanguageService({
const pendingValidationRequests = new Map<string, NodeJS.Timeout>();

monaco.languages.registerCompletionItemProvider(LANGUAGE_ID, {
provideCompletionItems(model, position, _context, _token): monaco.Thenable<monaco.languages.CompletionList> {
provideCompletionItems (model, position, _context, _token): monaco.Thenable<monaco.languages.CompletionList> {
const document = createDocument(model);
const wordUntil = model.getWordUntilPosition(position);
const defaultRange = new monaco.Range(position.lineNumber, wordUntil.startColumn, position.lineNumber, wordUntil.endColumn);
Expand All @@ -87,29 +87,29 @@ monaco.languages.registerCompletionItemProvider(LANGUAGE_ID, {
});
},

resolveCompletionItem(item, _token): monaco.languages.CompletionItem | monaco.Thenable<monaco.languages.CompletionItem> {
resolveCompletionItem (item, _token): monaco.languages.CompletionItem | monaco.Thenable<monaco.languages.CompletionItem> {
return jsonService.doResolve(m2p.asCompletionItem(item)).then(result => p2m.asCompletionItem(result, item.range));
}
});

monaco.languages.registerDocumentRangeFormattingEditProvider(LANGUAGE_ID, {
provideDocumentRangeFormattingEdits(model, range, options, _token): monaco.languages.TextEdit[] | monaco.Thenable<monaco.languages.TextEdit[]> {
provideDocumentRangeFormattingEdits (model, range, options, _token): monaco.languages.TextEdit[] | monaco.Thenable<monaco.languages.TextEdit[]> {
const document = createDocument(model);
const edits = jsonService.format(document, m2p.asRange(range), m2p.asFormattingOptions(options));
return p2m.asTextEdits(edits);
}
});

monaco.languages.registerDocumentSymbolProvider(LANGUAGE_ID, {
provideDocumentSymbols(model, _token): monaco.languages.DocumentSymbol[] | monaco.Thenable<monaco.languages.DocumentSymbol[]> {
provideDocumentSymbols (model, _token): monaco.languages.DocumentSymbol[] | monaco.Thenable<monaco.languages.DocumentSymbol[]> {
const document = createDocument(model);
const jsonDocument = jsonService.parseJSONDocument(document);
return p2m.asSymbolInformations(jsonService.findDocumentSymbols(document, jsonDocument));
}
});

monaco.languages.registerHoverProvider(LANGUAGE_ID, {
provideHover(model, position, _token): monaco.languages.Hover | monaco.Thenable<monaco.languages.Hover> {
provideHover (model, position, _token): monaco.languages.Hover | monaco.Thenable<monaco.languages.Hover> {
const document = createDocument(model);
const jsonDocument = jsonService.parseJSONDocument(document);
return jsonService.doHover(document, m2p.asPosition(position.lineNumber, position.column), jsonDocument).then((hover) => {
Expand All @@ -123,7 +123,7 @@ getModel().onDidChangeContent((_event) => {
});
validate();

function validate(): void {
function validate (): void {
const document = createDocument(getModel());
cleanPendingValidation(document);
pendingValidationRequests.set(document.uri, setTimeout(() => {
Expand All @@ -132,15 +132,15 @@ function validate(): void {
}));
}

function cleanPendingValidation(document: TextDocument): void {
function cleanPendingValidation (document: TextDocument): void {
const request = pendingValidationRequests.get(document.uri);
if (request !== undefined) {
clearTimeout(request);
pendingValidationRequests.delete(document.uri);
}
}

function doValidate(document: TextDocument): void {
function doValidate (document: TextDocument): void {
if (document.getText().length === 0) {
cleanDiagnostics();
return;
Expand All @@ -152,6 +152,6 @@ function doValidate(document: TextDocument): void {
});
}

function cleanDiagnostics(): void {
function cleanDiagnostics (): void {
monaco.editor.setModelMarkers(getModel(), 'default', []);
}
2 changes: 1 addition & 1 deletion packages/examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"clean": "npx shx rm -fr dist tsconfig.tsbuildinfo",
"lint": "echo 'No linting yet'",
"lint": "eslint src --ext .ts",
"compile": "tsc",
"watch": "tsc -w",
"copy:monacoworkers": "shx mkdir -p dist && shx cp -r ../../../node_modules/monaco-editor-workers/dist/workers/editorWorker* ./dist",
Expand Down
Loading

0 comments on commit 1ecb666

Please sign in to comment.