From ad5ad5bf222dd4e0be43423f7f3166d70d1ecf12 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 4 Dec 2018 13:55:59 -0500 Subject: [PATCH] Fix rule definitions in errors.tslint.json/warnings.tslint.json Opening error.tslint.json/warnings.tslint.json in Theia, I noticed it complains about them not matching the expected schema. It turns out that the error ones should not have the "options" field. For the warnings one, we do not need to specify "true" if we provide options for the rule (it's implied). This patch fixes that, as well as some files that were infringing the indent rule (treated as an error). I verified that we get the same warnings as before. Change-Id: Iec23facc5ca4cca4e22cf964f873ef37d59ffe37 Signed-off-by: Simon Marchi --- configs/errors.tslint.json | 62 +++--- configs/warnings.tslint.json | 7 +- packages/plugin-ext/src/api/model.ts | 74 +++---- .../src/main/browser/languages-main.ts | 2 +- .../plugin-ext/src/plugin/languages/lens.ts | 92 ++++----- .../src/plugin/languages/outline.ts | 182 +++++++++--------- 6 files changed, 203 insertions(+), 216 deletions(-) diff --git a/configs/errors.tslint.json b/configs/errors.tslint.json index 92fcaa31d5ec4..104644618f955 100644 --- a/configs/errors.tslint.json +++ b/configs/errors.tslint.json @@ -1,18 +1,14 @@ { "defaultSeverity": "error", "rules": { - "arrow-parens": { - "options": [ - true, - "ban-single-arg-parens" - ] - }, - "arrow-return-shorthand": { - "options": [ - true, - "multiline" - ] - }, + "arrow-parens": [ + true, + "ban-single-arg-parens" + ], + "arrow-return-shorthand": [ + true, + "multiline" + ], "class-name": true, "comment-format": [ true, @@ -25,13 +21,11 @@ "SPDX-License-Identifier: EPL-2\\.0 OR GPL-2\\.0 WITH Classpath-exception-2\\.0" ], "forin": true, - "indent": { - "options": [ - true, - "spaces", - 4 - ] - }, + "indent": [ + true, + "spaces", + 4 + ], "interface-over-type-literal": true, "jsdoc-format": [ true, @@ -58,23 +52,19 @@ "check-whitespace" ], "one-variable-per-declaration": true, - "prefer-const": { - "options": [ - true, - { - "destructuring": "all" - } - ] - }, - "quotemark": { - "options": [ - true, - "single", - "jsx-single", - "avoid-escape", - "avoid-template" - ] - }, + "prefer-const": [ + true, + { + "destructuring": "all" + } + ], + "quotemark": [ + true, + "single", + "jsx-single", + "avoid-escape", + "avoid-template" + ], "radix": false, "semicolon": [ true, diff --git a/configs/warnings.tslint.json b/configs/warnings.tslint.json index cbf91044fcb8f..7f308c355861a 100644 --- a/configs/warnings.tslint.json +++ b/configs/warnings.tslint.json @@ -3,13 +3,11 @@ "await-promise": { "severity": "warning", "options": [ - true, "Thenable" ] }, "no-any": { - "severity": "warning", - "options": true + "severity": "warning" }, "no-implicit-dependencies": { "severity": "warning", @@ -45,8 +43,7 @@ ] }, "no-return-await": { - "severity": "warning", - "options": true + "severity": "warning" }, "no-void-expression": { "severity": "warning", diff --git a/packages/plugin-ext/src/api/model.ts b/packages/plugin-ext/src/api/model.ts index 73230196454fa..3eb2be9d4b288 100644 --- a/packages/plugin-ext/src/api/model.ts +++ b/packages/plugin-ext/src/api/model.ts @@ -124,10 +124,10 @@ export interface Completion { export interface SingleEditOperation { range: Range; text: string; - /** - * This indicates that this operation has "insert" semantics. - * i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved. - */ + /** + * This indicates that this operation has "insert" semantics. + * i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved. + */ forceMoveMarkers?: boolean; } @@ -344,42 +344,42 @@ export interface WorkspaceEdit { } export enum SymbolKind { - File = 0, - Module = 1, - Namespace = 2, - Package = 3, - Class = 4, - Method = 5, - Property = 6, - Field = 7, - Constructor = 8, - Enum = 9, - Interface = 10, - Function = 11, - Variable = 12, - Constant = 13, - String = 14, - Number = 15, - Boolean = 16, - Array = 17, - Object = 18, - Key = 19, - Null = 20, - EnumMember = 21, - Struct = 22, - Event = 23, - Operator = 24, - TypeParameter = 25 + File = 0, + Module = 1, + Namespace = 2, + Package = 3, + Class = 4, + Method = 5, + Property = 6, + Field = 7, + Constructor = 8, + Enum = 9, + Interface = 10, + Function = 11, + Variable = 12, + Constant = 13, + String = 14, + Number = 15, + Boolean = 16, + Array = 17, + Object = 18, + Key = 19, + Null = 20, + EnumMember = 21, + Struct = 22, + Event = 23, + Operator = 24, + TypeParameter = 25 } export interface DocumentSymbol { - name: string; - detail: string; - kind: SymbolKind; - containerName?: string; - range: Range; - selectionRange: Range; - children?: DocumentSymbol[]; + name: string; + detail: string; + kind: SymbolKind; + containerName?: string; + range: Range; + selectionRange: Range; + children?: DocumentSymbol[]; } export interface WorkspaceFoldersChangeEvent { diff --git a/packages/plugin-ext/src/main/browser/languages-main.ts b/packages/plugin-ext/src/main/browser/languages-main.ts index f383e07ef1427..e8150ec2f04cb 100644 --- a/packages/plugin-ext/src/main/browser/languages-main.ts +++ b/packages/plugin-ext/src/main/browser/languages-main.ts @@ -308,7 +308,7 @@ export class LanguagesMainImpl implements LanguagesMain { } } this.disposables.set(handle, disposable); - } + } protected createDocumentSymbolProvider(handle: number, selector: LanguageSelector | undefined): monaco.languages.DocumentSymbolProvider { return { diff --git a/packages/plugin-ext/src/plugin/languages/lens.ts b/packages/plugin-ext/src/plugin/languages/lens.ts index ff3c63101cc63..137acfe9cb7e3 100644 --- a/packages/plugin-ext/src/plugin/languages/lens.ts +++ b/packages/plugin-ext/src/plugin/languages/lens.ts @@ -26,58 +26,58 @@ import { CommandsConverter } from '../command-registry'; /** Adapts the calls from main to extension thread for providing/resolving the code lenses. */ export class CodeLensAdapter { - private static readonly BAD_CMD: theia.Command = { id: 'missing', label: '<>' }; + private static readonly BAD_CMD: theia.Command = { id: 'missing', label: '<>' }; - private cacheId = 0; - private cache = new Map(); + private cacheId = 0; + private cache = new Map(); - constructor( - private readonly provider: theia.CodeLensProvider, - private readonly documents: DocumentsExtImpl, - private readonly commands: CommandsConverter - ) { } + constructor( + private readonly provider: theia.CodeLensProvider, + private readonly documents: DocumentsExtImpl, + private readonly commands: CommandsConverter + ) { } - provideCodeLenses(resource: URI): Promise { - const document = this.documents.getDocumentData(resource); - if (!document) { - return Promise.reject(new Error(`There is no document for ${resource}`)); - } + provideCodeLenses(resource: URI): Promise { + const document = this.documents.getDocumentData(resource); + if (!document) { + return Promise.reject(new Error(`There is no document for ${resource}`)); + } - const doc = document.document; + const doc = document.document; - return Promise.resolve(this.provider.provideCodeLenses(doc, createToken())).then(lenses => { - if (Array.isArray(lenses)) { - return lenses.map(lens => { - const id = this.cacheId++; - const lensSymbol = ObjectIdentifier.mixin({ - range: Converter.fromRange(lens.range)!, - command: this.commands.toInternal(lens.command) - }, id); - this.cache.set(id, lens); - return lensSymbol; - }); - } - return undefined; - }); - } + return Promise.resolve(this.provider.provideCodeLenses(doc, createToken())).then(lenses => { + if (Array.isArray(lenses)) { + return lenses.map(lens => { + const id = this.cacheId++; + const lensSymbol = ObjectIdentifier.mixin({ + range: Converter.fromRange(lens.range)!, + command: this.commands.toInternal(lens.command) + }, id); + this.cache.set(id, lens); + return lensSymbol; + }); + } + return undefined; + }); + } - resolveCodeLens(resource: URI, symbol: CodeLensSymbol): Promise { - const lens = this.cache.get(ObjectIdentifier.of(symbol)); - if (!lens) { - return Promise.resolve(undefined); - } + resolveCodeLens(resource: URI, symbol: CodeLensSymbol): Promise { + const lens = this.cache.get(ObjectIdentifier.of(symbol)); + if (!lens) { + return Promise.resolve(undefined); + } - let resolve: Promise; - if (typeof this.provider.resolveCodeLens !== 'function' || lens.isResolved) { - resolve = Promise.resolve(lens); - } else { - resolve = Promise.resolve(this.provider.resolveCodeLens(lens, createToken())); - } + let resolve: Promise; + if (typeof this.provider.resolveCodeLens !== 'function' || lens.isResolved) { + resolve = Promise.resolve(lens); + } else { + resolve = Promise.resolve(this.provider.resolveCodeLens(lens, createToken())); + } - return resolve.then(newLens => { - newLens = newLens || lens; - symbol.command = this.commands.toInternal(newLens.command || CodeLensAdapter.BAD_CMD); - return symbol; - }); - } + return resolve.then(newLens => { + newLens = newLens || lens; + symbol.command = this.commands.toInternal(newLens.command || CodeLensAdapter.BAD_CMD); + return symbol; + }); + } } diff --git a/packages/plugin-ext/src/plugin/languages/outline.ts b/packages/plugin-ext/src/plugin/languages/outline.ts index 6f4ab8388307f..4fc3a47f8ba7b 100644 --- a/packages/plugin-ext/src/plugin/languages/outline.ts +++ b/packages/plugin-ext/src/plugin/languages/outline.ts @@ -25,102 +25,102 @@ import * as types from '../types-impl'; /** Adapts the calls from main to extension thread for providing the document symbols. */ export class OutlineAdapter { - constructor( - private readonly documents: DocumentsExtImpl, - private readonly provider: theia.DocumentSymbolProvider - ) { } + constructor( + private readonly documents: DocumentsExtImpl, + private readonly provider: theia.DocumentSymbolProvider + ) { } - provideDocumentSymbols(resource: URI): Promise { - const document = this.documents.getDocumentData(resource); - if (!document) { - return Promise.reject(new Error(`There is no document for ${resource}`)); - } + provideDocumentSymbols(resource: URI): Promise { + const document = this.documents.getDocumentData(resource); + if (!document) { + return Promise.reject(new Error(`There is no document for ${resource}`)); + } - const doc = document.document; + const doc = document.document; - return Promise.resolve(this.provider.provideDocumentSymbols(doc, createToken())).then(value => { - if (!value || value.length === 0) { - return undefined; - } - if (value[0] instanceof types.DocumentSymbol) { - return (value).map(Converter.fromDocumentSymbol); - } else { - return OutlineAdapter.asDocumentSymbolTree(resource, value); - } - }); - } + return Promise.resolve(this.provider.provideDocumentSymbols(doc, createToken())).then(value => { + if (!value || value.length === 0) { + return undefined; + } + if (value[0] instanceof types.DocumentSymbol) { + return (value).map(Converter.fromDocumentSymbol); + } else { + return OutlineAdapter.asDocumentSymbolTree(resource, value); + } + }); + } - private static asDocumentSymbolTree(resource: URI, info: types.SymbolInformation[]): DocumentSymbol[] { - // first sort by start (and end) and then loop over all elements - // and build a tree based on containment. - info = info.slice(0).sort((a, b) => { - let r = a.location.range.start.compareTo(b.location.range.start); - if (r === 0) { - r = b.location.range.end.compareTo(a.location.range.end); - } - return r; - }); - const res: DocumentSymbol[] = []; - const parentStack: DocumentSymbol[] = []; - for (let i = 0; i < info.length; i++) { - const element = { - name: info[i].name, - detail: '', - kind: Converter.SymbolKind.fromSymbolKind(info[i].kind), - containerName: info[i].containerName, - range: Converter.fromRange(info[i].location.range), - selectionRange: Converter.fromRange(info[i].location.range), - children: [] - }; + private static asDocumentSymbolTree(resource: URI, info: types.SymbolInformation[]): DocumentSymbol[] { + // first sort by start (and end) and then loop over all elements + // and build a tree based on containment. + info = info.slice(0).sort((a, b) => { + let r = a.location.range.start.compareTo(b.location.range.start); + if (r === 0) { + r = b.location.range.end.compareTo(a.location.range.end); + } + return r; + }); + const res: DocumentSymbol[] = []; + const parentStack: DocumentSymbol[] = []; + for (let i = 0; i < info.length; i++) { + const element = { + name: info[i].name, + detail: '', + kind: Converter.SymbolKind.fromSymbolKind(info[i].kind), + containerName: info[i].containerName, + range: Converter.fromRange(info[i].location.range), + selectionRange: Converter.fromRange(info[i].location.range), + children: [] + }; - while (true) { - if (parentStack.length === 0) { - parentStack.push(element); - res.push(element); - break; - } - const parent = parentStack[parentStack.length - 1]; - if (OutlineAdapter.containsRange(parent.range, element.range) && !OutlineAdapter.equalsRange(parent.range, element.range)) { - parent.children!.push(element); - parentStack.push(element); - break; - } - parentStack.pop(); - } - } - return res; - } + while (true) { + if (parentStack.length === 0) { + parentStack.push(element); + res.push(element); + break; + } + const parent = parentStack[parentStack.length - 1]; + if (OutlineAdapter.containsRange(parent.range, element.range) && !OutlineAdapter.equalsRange(parent.range, element.range)) { + parent.children!.push(element); + parentStack.push(element); + break; + } + parentStack.pop(); + } + } + return res; + } - /** - * Test if `otherRange` is in `range`. If the ranges are equal, will return true. - */ - private static containsRange(range: Range, otherRange: Range): boolean { - if (otherRange.startLineNumber < range.startLineNumber || otherRange.endLineNumber < range.startLineNumber) { - return false; - } - if (otherRange.startLineNumber > range.endLineNumber || otherRange.endLineNumber > range.endLineNumber) { - return false; - } - if (otherRange.startLineNumber === range.startLineNumber && otherRange.startColumn < range.startColumn) { - return false; - } - if (otherRange.endLineNumber === range.endLineNumber && otherRange.endColumn > range.endColumn) { - return false; - } - return true; - } + /** + * Test if `otherRange` is in `range`. If the ranges are equal, will return true. + */ + private static containsRange(range: Range, otherRange: Range): boolean { + if (otherRange.startLineNumber < range.startLineNumber || otherRange.endLineNumber < range.startLineNumber) { + return false; + } + if (otherRange.startLineNumber > range.endLineNumber || otherRange.endLineNumber > range.endLineNumber) { + return false; + } + if (otherRange.startLineNumber === range.startLineNumber && otherRange.startColumn < range.startColumn) { + return false; + } + if (otherRange.endLineNumber === range.endLineNumber && otherRange.endColumn > range.endColumn) { + return false; + } + return true; + } - /** - * Test if range `a` equals `b`. - */ - private static equalsRange(a: Range, b: Range): boolean { - return ( - !!a && - !!b && - a.startLineNumber === b.startLineNumber && - a.startColumn === b.startColumn && - a.endLineNumber === b.endLineNumber && - a.endColumn === b.endColumn - ); - } + /** + * Test if range `a` equals `b`. + */ + private static equalsRange(a: Range, b: Range): boolean { + return ( + !!a && + !!b && + a.startLineNumber === b.startLineNumber && + a.startColumn === b.startColumn && + a.endLineNumber === b.endLineNumber && + a.endColumn === b.endColumn + ); + } }