From 80d2ce918a138cafebd63a381769313b95c06ac1 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 14 May 2022 05:30:35 +0000 Subject: [PATCH 1/2] Update dependency prettier to v2 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 307adbcd3..43870b4cf 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "eslint-plugin-prettier": "3.4.1", "eslint-plugin-simple-import-sort": "4.0.0", "jest": "25.5.4", - "prettier": "1.19.1", + "prettier": "2.6.2", "ts-jest": "25.5.1", "typescript": "3.9.10", "vscode-languageserver": "6.1.1" diff --git a/yarn.lock b/yarn.lock index 25c2a0d81..a870a333c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2803,10 +2803,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@1.19.1: - version "1.19.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" - integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== +prettier@2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032" + integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew== pretty-format@^25.2.1, pretty-format@^25.5.0: version "25.5.0" From 741796b248b4ff2679dd7c492dd317a8204e670d Mon Sep 17 00:00:00 2001 From: skovhus Date: Sat, 14 May 2022 20:23:15 +0200 Subject: [PATCH 2/2] Run formatter --- server/bin/main.js | 6 ++-- server/src/__tests__/executables.test.ts | 6 ++-- server/src/analyser.ts | 36 +++++++++++++----------- server/src/executables.ts | 4 +-- server/src/linter.ts | 4 +-- server/src/server.ts | 35 ++++++++++++----------- server/src/util/__tests__/sh.test.ts | 2 +- server/src/util/array.ts | 2 +- server/src/util/flatten.ts | 2 +- server/src/util/fs.ts | 2 +- server/src/util/sh.ts | 4 +-- server/src/util/tree-sitter.ts | 2 +- testing/fixtures.ts | 6 ++-- vscode-client/src/server.ts | 20 ++++++------- 14 files changed, 66 insertions(+), 65 deletions(-) diff --git a/server/bin/main.js b/server/bin/main.js index 7af38ec23..16609d819 100755 --- a/server/bin/main.js +++ b/server/bin/main.js @@ -6,9 +6,9 @@ const package = require('../package') const args = process.argv -const start = args.find(s => s == 'start') -const version = args.find(s => s == '-v' || s == '--version') -const help = args.find(s => s == '-h' || s == '--help') +const start = args.find((s) => s == 'start') +const version = args.find((s) => s == '-v' || s == '--version') +const help = args.find((s) => s == '-h' || s == '--help') if (start) { server.listen() diff --git a/server/src/__tests__/executables.test.ts b/server/src/__tests__/executables.test.ts index 7d64bfccc..10e79bf3c 100644 --- a/server/src/__tests__/executables.test.ts +++ b/server/src/__tests__/executables.test.ts @@ -12,17 +12,17 @@ beforeAll(async () => { describe('list', () => { it('finds executables on the PATH', async () => { - const result = executables.list().find(x => x === 'iam-executable') + const result = executables.list().find((x) => x === 'iam-executable') expect(result).toBeTruthy() }) it.skip('only considers files that have the executable bit set', async () => { - const result = executables.list().find(x => x === 'iam-not-executable') + const result = executables.list().find((x) => x === 'iam-not-executable') expect(result).toBeFalsy() }) it('only considers executable directly on the PATH', async () => { - const result = executables.list().find(x => x === 'iam-executable-in-sub-folder') + const result = executables.list().find((x) => x === 'iam-executable-in-sub-folder') expect(result).toBeFalsy() }) }) diff --git a/server/src/analyser.ts b/server/src/analyser.ts index dba8c8ba8..66af8766d 100644 --- a/server/src/analyser.ts +++ b/server/src/analyser.ts @@ -123,11 +123,11 @@ export default class Analyzer { */ public findDefinition(name: string): LSP.Location[] { const symbols: LSP.SymbolInformation[] = [] - Object.keys(this.uriToDeclarations).forEach(uri => { + Object.keys(this.uriToDeclarations).forEach((uri) => { const declarationNames = this.uriToDeclarations[uri][name] || [] - declarationNames.forEach(d => symbols.push(d)) + declarationNames.forEach((d) => symbols.push(d)) }) - return symbols.map(s => s.location) + return symbols.map((s) => s.location) } /** @@ -175,10 +175,7 @@ export default class Analyzer { // FIXME: type the response and unit test it const explainshellResponse = await request({ - uri: URI(endpoint) - .path('/api/explain') - .addQuery('cmd', cmd) - .toString(), + uri: URI(endpoint).path('/api/explain').addQuery('cmd', cmd).toString(), json: true, }) @@ -216,7 +213,7 @@ export default class Analyzer { */ public findReferences(name: string): LSP.Location[] { const uris = Object.keys(this.uriToTreeSitterTrees) - return flattenArray(uris.map(uri => this.findOccurrences(uri, name))) + return flattenArray(uris.map((uri) => this.findOccurrences(uri, name))) } /** @@ -229,7 +226,7 @@ export default class Analyzer { const locations: LSP.Location[] = [] - TreeSitterUtil.forEach(tree.rootNode, n => { + TreeSitterUtil.forEach(tree.rootNode, (n) => { let name: null | string = null let range: null | LSP.Range = null @@ -273,12 +270,12 @@ export default class Analyzer { }): LSP.SymbolInformation[] { const symbols: LSP.SymbolInformation[] = [] - Object.keys(this.uriToDeclarations).forEach(uri => { + Object.keys(this.uriToDeclarations).forEach((uri) => { const declarationsInFile = this.uriToDeclarations[uri] || {} - Object.keys(declarationsInFile).map(name => { + Object.keys(declarationsInFile).map((name) => { const match = exactMatch ? name === word : name.startsWith(word) if (match) { - declarationsInFile[name].forEach(symbol => symbols.push(symbol)) + declarationsInFile[name].forEach((symbol) => symbols.push(symbol)) } }) }) @@ -325,7 +322,10 @@ export default class Analyzer { const name = contents.slice(named.startIndex, named.endIndex) const namedDeclarations = this.uriToDeclarations[uri][name] || [] - const parent = TreeSitterUtil.findParent(n, p => p.type === 'function_definition') + const parent = TreeSitterUtil.findParent( + n, + (p) => p.type === 'function_definition', + ) const parentName = parent && parent.firstNamedChild ? contents.slice( @@ -469,17 +469,19 @@ export default class Analyzer { } public getAllVariableSymbols(): LSP.SymbolInformation[] { - return this.getAllSymbols().filter(symbol => symbol.kind === LSP.SymbolKind.Variable) + return this.getAllSymbols().filter( + (symbol) => symbol.kind === LSP.SymbolKind.Variable, + ) } private getAllSymbols(): LSP.SymbolInformation[] { // NOTE: this could be cached, it takes < 1 ms to generate for a project with 250 bash files... const symbols: LSP.SymbolInformation[] = [] - Object.keys(this.uriToDeclarations).forEach(uri => { - Object.keys(this.uriToDeclarations[uri]).forEach(name => { + Object.keys(this.uriToDeclarations).forEach((uri) => { + Object.keys(this.uriToDeclarations[uri]).forEach((name) => { const declarationNames = this.uriToDeclarations[uri][name] || [] - declarationNames.forEach(d => symbols.push(d)) + declarationNames.forEach((d) => symbols.push(d)) }) }) diff --git a/server/src/executables.ts b/server/src/executables.ts index d41d5587c..ef6fea9f1 100644 --- a/server/src/executables.ts +++ b/server/src/executables.ts @@ -17,11 +17,11 @@ export default class Executables { */ public static fromPath(path: string): Promise { const paths = path.split(':') - const promises = paths.map(x => findExecutablesInPath(x)) + const promises = paths.map((x) => findExecutablesInPath(x)) return Promise.all(promises) .then(ArrayUtil.flatten) .then(ArrayUtil.uniq) - .then(executables => new Executables(executables)) + .then((executables) => new Executables(executables)) } private executables: Set diff --git a/server/src/linter.ts b/server/src/linter.ts index 3e68ada4f..0f78c6498 100644 --- a/server/src/linter.ts +++ b/server/src/linter.ts @@ -73,8 +73,8 @@ export default class Linter { const proc = spawn(executablePath, [...args, '-'], { cwd: this.cwd }) proc.on('error', reject) proc.on('close', resolve) - proc.stdout.on('data', data => (out += data)) - proc.stderr.on('data', data => (err += data)) + proc.stdout.on('data', (data) => (out += data)) + proc.stderr.on('data', (data) => (err += data)) proc.stdin.on('error', () => { // XXX: Ignore STDIN errors in case the process ends too quickly, before we try to // write. If we write after the process ends without this, we get an uncatchable EPIPE. diff --git a/server/src/server.ts b/server/src/server.ts index 2e1c565fc..50a7002c3 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -74,7 +74,7 @@ export default class BashServer { // The content of a text document has changed. This event is emitted // when the text document first opened or when its content has changed. this.documents.listen(this.connection) - this.documents.onDidChangeContent(async change => { + this.documents.onDidChangeContent(async (change) => { const { uri } = change.document // Load the tree for the modified contents into the analyzer: @@ -183,8 +183,9 @@ export default class BashServer { currentUri, symbolUri, )}${symbolDocumentation}` - : `${symbolKindToDescription(symbol.kind)} defined on line ${symbolStarLine + - 1}${symbolDocumentation}` + : `${symbolKindToDescription(symbol.kind)} defined on line ${ + symbolStarLine + 1 + }${symbolDocumentation}` } private getCompletionItemsForSymbols({ @@ -272,7 +273,7 @@ export default class BashServer { currentUri, }) // do not return hover referencing for the current line - .filter(symbol => symbol.location.range.start.line !== params.position.line) + .filter((symbol) => symbol.location.range.start.line !== params.position.line) .map((symbol: LSP.SymbolInformation) => this.getDocumentationForSymbol({ currentUri, symbol }), ) @@ -316,7 +317,7 @@ export default class BashServer { return this.analyzer .findOccurrences(params.textDocument.uri, word) - .map(n => ({ range: n.range })) + .map((n) => ({ range: n.range })) } private onReferences(params: LSP.ReferenceParams): LSP.Location[] | null { @@ -396,7 +397,7 @@ export default class BashServer { return symbolCompletions } - const reservedWordsCompletions = ReservedWords.LIST.map(reservedWord => ({ + const reservedWordsCompletions = ReservedWords.LIST.map((reservedWord) => ({ label: reservedWord, kind: LSP.SymbolKind.Interface, // ?? data: { @@ -407,8 +408,8 @@ export default class BashServer { const programCompletions = this.executables .list() - .filter(executable => !Builtins.isBuiltin(executable)) - .map(executable => { + .filter((executable) => !Builtins.isBuiltin(executable)) + .map((executable) => { return { label: executable, kind: LSP.SymbolKind.Function, @@ -419,7 +420,7 @@ export default class BashServer { } }) - const builtinsCompletions = Builtins.LIST.map(builtin => ({ + const builtinsCompletions = Builtins.LIST.map((builtin) => ({ label: builtin, kind: LSP.SymbolKind.Interface, // ?? data: { @@ -428,7 +429,7 @@ export default class BashServer { }, })) - const optionsCompletions = options.map(option => ({ + const optionsCompletions = options.map((option) => ({ label: option, kind: LSP.SymbolKind.Interface, data: { @@ -447,7 +448,7 @@ export default class BashServer { if (word) { // Filter to only return suffixes of the current word - return allCompletions.filter(item => item.label.startsWith(word)) + return allCompletions.filter((item) => item.label.startsWith(word)) } return allCompletions @@ -500,15 +501,15 @@ function deduplicateSymbols({ const getSymbolId = ({ name, kind }: LSP.SymbolInformation) => `${name}${kind}` - const symbolsCurrentFile = symbols.filter(s => isCurrentFile(s)) + const symbolsCurrentFile = symbols.filter((s) => isCurrentFile(s)) const symbolsOtherFiles = symbols - .filter(s => !isCurrentFile(s)) + .filter((s) => !isCurrentFile(s)) // Remove identical symbols matching current file .filter( - symbolOtherFiles => + (symbolOtherFiles) => !symbolsCurrentFile.some( - symbolCurrentFile => + (symbolCurrentFile) => getSymbolId(symbolCurrentFile) === getSymbolId(symbolOtherFiles), ), ) @@ -599,6 +600,6 @@ function getCommandOptions(name: string, word: string): string[] { return options.stdout .toString() .split('\t') - .map(l => l.trim()) - .filter(l => l.length > 0) + .map((l) => l.trim()) + .filter((l) => l.length > 0) } diff --git a/server/src/util/__tests__/sh.test.ts b/server/src/util/__tests__/sh.test.ts index 84663c06b..435368f16 100644 --- a/server/src/util/__tests__/sh.test.ts +++ b/server/src/util/__tests__/sh.test.ts @@ -512,7 +512,7 @@ BSD April 12, 2003 BSD`) describe('memorize', () => { it('memorizes a function', async () => { - const fnRaw = jest.fn(async args => args) + const fnRaw = jest.fn(async (args) => args) const arg1 = { one: '1' } const arg2 = { another: { word: 'word' } } const fnMemorized = sh.memorize(fnRaw) diff --git a/server/src/util/array.ts b/server/src/util/array.ts index 87e847da5..6f420b449 100644 --- a/server/src/util/array.ts +++ b/server/src/util/array.ts @@ -25,7 +25,7 @@ export function uniqueBasedOnHash>( const result: typeof list = [] const hashSet = new Set() - list.forEach(element => { + list.forEach((element) => { const hash = elementToHash(element) if (hashSet.has(hash)) { return diff --git a/server/src/util/flatten.ts b/server/src/util/flatten.ts index 07bfefe44..7c4193af3 100644 --- a/server/src/util/flatten.ts +++ b/server/src/util/flatten.ts @@ -3,5 +3,5 @@ export function flattenArray(nestedArray: T[][]): T[] { } export function flattenObjectValues(object: { [key: string]: T[] }): T[] { - return flattenArray(Object.keys(object).map(objectKey => object[objectKey])) + return flattenArray(Object.keys(object).map((objectKey) => object[objectKey])) } diff --git a/server/src/util/fs.ts b/server/src/util/fs.ts index 43a114877..b566a6e5a 100644 --- a/server/src/util/fs.ts +++ b/server/src/util/fs.ts @@ -20,7 +20,7 @@ export async function getFilePaths({ glob( globPattern, { cwd: rootPath, nodir: true, absolute: true, strict: false }, - function(err, files) { + function (err, files) { if (err) { return reject(err) } diff --git a/server/src/util/sh.ts b/server/src/util/sh.ts index 42b50457d..2eb999a09 100644 --- a/server/src/util/sh.ts +++ b/server/src/util/sh.ts @@ -18,7 +18,7 @@ export function execShellScript(body: string, cmd = 'bash'): Promise { } } - process.stdout.on('data', buffer => { + process.stdout.on('data', (buffer) => { output += buffer }) @@ -110,7 +110,7 @@ export function formatManOutput(manOutput: string): string { export function memorize(func: T): T { const cache = new Map() - const returnFunc = async function(arg: any) { + const returnFunc = async function (arg: any) { const cacheKey = JSON.stringify(arg) if (cache.has(cacheKey)) { diff --git a/server/src/util/tree-sitter.ts b/server/src/util/tree-sitter.ts index 3a80b4cfe..cbd7fd853 100644 --- a/server/src/util/tree-sitter.ts +++ b/server/src/util/tree-sitter.ts @@ -4,7 +4,7 @@ import { SyntaxNode } from 'web-tree-sitter' export function forEach(node: SyntaxNode, cb: (n: SyntaxNode) => void) { cb(node) if (node.children.length) { - node.children.forEach(n => forEach(n, cb)) + node.children.forEach((n) => forEach(n, cb)) } } diff --git a/testing/fixtures.ts b/testing/fixtures.ts index 88a4eae30..f703e1082 100644 --- a/testing/fixtures.ts +++ b/testing/fixtures.ts @@ -27,9 +27,9 @@ export const FIXTURE_URI = { SHELLCHECK_SOURCE: `file://${path.join(FIXTURE_FOLDER, 'shellcheck', 'source.sh')}`, } -export const FIXTURE_DOCUMENT: Record = (Object.keys( - FIXTURE_URI, -) as Array).reduce((acc, cur: FIXTURE_KEY) => { +export const FIXTURE_DOCUMENT: Record = ( + Object.keys(FIXTURE_URI) as Array +).reduce((acc, cur: FIXTURE_KEY) => { acc[cur] = getDocument(FIXTURE_URI[cur]) return acc }, {} as any) diff --git a/vscode-client/src/server.ts b/vscode-client/src/server.ts index a617ccba9..56d359761 100644 --- a/vscode-client/src/server.ts +++ b/vscode-client/src/server.ts @@ -9,20 +9,18 @@ import { const connection: IConnection = createConnection(ProposedFeatures.all) -connection.onInitialize( - async (params: InitializeParams): Promise => { - connection.console.info('BashLanguageServer initializing...') +connection.onInitialize(async (params: InitializeParams): Promise => { + connection.console.info('BashLanguageServer initializing...') - const server = await BashLanguageServer.initialize(connection, params) - server.register(connection) + const server = await BashLanguageServer.initialize(connection, params) + server.register(connection) - connection.console.info('BashLanguageServer initialized') + connection.console.info('BashLanguageServer initialized') - return { - capabilities: server.capabilities(), - } - }, -) + return { + capabilities: server.capabilities(), + } +}) connection.listen()