Skip to content

Update dependency prettier to v2 #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions server/bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions server/src/__tests__/executables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down
36 changes: 19 additions & 17 deletions server/src/analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down Expand Up @@ -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,
})

Expand Down Expand Up @@ -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)))
}

/**
Expand All @@ -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

Expand Down Expand Up @@ -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))
}
})
})
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))
})
})

Expand Down
4 changes: 2 additions & 2 deletions server/src/executables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export default class Executables {
*/
public static fromPath(path: string): Promise<Executables> {
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<string>
Expand Down
4 changes: 2 additions & 2 deletions server/src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 18 additions & 17 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 }),
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand All @@ -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,
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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
Expand Down Expand Up @@ -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),
),
)
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion server/src/util/__tests__/sh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/src/util/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function uniqueBasedOnHash<A extends Record<string, any>>(
const result: typeof list = []
const hashSet = new Set<string>()

list.forEach(element => {
list.forEach((element) => {
const hash = elementToHash(element)
if (hashSet.has(hash)) {
return
Expand Down
2 changes: 1 addition & 1 deletion server/src/util/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export function flattenArray<T>(nestedArray: T[][]): T[] {
}

export function flattenObjectValues<T>(object: { [key: string]: T[] }): T[] {
return flattenArray(Object.keys(object).map(objectKey => object[objectKey]))
return flattenArray(Object.keys(object).map((objectKey) => object[objectKey]))
}
2 changes: 1 addition & 1 deletion server/src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/util/sh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function execShellScript(body: string, cmd = 'bash'): Promise<string> {
}
}

process.stdout.on('data', buffer => {
process.stdout.on('data', (buffer) => {
output += buffer
})

Expand Down Expand Up @@ -110,7 +110,7 @@ export function formatManOutput(manOutput: string): string {
export function memorize<T extends Function>(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)) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/util/tree-sitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
6 changes: 3 additions & 3 deletions testing/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const FIXTURE_URI = {
SHELLCHECK_SOURCE: `file://${path.join(FIXTURE_FOLDER, 'shellcheck', 'source.sh')}`,
}

export const FIXTURE_DOCUMENT: Record<FIXTURE_KEY, LSP.TextDocument> = (Object.keys(
FIXTURE_URI,
) as Array<FIXTURE_KEY>).reduce((acc, cur: FIXTURE_KEY) => {
export const FIXTURE_DOCUMENT: Record<FIXTURE_KEY, LSP.TextDocument> = (
Object.keys(FIXTURE_URI) as Array<FIXTURE_KEY>
).reduce((acc, cur: FIXTURE_KEY) => {
acc[cur] = getDocument(FIXTURE_URI[cur])
return acc
}, {} as any)
Expand Down
20 changes: 9 additions & 11 deletions vscode-client/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ import {

const connection: IConnection = createConnection(ProposedFeatures.all)

connection.onInitialize(
async (params: InitializeParams): Promise<InitializeResult> => {
connection.console.info('BashLanguageServer initializing...')
connection.onInitialize(async (params: InitializeParams): Promise<InitializeResult> => {
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()

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down