Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Ensure CI runs lint and tests (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
efritz authored Sep 14, 2021
1 parent bd4ae0f commit 3545e03
Show file tree
Hide file tree
Showing 56 changed files with 210 additions and 130 deletions.
4 changes: 3 additions & 1 deletion .buildkite/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set -ex
cd "$(dirname "${BASH_SOURCE[0]}")/.."

yarn --mutex network --frozen-lockfile --network-timeout 60000
yarn run build eslint prettier-check
yarn run build
yarn run eslint
yarn run prettier-check
4 changes: 3 additions & 1 deletion .buildkite/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set -ex
cd "$(dirname "${BASH_SOURCE[0]}")/.."

yarn --mutex network --frozen-lockfile --network-timeout 60000
yarn run build test coverage
yarn run build
yarn run test
yarn run coverage
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {
node: true,
},
parserOptions: {
project: ['template/tsconfig.json', 'dev/scripts/tsconfig.json'],
project: ['template/tsconfig.json', 'scripts/tsconfig.json'],
},
ignorePatterns: ['generated-*', '**/dist', 'samples'],
ignorePatterns: ['generated-*', '**/dist'],
rules: {
// [...a] breaks when Array.from(a) works
// when a is not an array but an iterable
"unicorn/prefer-spread": 0
'unicorn/prefer-spread': 0,
},
}
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
generated-*
temp
.cache
.nyc_output
coverage
dist
generated-*
node_modules
coverage
.cache
.nyc_output/

.eslintcache
yarn-error.log
10 changes: 4 additions & 6 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
generated-*
temp
dist
node_modules
coverage
.cache
samples
.nyc_output
coverage
dist
generated-*
node_modules
1 change: 1 addition & 0 deletions scripts/args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import yargs from 'yargs'

import { languageSpecs } from '../template/src/language-specs/languages'
import { LanguageSpec } from '../template/src/language-specs/spec'

Expand Down
9 changes: 7 additions & 2 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as path from 'path'

import { copy, emptyDir, ensureDir } from 'fs-extra'
import * as fs from 'mz/fs'
import * as path from 'path'

import { LanguageSpec } from '../template/src/language-specs/spec'

import { findLanguageSpecs } from './args'

async function main(): Promise<void> {
Expand Down Expand Up @@ -46,7 +49,9 @@ async function generate({ languageID, stylized }: LanguageSpec): Promise<void> {
// Update README.md placeholders with language name
await fs.writeFile(
readmeFilename,
(await fs.readFile(readmeFilename))
(
await fs.readFile(readmeFilename)
)
.toString()
.replace(/LANG\b/g, stylized)
.replace(/LANGID\b/g, languageID)
Expand Down
1 change: 1 addition & 0 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as child_process from 'mz/child_process'
import * as fs from 'mz/fs'

import { findLanguageSpecs } from './args'

async function main(): Promise<void> {
Expand Down
3 changes: 3 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.json",
}
11 changes: 6 additions & 5 deletions template/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as sourcegraph from 'sourcegraph'
import { languageSpecs } from './language-specs/languages'
import { languageID } from './language'
import { from } from 'rxjs'
import { distinctUntilChanged, map, startWith } from 'rxjs/operators'
import * as sourcegraph from 'sourcegraph'

import { languageID } from './language'
import { languageSpecs } from './language-specs/languages'
import { LanguageSpec } from './language-specs/spec'
import { Logger, RedactingLogger } from './logging'
import { createProviders } from './providers'

/**
* Register providers on the extension host.
*
* @param ctx The extension context.
* @param context The extension context.
*/
export const activate = (context: sourcegraph.ExtensionContext): void => {
for (const spec of languageID === 'all'
Expand Down Expand Up @@ -39,7 +40,7 @@ const DUMMY_CTX = {
* Activate the extension by registering definition, reference, and hover providers
* with LSIF and search-based providers.
*
* @param ctx The extension context.
* @param context The extension context.
* @param selector The document selector for which this extension is active.
* @param languageSpec The language spec used to provide search-based code intelligence.
* @param logger An optional logger instance.
Expand Down
4 changes: 3 additions & 1 deletion template/src/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import mock from 'mock-require'

// Stub Sourcegraph API
import { createStubSourcegraphAPI } from '@sourcegraph/extension-api-stubs'
import mock from 'mock-require'

mock('sourcegraph', createStubSourcegraphAPI())
1 change: 1 addition & 0 deletions template/src/language-specs/cpp.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from 'assert'

import { cppSpec } from './cpp'
import { nilFilterContext, nilResult } from './spec.test'

Expand Down
1 change: 1 addition & 0 deletions template/src/language-specs/go.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from 'assert'

import { goSpec } from './go'
import { nilFilterContext, nilResult } from './spec.test'

Expand Down
1 change: 1 addition & 0 deletions template/src/language-specs/go.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path'

import { slashPattern } from './comments'
import { FilterContext, LanguageSpec, Result, LSIFSupport } from './spec'
import { extractFromLines, filterResults } from './util'
Expand Down
4 changes: 3 additions & 1 deletion template/src/language-specs/icons.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as assert from 'assert'
import * as fs from 'mz/fs'
import * as path from 'path'

import * as fs from 'mz/fs'

import { languageSpecs } from './languages'

describe('all defined languages', () => {
Expand Down
1 change: 1 addition & 0 deletions template/src/language-specs/java.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from 'assert'

import { javaSpec } from './java'
import { nilFilterContext, nilResult } from './spec.test'

Expand Down
1 change: 1 addition & 0 deletions template/src/language-specs/java.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path'

import { javaStyleComment } from './comments'
import { FilterContext, LanguageSpec, Result, LSIFSupport } from './spec'
import { extractFromLines, filterResultsByImports, slashToDot } from './util'
Expand Down
11 changes: 6 additions & 5 deletions template/src/language-specs/python.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from 'assert'

import { pythonSpec, relativeImportPath } from './python'
import { nilFilterContext, nilResult } from './spec.test'

Expand Down Expand Up @@ -36,10 +37,10 @@ describe('pythonSpec', () => {

describe('relativeImportPath', () => {
it('converts relative import to path', () => {
assert.equal(relativeImportPath('a/b/c.py', 'foo'), undefined)
assert.equal(relativeImportPath('a/b/c.py', '.foo'), 'a/b/foo')
assert.equal(relativeImportPath('a/b/c.py', '.foo.bar'), 'a/b/foo/bar')
assert.equal(relativeImportPath('a/b/c.py', '..foo.bar'), 'a/foo/bar')
assert.equal(relativeImportPath('a/b/c.py', '....foo'), '../foo')
assert.strictEqual(relativeImportPath('a/b/c.py', 'foo'), undefined)
assert.strictEqual(relativeImportPath('a/b/c.py', '.foo'), 'a/b/foo')
assert.strictEqual(relativeImportPath('a/b/c.py', '.foo.bar'), 'a/b/foo/bar')
assert.strictEqual(relativeImportPath('a/b/c.py', '..foo.bar'), 'a/foo/bar')
assert.strictEqual(relativeImportPath('a/b/c.py', '....foo'), '../foo')
})
})
1 change: 1 addition & 0 deletions template/src/language-specs/python.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path'

import { pythonStyleComment } from './comments'
import { FilterContext, LanguageSpec, Result } from './spec'
import { extractFromLines, filterResultsByImports, removeExtension } from './util'
Expand Down
1 change: 1 addition & 0 deletions template/src/language-specs/typescript.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from 'assert'

import { nilFilterContext, nilResult } from './spec.test'
import { typescriptSpec } from './typescript'

Expand Down
1 change: 1 addition & 0 deletions template/src/language-specs/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path'

import { cStyleComment } from './comments'
import { FilterContext, LanguageSpec, Result, LSIFSupport } from './spec'
import { extractFromLines, filterResultsByImports, removeExtension } from './util'
Expand Down
5 changes: 3 additions & 2 deletions template/src/language-specs/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isDefined } from '../util/helpers'

import { Result } from './spec'

/**
Expand Down Expand Up @@ -32,7 +33,7 @@ export function extractFromLines(fileContent: string, ...patterns: RegExp[]): st
*
* @param results A list of results to filter.
* @param importPaths A list of import paths.
* @param fn The filter function.
* @param func The filter function.
*/
export function filterResultsByImports<T extends Result>(
results: T[],
Expand All @@ -47,7 +48,7 @@ export function filterResultsByImports<T extends Result>(
* function returns the original input unchanged.
*
* @param results A list of results to filter.
* @param fn The filter function.
* @param func The filter function.
*/
export function filterResults<T extends Result>(results: T[], func: (result: T) => boolean): T[] {
const filteredResults = results.filter(result => func(result))
Expand Down
3 changes: 3 additions & 0 deletions template/src/lsif/definition-hover.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as assert from 'assert'

import * as sinon from 'sinon'
import * as sourcegraph from 'sourcegraph'

import { QueryGraphQLFn } from '../util/graphql'

import { GenericLSIFResponse } from './api'
import { definitionAndHoverForPosition, DefinitionAndHoverResponse } from './definition-hover'
import { makeEnvelope, resource1, resource2, resource3, range1, range2, range3, document, position } from './util.test'
Expand Down
9 changes: 6 additions & 3 deletions template/src/lsif/definition-hover.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as sourcegraph from 'sourcegraph'
import gql from 'tagged-template-noop'

import { DefinitionAndHover } from '../providers'
import { queryGraphQL as sgQueryGraphQL, QueryGraphQLFn } from '../util/graphql'
import { LocationConnectionNode, nodeToLocation } from './locations'

import { GenericLSIFResponse, queryLSIF } from './api'
import { DefinitionAndHover } from '../providers'
import { LocationConnectionNode, nodeToLocation } from './locations'

export type DefinitionAndHoverResponse = Partial<DefinitionResponse> & HoverResponse

Expand Down Expand Up @@ -97,7 +99,8 @@ export async function definitionAndHoverForPosition(
* Convert a GraphQL definition and hover response into an object consisting of a list of Sourcegraph
* locations and a markdown-formatted hover object.
*
* @param lsifObj The resolved LSIF object.
* @param textDocument The current document.
* @param lsifObject The resolved LSIF object.
*/
export function definitionAndHoverResponseToLocations(
textDocument: sourcegraph.TextDocument,
Expand Down
3 changes: 2 additions & 1 deletion template/src/lsif/highlights.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as assert from 'assert'
import { range1, range2, range3, range4, document } from './util.test'

import { filterLocationsForDocumentHighlights } from './highlights'
import { range1, range2, range3, range4, document } from './util.test'

describe('filterLocationsForDocumentHighlights', () => {
it('should filter out distinct paths', () => {
Expand Down
1 change: 1 addition & 0 deletions template/src/lsif/highlights.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as sourcegraph from 'sourcegraph'

import { isDefined } from '../util/helpers'

export function filterLocationsForDocumentHighlights(
Expand Down
2 changes: 2 additions & 0 deletions template/src/lsif/locations.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as assert from 'assert'

import * as sourcegraph from 'sourcegraph'

import { nodeToLocation } from './locations'

describe('nodeToLocation', () => {
Expand Down
3 changes: 2 additions & 1 deletion template/src/lsif/locations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as sourcegraph from 'sourcegraph'

import { parseGitURI } from '../util/uri'

export interface LocationConnectionNode {
Expand All @@ -13,7 +14,7 @@ export interface LocationConnectionNode {
/**
* Convert a GraphQL location connection node into a Sourcegraph location.
*
* @param doc The current document.
* @param textDocument The current document.
* @param node A location connection node.
*/
export function nodeToLocation(
Expand Down
15 changes: 9 additions & 6 deletions template/src/lsif/providers.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as assert from 'assert'

import * as sinon from 'sinon'
import * as sourcegraph from 'sourcegraph'

import { QueryGraphQLFn } from '../util/graphql'
import { createGraphQLProviders as createProviders } from './providers'

import { GenericLSIFResponse } from './api'
import { DefinitionResponse, DefinitionAndHoverResponse } from './definition-hover'
import { createGraphQLProviders as createProviders } from './providers'
import { ReferencesResponse, MAX_REFERENCE_PAGE_REQUESTS } from './references'
import {
gatherValues,
Expand All @@ -21,7 +25,6 @@ import {
document,
position,
} from './util.test'
import { DefinitionResponse, DefinitionAndHoverResponse } from './definition-hover'

describe('graphql providers', () => {
describe('combined definition and hover provider', () => {
Expand Down Expand Up @@ -239,9 +242,9 @@ describe('graphql providers', () => {
[[location1], [location1, location2], [location1, location2, location3]]
)

assert.equal(queryGraphQLFn.getCall(0).args[1]?.after, undefined)
assert.equal(queryGraphQLFn.getCall(1).args[1]?.after, 'page2')
assert.equal(queryGraphQLFn.getCall(2).args[1]?.after, 'page3')
assert.strictEqual(queryGraphQLFn.getCall(0).args[1]?.after, undefined)
assert.strictEqual(queryGraphQLFn.getCall(1).args[1]?.after, 'page2')
assert.strictEqual(queryGraphQLFn.getCall(2).args[1]?.after, 'page3')
})

it('should not page results indefinitely', async () => {
Expand Down Expand Up @@ -272,7 +275,7 @@ describe('graphql providers', () => {
values
)

assert.equal(queryGraphQLFn.callCount, MAX_REFERENCE_PAGE_REQUESTS)
assert.strictEqual(queryGraphQLFn.callCount, MAX_REFERENCE_PAGE_REQUESTS)
})
})

Expand Down
10 changes: 6 additions & 4 deletions template/src/lsif/providers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as sourcegraph from 'sourcegraph'

import { Logger } from '../logging'
import { noopProviders, CombinedProviders, DefinitionAndHover } from '../providers'
import { queryGraphQL as sgQueryGraphQL, QueryGraphQLFn } from '../util/graphql'
import { asyncGeneratorFromPromise, cachePromiseProvider } from '../util/ix'
import { Logger } from '../logging'
import { RangeWindowFactoryFn, makeRangeWindowFactory } from './ranges'
import { referencesForPosition, referencePageForPosition } from './references'
import { filterLocationsForDocumentHighlights } from './highlights'
import { raceWithDelayOffset } from '../util/promise'

import { definitionAndHoverForPosition, hoverPayloadToHover } from './definition-hover'
import { filterLocationsForDocumentHighlights } from './highlights'
import { RangeWindowFactoryFn, makeRangeWindowFactory } from './ranges'
import { referencesForPosition, referencePageForPosition } from './references'

/**
* Creates providers powered by LSIF-based code intelligence. This particular
Expand Down
Loading

0 comments on commit 3545e03

Please sign in to comment.