Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 2becf28

Browse files
authored
chore: migrate to eslint (#249)
1 parent 25e8f52 commit 2becf28

18 files changed

+987
-142
lines changed

.eslintrc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "@sourcegraph/eslint-config",
3+
"parserOptions": {
4+
"project": "tsconfig.json"
5+
},
6+
"overrides": [
7+
{
8+
"files": ["testdata/**"],
9+
"rules": {
10+
"no-sync": "warn"
11+
}
12+
},
13+
{
14+
"files": ["*.test.*", "src/testutils/**"],
15+
"rules": {
16+
"import/extensions": ["error", "never", { "html": "always" }]
17+
}
18+
}
19+
]
20+
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
script:
1414
- yarn run prettier-check
1515
- yarn run typecheck
16-
- yarn run tslint
16+
- yarn run eslint
1717
- yarn run build
1818
- yarn test -- --single-run --browsers ChromeHeadlessNoSandbox
1919
- bash <(curl -s https://codecov.io/bash)

.vscode/tasks.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@
1414
"runOn": "folderOpen",
1515
},
1616
},
17+
{
18+
"type": "npm",
19+
"script": "eslint",
20+
"problemMatcher": ["$eslint-stylish"],
21+
"label": "ESLint",
22+
"detail": "Lint whole project with ESLint",
23+
},
1724
],
1825
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"prettier": "prettier '**/{*.{js?(on),ts?(x),scss,yml},.*.js?(on),.*.yml}' --write --list-different",
1818
"prettier-check": "npm run prettier -- --write=false",
1919
"typecheck": "tsc -p tsconfig.json",
20-
"tslint": "tslint -c tslint.json -p tsconfig.json './src/*.ts?(x)' './testdata/*.ts?(x)' './*.ts?(x)'",
20+
"eslint": "eslint './src/**/*.ts?(x)' './testdata/**/*.ts?(x)' './*.ts?(x)'",
2121
"build": "tsc -p tsconfig.dist.json",
2222
"watch": "yarn run build --watch",
2323
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' karma start",
@@ -39,9 +39,9 @@
3939
"devDependencies": {
4040
"@commitlint/cli": "^8.3.5",
4141
"@commitlint/config-conventional": "^8.3.4",
42+
"@sourcegraph/eslint-config": "^0.16.0",
4243
"@sourcegraph/prettierrc": "^3.0.3",
4344
"@sourcegraph/tsconfig": "^4.0.1",
44-
"@sourcegraph/tslint-config": "^13.4.0",
4545
"@types/chai": "4.2.11",
4646
"@types/karma": "4.4.1",
4747
"@types/karma-webpack": "2.0.7",
@@ -53,6 +53,7 @@
5353
"@types/webpack-env": "1.15.1",
5454
"awesome-typescript-loader": "^5.2.1",
5555
"chai": "^4.2.0",
56+
"eslint": "^6.8.0",
5657
"esm": "^3.2.25",
5758
"husky": "^4.2.1",
5859
"istanbul-instrumenter-loader": "^3.0.1",
@@ -73,7 +74,6 @@
7374
"sinon": "^8.1.1",
7475
"sourcegraph": "^23.0.1",
7576
"ts-node": "^8.2.0",
76-
"tslint": "^6.1.1",
7777
"typescript": "^3.8.3",
7878
"webpack": "^4.42.1",
7979
"webpack-cli": "^3.3.11"

src/hoverifier.test.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ describe('Hoverifier', () => {
434434
}
435435

436436
// Click (to pin) https://sourcegraph.sgdev.org/github.com/gorilla/mux@cb4698366aa625048f3b815af6a0dea8aef9280a/-/blob/mux.go#L24:6
437-
cold(`a`).subscribe(() => {
437+
cold('a').subscribe(() => {
438438
dispatchMouseEventAtPositionImpure('click', codeView, {
439439
line: 24,
440440
character: 6,
@@ -502,7 +502,7 @@ describe('Hoverifier', () => {
502502
distinctUntilChanged()
503503
)
504504

505-
const outputDiagram = `ab`
505+
const outputDiagram = 'ab'
506506
const outputValues: {
507507
[key: string]: 'hidden' | 'pinned' | 'visible'
508508
} = {
@@ -511,15 +511,15 @@ describe('Hoverifier', () => {
511511
}
512512

513513
// Click (to pin) https://sourcegraph.sgdev.org/github.com/gorilla/mux@cb4698366aa625048f3b815af6a0dea8aef9280a/-/blob/mux.go#L24:6
514-
cold(`a`).subscribe(() =>
514+
cold('a').subscribe(() =>
515515
dispatchMouseEventAtPositionImpure('click', codeView, {
516516
line: 24,
517517
character: 6,
518518
})
519519
)
520520

521521
// Click to another position and ensure the hover is no longer pinned.
522-
cold(`-b`).subscribe(() =>
522+
cold('-b').subscribe(() =>
523523
positionJumps.next({
524524
codeView: codeView.codeView,
525525
scrollElement: codeView.container,
@@ -716,14 +716,17 @@ describe('Hoverifier', () => {
716716
}
717717

718718
// Mouse on https://sourcegraph.sgdev.org/github.com/gorilla/mux@cb4698366aa625048f3b815af6a0dea8aef9280a/-/blob/mux.go#L24:6
719-
cold(`a b ${MOUSEOVER_DELAY - 2}ms c d e`, {
720-
a: 'mouseover',
721-
b: 'mousemove',
722-
// Now perform repeated mousemove/mouseover events on the same token.
723-
c: 'mousemove',
724-
d: 'mouseover',
725-
e: 'mousemove',
726-
} as Record<string, SupportedMouseEvent>).subscribe(eventType =>
719+
cold(
720+
`a b ${MOUSEOVER_DELAY - 2}ms c d e`,
721+
((): Record<string, SupportedMouseEvent> => ({
722+
a: 'mouseover',
723+
b: 'mousemove',
724+
// Now perform repeated mousemove/mouseover events on the same token.
725+
c: 'mousemove',
726+
d: 'mouseover',
727+
e: 'mousemove',
728+
}))()
729+
).subscribe(eventType =>
727730
dispatchMouseEventAtPositionImpure(eventType, codeView, {
728731
line: 24,
729732
character: 6,

src/hoverifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ export function createHoverifier<C extends object, D, A>({
529529
}
530530
return {
531531
...rest,
532-
eventType: 'jump' as 'jump',
532+
eventType: 'jump' as const,
533533
target,
534534
position: { ...position, part },
535535
codeView,
@@ -891,7 +891,7 @@ export function createHoverifier<C extends object, D, A>({
891891
)
892892
}
893893

894-
const resetHover = () => {
894+
const resetHover = (): void => {
895895
container.update({
896896
hoverOverlayIsFixed: false,
897897
hoverOverlayPosition: undefined,

src/positions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('positions', () => {
5959

6060
for (const tokenize of [false, true]) {
6161
for (const codeView of testcases) {
62-
it((tokenize ? 'tokenizes' : 'does not tokenize') + ` the DOM when tokenize: ${tokenize}`, () => {
62+
it((tokenize ? 'tokenizes' : 'does not tokenize') + ` the DOM when tokenize: ${String(tokenize)}`, () => {
6363
of(codeView.codeView)
6464
.pipe(findPositionsFromEvents({ domFunctions: codeView, tokenize }))
6565
.subscribe()

src/positions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const findPositionsFromEvents = ({
6161
),
6262
from(elements).pipe(
6363
switchMap(element => fromEvent<MouseEvent>(element, 'click')),
64-
map(event => ({ event, eventType: 'click' as 'click' })),
64+
map(event => ({ event, eventType: 'click' as const })),
6565
// ignore click events caused by the user selecting text.
6666
// Selecting text should not mess with the hover, hover pinning nor the URL.
6767
filter(() => {

src/testutils/assert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const isWithinOne = (a: number, b: number) =>
1+
export const isWithinOne = (a: number, b: number): void =>
22
chai.assert(Math.abs(a - b) < 1, `expected the difference between ${a} and ${b} to be less than 1`)

src/testutils/dom.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class DOM {
191191

192192
/**
193193
* Creates and inserts the generated test cases into the DOM
194+
*
194195
* @returns the CodeViewProps for the test cases added to the DOM.
195196
*/
196197
public createCodeViews(): CodeViewProps[] {
@@ -205,6 +206,7 @@ export class DOM {
205206

206207
/**
207208
* Creates a div with some arbitrary content.
209+
*
208210
* @param html the content of the element you wish to create.
209211
* @returns the created div.
210212
*/

0 commit comments

Comments
 (0)