Skip to content

Commit fdeab08

Browse files
authored
Merge pull request #382 from bash-lsp/renovate/prettier-2.x
Update dependency prettier to v2
2 parents 0a78633 + 741796b commit fdeab08

File tree

16 files changed

+71
-70
lines changed

16 files changed

+71
-70
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"eslint-plugin-prettier": "3.4.1",
2727
"eslint-plugin-simple-import-sort": "4.0.0",
2828
"jest": "25.5.4",
29-
"prettier": "1.19.1",
29+
"prettier": "2.6.2",
3030
"ts-jest": "25.5.1",
3131
"typescript": "3.9.10",
3232
"vscode-languageserver": "6.1.1"

server/bin/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const package = require('../package')
66

77
const args = process.argv
88

9-
const start = args.find(s => s == 'start')
10-
const version = args.find(s => s == '-v' || s == '--version')
11-
const help = args.find(s => s == '-h' || s == '--help')
9+
const start = args.find((s) => s == 'start')
10+
const version = args.find((s) => s == '-v' || s == '--version')
11+
const help = args.find((s) => s == '-h' || s == '--help')
1212

1313
if (start) {
1414
server.listen()

server/src/__tests__/executables.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ beforeAll(async () => {
1212

1313
describe('list', () => {
1414
it('finds executables on the PATH', async () => {
15-
const result = executables.list().find(x => x === 'iam-executable')
15+
const result = executables.list().find((x) => x === 'iam-executable')
1616
expect(result).toBeTruthy()
1717
})
1818

1919
it.skip('only considers files that have the executable bit set', async () => {
20-
const result = executables.list().find(x => x === 'iam-not-executable')
20+
const result = executables.list().find((x) => x === 'iam-not-executable')
2121
expect(result).toBeFalsy()
2222
})
2323

2424
it('only considers executable directly on the PATH', async () => {
25-
const result = executables.list().find(x => x === 'iam-executable-in-sub-folder')
25+
const result = executables.list().find((x) => x === 'iam-executable-in-sub-folder')
2626
expect(result).toBeFalsy()
2727
})
2828
})

server/src/analyser.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ export default class Analyzer {
123123
*/
124124
public findDefinition(name: string): LSP.Location[] {
125125
const symbols: LSP.SymbolInformation[] = []
126-
Object.keys(this.uriToDeclarations).forEach(uri => {
126+
Object.keys(this.uriToDeclarations).forEach((uri) => {
127127
const declarationNames = this.uriToDeclarations[uri][name] || []
128-
declarationNames.forEach(d => symbols.push(d))
128+
declarationNames.forEach((d) => symbols.push(d))
129129
})
130-
return symbols.map(s => s.location)
130+
return symbols.map((s) => s.location)
131131
}
132132

133133
/**
@@ -175,10 +175,7 @@ export default class Analyzer {
175175

176176
// FIXME: type the response and unit test it
177177
const explainshellResponse = await request({
178-
uri: URI(endpoint)
179-
.path('/api/explain')
180-
.addQuery('cmd', cmd)
181-
.toString(),
178+
uri: URI(endpoint).path('/api/explain').addQuery('cmd', cmd).toString(),
182179
json: true,
183180
})
184181

@@ -216,7 +213,7 @@ export default class Analyzer {
216213
*/
217214
public findReferences(name: string): LSP.Location[] {
218215
const uris = Object.keys(this.uriToTreeSitterTrees)
219-
return flattenArray(uris.map(uri => this.findOccurrences(uri, name)))
216+
return flattenArray(uris.map((uri) => this.findOccurrences(uri, name)))
220217
}
221218

222219
/**
@@ -229,7 +226,7 @@ export default class Analyzer {
229226

230227
const locations: LSP.Location[] = []
231228

232-
TreeSitterUtil.forEach(tree.rootNode, n => {
229+
TreeSitterUtil.forEach(tree.rootNode, (n) => {
233230
let name: null | string = null
234231
let range: null | LSP.Range = null
235232

@@ -273,12 +270,12 @@ export default class Analyzer {
273270
}): LSP.SymbolInformation[] {
274271
const symbols: LSP.SymbolInformation[] = []
275272

276-
Object.keys(this.uriToDeclarations).forEach(uri => {
273+
Object.keys(this.uriToDeclarations).forEach((uri) => {
277274
const declarationsInFile = this.uriToDeclarations[uri] || {}
278-
Object.keys(declarationsInFile).map(name => {
275+
Object.keys(declarationsInFile).map((name) => {
279276
const match = exactMatch ? name === word : name.startsWith(word)
280277
if (match) {
281-
declarationsInFile[name].forEach(symbol => symbols.push(symbol))
278+
declarationsInFile[name].forEach((symbol) => symbols.push(symbol))
282279
}
283280
})
284281
})
@@ -325,7 +322,10 @@ export default class Analyzer {
325322
const name = contents.slice(named.startIndex, named.endIndex)
326323
const namedDeclarations = this.uriToDeclarations[uri][name] || []
327324

328-
const parent = TreeSitterUtil.findParent(n, p => p.type === 'function_definition')
325+
const parent = TreeSitterUtil.findParent(
326+
n,
327+
(p) => p.type === 'function_definition',
328+
)
329329
const parentName =
330330
parent && parent.firstNamedChild
331331
? contents.slice(
@@ -469,17 +469,19 @@ export default class Analyzer {
469469
}
470470

471471
public getAllVariableSymbols(): LSP.SymbolInformation[] {
472-
return this.getAllSymbols().filter(symbol => symbol.kind === LSP.SymbolKind.Variable)
472+
return this.getAllSymbols().filter(
473+
(symbol) => symbol.kind === LSP.SymbolKind.Variable,
474+
)
473475
}
474476

475477
private getAllSymbols(): LSP.SymbolInformation[] {
476478
// NOTE: this could be cached, it takes < 1 ms to generate for a project with 250 bash files...
477479
const symbols: LSP.SymbolInformation[] = []
478480

479-
Object.keys(this.uriToDeclarations).forEach(uri => {
480-
Object.keys(this.uriToDeclarations[uri]).forEach(name => {
481+
Object.keys(this.uriToDeclarations).forEach((uri) => {
482+
Object.keys(this.uriToDeclarations[uri]).forEach((name) => {
481483
const declarationNames = this.uriToDeclarations[uri][name] || []
482-
declarationNames.forEach(d => symbols.push(d))
484+
declarationNames.forEach((d) => symbols.push(d))
483485
})
484486
})
485487

server/src/executables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export default class Executables {
1717
*/
1818
public static fromPath(path: string): Promise<Executables> {
1919
const paths = path.split(':')
20-
const promises = paths.map(x => findExecutablesInPath(x))
20+
const promises = paths.map((x) => findExecutablesInPath(x))
2121
return Promise.all(promises)
2222
.then(ArrayUtil.flatten)
2323
.then(ArrayUtil.uniq)
24-
.then(executables => new Executables(executables))
24+
.then((executables) => new Executables(executables))
2525
}
2626

2727
private executables: Set<string>

server/src/linter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export default class Linter {
7373
const proc = spawn(executablePath, [...args, '-'], { cwd: this.cwd })
7474
proc.on('error', reject)
7575
proc.on('close', resolve)
76-
proc.stdout.on('data', data => (out += data))
77-
proc.stderr.on('data', data => (err += data))
76+
proc.stdout.on('data', (data) => (out += data))
77+
proc.stderr.on('data', (data) => (err += data))
7878
proc.stdin.on('error', () => {
7979
// XXX: Ignore STDIN errors in case the process ends too quickly, before we try to
8080
// write. If we write after the process ends without this, we get an uncatchable EPIPE.

server/src/server.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class BashServer {
7474
// The content of a text document has changed. This event is emitted
7575
// when the text document first opened or when its content has changed.
7676
this.documents.listen(this.connection)
77-
this.documents.onDidChangeContent(async change => {
77+
this.documents.onDidChangeContent(async (change) => {
7878
const { uri } = change.document
7979

8080
// Load the tree for the modified contents into the analyzer:
@@ -183,8 +183,9 @@ export default class BashServer {
183183
currentUri,
184184
symbolUri,
185185
)}${symbolDocumentation}`
186-
: `${symbolKindToDescription(symbol.kind)} defined on line ${symbolStarLine +
187-
1}${symbolDocumentation}`
186+
: `${symbolKindToDescription(symbol.kind)} defined on line ${
187+
symbolStarLine + 1
188+
}${symbolDocumentation}`
188189
}
189190

190191
private getCompletionItemsForSymbols({
@@ -272,7 +273,7 @@ export default class BashServer {
272273
currentUri,
273274
})
274275
// do not return hover referencing for the current line
275-
.filter(symbol => symbol.location.range.start.line !== params.position.line)
276+
.filter((symbol) => symbol.location.range.start.line !== params.position.line)
276277
.map((symbol: LSP.SymbolInformation) =>
277278
this.getDocumentationForSymbol({ currentUri, symbol }),
278279
)
@@ -316,7 +317,7 @@ export default class BashServer {
316317

317318
return this.analyzer
318319
.findOccurrences(params.textDocument.uri, word)
319-
.map(n => ({ range: n.range }))
320+
.map((n) => ({ range: n.range }))
320321
}
321322

322323
private onReferences(params: LSP.ReferenceParams): LSP.Location[] | null {
@@ -396,7 +397,7 @@ export default class BashServer {
396397
return symbolCompletions
397398
}
398399

399-
const reservedWordsCompletions = ReservedWords.LIST.map(reservedWord => ({
400+
const reservedWordsCompletions = ReservedWords.LIST.map((reservedWord) => ({
400401
label: reservedWord,
401402
kind: LSP.SymbolKind.Interface, // ??
402403
data: {
@@ -407,8 +408,8 @@ export default class BashServer {
407408

408409
const programCompletions = this.executables
409410
.list()
410-
.filter(executable => !Builtins.isBuiltin(executable))
411-
.map(executable => {
411+
.filter((executable) => !Builtins.isBuiltin(executable))
412+
.map((executable) => {
412413
return {
413414
label: executable,
414415
kind: LSP.SymbolKind.Function,
@@ -419,7 +420,7 @@ export default class BashServer {
419420
}
420421
})
421422

422-
const builtinsCompletions = Builtins.LIST.map(builtin => ({
423+
const builtinsCompletions = Builtins.LIST.map((builtin) => ({
423424
label: builtin,
424425
kind: LSP.SymbolKind.Interface, // ??
425426
data: {
@@ -428,7 +429,7 @@ export default class BashServer {
428429
},
429430
}))
430431

431-
const optionsCompletions = options.map(option => ({
432+
const optionsCompletions = options.map((option) => ({
432433
label: option,
433434
kind: LSP.SymbolKind.Interface,
434435
data: {
@@ -447,7 +448,7 @@ export default class BashServer {
447448

448449
if (word) {
449450
// Filter to only return suffixes of the current word
450-
return allCompletions.filter(item => item.label.startsWith(word))
451+
return allCompletions.filter((item) => item.label.startsWith(word))
451452
}
452453

453454
return allCompletions
@@ -500,15 +501,15 @@ function deduplicateSymbols({
500501

501502
const getSymbolId = ({ name, kind }: LSP.SymbolInformation) => `${name}${kind}`
502503

503-
const symbolsCurrentFile = symbols.filter(s => isCurrentFile(s))
504+
const symbolsCurrentFile = symbols.filter((s) => isCurrentFile(s))
504505

505506
const symbolsOtherFiles = symbols
506-
.filter(s => !isCurrentFile(s))
507+
.filter((s) => !isCurrentFile(s))
507508
// Remove identical symbols matching current file
508509
.filter(
509-
symbolOtherFiles =>
510+
(symbolOtherFiles) =>
510511
!symbolsCurrentFile.some(
511-
symbolCurrentFile =>
512+
(symbolCurrentFile) =>
512513
getSymbolId(symbolCurrentFile) === getSymbolId(symbolOtherFiles),
513514
),
514515
)
@@ -599,6 +600,6 @@ function getCommandOptions(name: string, word: string): string[] {
599600
return options.stdout
600601
.toString()
601602
.split('\t')
602-
.map(l => l.trim())
603-
.filter(l => l.length > 0)
603+
.map((l) => l.trim())
604+
.filter((l) => l.length > 0)
604605
}

server/src/util/__tests__/sh.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ BSD April 12, 2003 BSD`)
512512

513513
describe('memorize', () => {
514514
it('memorizes a function', async () => {
515-
const fnRaw = jest.fn(async args => args)
515+
const fnRaw = jest.fn(async (args) => args)
516516
const arg1 = { one: '1' }
517517
const arg2 = { another: { word: 'word' } }
518518
const fnMemorized = sh.memorize(fnRaw)

server/src/util/array.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function uniqueBasedOnHash<A extends Record<string, any>>(
2525
const result: typeof list = []
2626
const hashSet = new Set<string>()
2727

28-
list.forEach(element => {
28+
list.forEach((element) => {
2929
const hash = elementToHash(element)
3030
if (hashSet.has(hash)) {
3131
return

server/src/util/flatten.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export function flattenArray<T>(nestedArray: T[][]): T[] {
33
}
44

55
export function flattenObjectValues<T>(object: { [key: string]: T[] }): T[] {
6-
return flattenArray(Object.keys(object).map(objectKey => object[objectKey]))
6+
return flattenArray(Object.keys(object).map((objectKey) => object[objectKey]))
77
}

server/src/util/fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function getFilePaths({
2020
glob(
2121
globPattern,
2222
{ cwd: rootPath, nodir: true, absolute: true, strict: false },
23-
function(err, files) {
23+
function (err, files) {
2424
if (err) {
2525
return reject(err)
2626
}

server/src/util/sh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function execShellScript(body: string, cmd = 'bash'): Promise<string> {
1818
}
1919
}
2020

21-
process.stdout.on('data', buffer => {
21+
process.stdout.on('data', (buffer) => {
2222
output += buffer
2323
})
2424

@@ -110,7 +110,7 @@ export function formatManOutput(manOutput: string): string {
110110
export function memorize<T extends Function>(func: T): T {
111111
const cache = new Map()
112112

113-
const returnFunc = async function(arg: any) {
113+
const returnFunc = async function (arg: any) {
114114
const cacheKey = JSON.stringify(arg)
115115

116116
if (cache.has(cacheKey)) {

server/src/util/tree-sitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SyntaxNode } from 'web-tree-sitter'
44
export function forEach(node: SyntaxNode, cb: (n: SyntaxNode) => void) {
55
cb(node)
66
if (node.children.length) {
7-
node.children.forEach(n => forEach(n, cb))
7+
node.children.forEach((n) => forEach(n, cb))
88
}
99
}
1010

testing/fixtures.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export const FIXTURE_URI = {
2727
SHELLCHECK_SOURCE: `file://${path.join(FIXTURE_FOLDER, 'shellcheck', 'source.sh')}`,
2828
}
2929

30-
export const FIXTURE_DOCUMENT: Record<FIXTURE_KEY, LSP.TextDocument> = (Object.keys(
31-
FIXTURE_URI,
32-
) as Array<FIXTURE_KEY>).reduce((acc, cur: FIXTURE_KEY) => {
30+
export const FIXTURE_DOCUMENT: Record<FIXTURE_KEY, LSP.TextDocument> = (
31+
Object.keys(FIXTURE_URI) as Array<FIXTURE_KEY>
32+
).reduce((acc, cur: FIXTURE_KEY) => {
3333
acc[cur] = getDocument(FIXTURE_URI[cur])
3434
return acc
3535
}, {} as any)

vscode-client/src/server.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@ import {
99

1010
const connection: IConnection = createConnection(ProposedFeatures.all)
1111

12-
connection.onInitialize(
13-
async (params: InitializeParams): Promise<InitializeResult> => {
14-
connection.console.info('BashLanguageServer initializing...')
12+
connection.onInitialize(async (params: InitializeParams): Promise<InitializeResult> => {
13+
connection.console.info('BashLanguageServer initializing...')
1514

16-
const server = await BashLanguageServer.initialize(connection, params)
17-
server.register(connection)
15+
const server = await BashLanguageServer.initialize(connection, params)
16+
server.register(connection)
1817

19-
connection.console.info('BashLanguageServer initialized')
18+
connection.console.info('BashLanguageServer initialized')
2019

21-
return {
22-
capabilities: server.capabilities(),
23-
}
24-
},
25-
)
20+
return {
21+
capabilities: server.capabilities(),
22+
}
23+
})
2624

2725
connection.listen()
2826

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,10 +2803,10 @@ prettier-linter-helpers@^1.0.0:
28032803
dependencies:
28042804
fast-diff "^1.1.2"
28052805

2806-
prettier@1.19.1:
2807-
version "1.19.1"
2808-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
2809-
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
2806+
prettier@2.6.2:
2807+
version "2.6.2"
2808+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032"
2809+
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==
28102810

28112811
pretty-format@^25.2.1, pretty-format@^25.5.0:
28122812
version "25.5.0"

0 commit comments

Comments
 (0)