Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit 151135b

Browse files
committed
chore: adopt ESLint
1 parent 5ec3465 commit 151135b

8 files changed

Lines changed: 1020 additions & 306 deletions

File tree

.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "@sourcegraph/eslint-config",
3+
"parserOptions": {
4+
"project": "tsconfig.json"
5+
}
6+
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
- stage: test
1010
script:
1111
- npm run prettier-check
12-
- npm run tslint
1312
- npm run typecheck
13+
- npm run eslint
1414
- npm run build
1515
- npm run cover
1616
- nyc report --reporter json

.vscode/tasks.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "eslint",
9+
"problemMatcher": ["$eslint-stylish"]
10+
}
11+
]
12+
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
]
9191
},
9292
"scripts": {
93-
"tslint": "tslint -p tsconfig.json './src/**/*.ts'",
93+
"eslint": "eslint './src/**/*.ts'",
9494
"typecheck": "tsc -p tsconfig.json",
9595
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha --require ts-node/register --require source-map-support/register --opts mocha.opts",
9696
"cover": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --require ts-node/register --require source-map-support/register --all mocha --opts mocha.opts --timeout 10000",
@@ -109,12 +109,13 @@
109109
"devDependencies": {
110110
"@commitlint/cli": "^7.0.0",
111111
"@commitlint/config-conventional": "^7.0.1",
112+
"@sourcegraph/eslint-config": "^0.12.0",
112113
"@sourcegraph/prettierrc": "^2.2.0",
113114
"@sourcegraph/tsconfig": "^3.0.0",
114-
"@sourcegraph/tslint-config": "^12.1.0",
115115
"@types/mocha": "^5.2.6",
116116
"@types/node": "^12.7.3",
117117
"@types/sinon": "^7.0.8",
118+
"eslint": "^6.8.0",
118119
"husky": "^1.3.1",
119120
"mocha": "^6.0.2",
120121
"nyc": "^13.3.0",
@@ -124,7 +125,6 @@
124125
"source-map-support": "^0.5.10",
125126
"sourcegraph": "^23.0.0",
126127
"ts-node": "^8.0.2",
127-
"tslint": "^5.13.1",
128128
"typescript": "^3.3.3333"
129129
},
130130
"dependencies": {

src/codeownersFile.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@ import gql from 'tagged-template-noop'
44
import { resolveURI } from './uri'
55
import { memoizeAsync } from './util/memoizeAsync'
66

7-
export async function getCodeOwners(uri: string): Promise<string[] | null> {
8-
const codeownersFile = await getCodeownersFile({ uri, sourcegraph })
9-
if (!codeownersFile) {
10-
return null
11-
}
12-
const codeownersEntries = parseCodeownersFile(codeownersFile)
13-
const entry = matchCodeownersFile(resolveURI(uri).path, codeownersEntries)
14-
if (entry) {
15-
return entry.owners
16-
}
17-
return null
18-
}
19-
207
const getCodeownersFile = memoizeAsync(
218
async ({
229
uri,
@@ -61,6 +48,19 @@ const getCodeownersFile = memoizeAsync(
6148
}
6249
)
6350

51+
export async function getCodeOwners(uri: string): Promise<string[] | null> {
52+
const codeownersFile = await getCodeownersFile({ uri, sourcegraph })
53+
if (!codeownersFile) {
54+
return null
55+
}
56+
const codeownersEntries = parseCodeownersFile(codeownersFile)
57+
const entry = matchCodeownersFile(resolveURI(uri).path, codeownersEntries)
58+
if (entry) {
59+
return entry.owners
60+
}
61+
return null
62+
}
63+
6464
/**
6565
* An individual entry from a CODEOWNERS file
6666
*/

src/extension.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
import { combineLatest, from, Observable } from 'rxjs'
2-
import { startWith } from 'rxjs/operators'
2+
import { startWith, switchMap, filter, map } from 'rxjs/operators'
33
import * as sourcegraph from 'sourcegraph'
44
import { getCodeOwners } from './codeownersFile'
55
import { formatCodeOwners } from './codeOwners'
66

77
export function activate(ctx: sourcegraph.ExtensionContext): void {
88
ctx.subscriptions.add(
9-
combineLatest(
9+
combineLatest([
1010
from(sourcegraph.workspace.onDidOpenTextDocument).pipe(
1111
startWith(
1212
sourcegraph.app.activeWindow && sourcegraph.app.activeWindow.activeViewComponent
1313
? sourcegraph.app.activeWindow.activeViewComponent.document
1414
: null
1515
)
1616
),
17-
new Observable(subscriber => sourcegraph.configuration.subscribe(() => subscriber.next()))
18-
).subscribe(async ([doc]) => {
19-
if (!doc) {
20-
return
21-
}
22-
23-
let owners: string[] | null = null
24-
if (!sourcegraph.configuration.get().value['codeOwnership.hide']) {
25-
try {
26-
owners = await getCodeOwners(doc.uri)
27-
} catch (err) {
28-
console.error(`Error getting code owners for ${doc.uri}:`, err)
29-
}
30-
}
31-
const { label, description } = formatCodeOwners(owners)
32-
sourcegraph.internal.updateContext({
33-
[`codeOwnership.file.${doc.uri}.label`]: label,
34-
[`codeOwnership.file.${doc.uri}.description`]: description,
17+
new Observable(subscriber => sourcegraph.configuration.subscribe(() => subscriber.next())),
18+
])
19+
.pipe(
20+
map(([textDocument]) => textDocument),
21+
filter((textDocument): textDocument is NonNullable<typeof textDocument> => !!textDocument),
22+
switchMap(async textDocument => {
23+
if (!sourcegraph.configuration.get().value['codeOwnership.hide']) {
24+
try {
25+
return { textDocument, owners: await getCodeOwners(textDocument.uri) }
26+
} catch (err) {
27+
console.error(`Error getting code owners for ${textDocument.uri}:`, err)
28+
}
29+
}
30+
return { textDocument, owners: null }
31+
})
32+
)
33+
.subscribe(({ textDocument, owners }) => {
34+
const { label, description } = formatCodeOwners(owners)
35+
sourcegraph.internal.updateContext({
36+
[`codeOwnership.file.${textDocument.uri}.label`]: label,
37+
[`codeOwnership.file.${textDocument.uri}.description`]: description,
38+
})
3539
})
36-
})
3740
)
3841
}

tslint.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)