Skip to content

Commit 7774067

Browse files
committed
Setup eslint
Enabled default rules plus `require-await` to catch any promises that are left un-awaited.
1 parent c6fd6cc commit 7774067

11 files changed

+1218
-501
lines changed

eslint.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import globals from 'globals';
2+
import pluginJs from '@eslint/js';
3+
import tseslint from 'typescript-eslint';
4+
5+
/** @type {import('eslint').Linter.FlatConfig[]} */
6+
const config = [
7+
{ files: ['src/**/*.ts'], ignores: ['build/**/*'] },
8+
{ languageOptions: { globals: globals.node } },
9+
{ rules: { 'require-await': 'error' } },
10+
pluginJs.configs.recommended,
11+
...tseslint.configs.recommended,
12+
];
13+
14+
export default config;

package-lock.json

Lines changed: 1162 additions & 468 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@
3636
},
3737
"scripts": {
3838
"clean": "rimraf './build'",
39+
"lint": "cross-env ./node_modules/.bin/eslint src scripts",
3940
"build": "npm run clean && node ./scripts/build.mjs",
4041
"build:dev": "npm run build -- --watch",
4142
"build:publish": "npm run build -- --prod",
4243
"test": "cross-env ./node_modules/.bin/tsc && cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" ./node_modules/.bin/jest",
4344
"previewTheme": "nodemon -q build/previewTheme.mjs",
4445
"benchmark": "npm run build && node build/benchmark.mjs",
45-
"prepublishOnly": "npm run build:publish && npm run test"
46+
"prepublishOnly": "npm run lint && npm run build:publish && npm run test"
4647
},
4748
"devDependencies": {
49+
"@eslint/js": "^9.6.0",
4850
"@types/benchmark": "^2.1.0",
4951
"@types/diff": "^5.0.0",
5052
"@types/jest": "^29.5.1",
@@ -53,12 +55,15 @@
5355
"benchmark": "^2.1.4",
5456
"cross-env": "^7.0.3",
5557
"esbuild": "^0.17.18",
58+
"eslint": "^9.6.0",
59+
"globals": "^15.8.0",
5660
"jest": "^29.7.0",
5761
"nodemon": "^2.0.7",
5862
"prettier": "^2.2.1",
5963
"rimraf": "^5.0.5",
6064
"ts-jest": "^29.1.0",
61-
"typescript": "^5.0.4"
65+
"typescript": "^5.0.4",
66+
"typescript-eslint": "^7.15.0"
6267
},
6368
"packageManager": "npm@9.8.1"
6469
}

src/__snapshots__/index.test.ts.snap

Lines changed: 16 additions & 16 deletions
Large diffs are not rendered by default.

src/getGitConfig.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const DEFAULT_THEME_NAME = 'dark';
1111

1212
const GIT_CONFIG_KEY_PREFIX = 'split-diffs';
1313
const GIT_CONFIG_LINE_REGEX = new RegExp(
14-
`${GIT_CONFIG_KEY_PREFIX}\.([^=]+)=(.*)`
14+
`${GIT_CONFIG_KEY_PREFIX}\\.([^=]+)=(.*)`
1515
);
1616

1717
function extractFromGitConfigString(configString: string) {
@@ -36,7 +36,9 @@ export function getGitConfig(configString: string): GitConfig {
3636
if (!isNaN(parsedMinLineWidth)) {
3737
minLineWidth = parsedMinLineWidth;
3838
}
39-
} catch {}
39+
} catch {
40+
// Ignore invalid values
41+
}
4042

4143
return {
4244
MIN_LINE_WIDTH: minLineWidth,

src/index.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const TEST_THEME = Object.fromEntries(
1010
) as Theme;
1111

1212
const replaceColoredText =
13+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1314
(r: number, g: number, b: number) => (text: string) =>
1415
text.replace(/./g, '░');
1516

@@ -164,7 +165,7 @@ index 9f14e96..eaf3730 100644
164165
).toMatchSnapshot();
165166
});
166167

167-
test('commit with deletion', async function () {
168+
test('commit with deletion', function () {
168169
expect(`commit eccfb5a2b3d76ba53df315f977da74b18d50113e
169170
Author: Shrey Banga <shrey@quip.com>
170171
Date: Thu Aug 22 10:07:25 2019 -0700
@@ -316,7 +317,7 @@ index 0000000..6499edf
316317
@@ -0,0 +1,2 @@
317318
+node_modules/**
318319
+build/**
319-
\ No newline at end of file`)
320+
\\ No newline at end of file`)
320321
).toMatchSnapshot();
321322
});
322323

@@ -380,7 +381,7 @@ index ca15c64..0000000
380381
- end tell
381382
- end timeout
382383
-end run
383-
\ No newline at end of file`)
384+
\\ No newline at end of file`)
384385
).toMatchSnapshot();
385386
});
386387

@@ -465,7 +466,7 @@ index d88c464..6901818 100644
465466
+++ b/file1
466467
@@ -1 +1,2 @@
467468
-This is file1
468-
\ No newline at end of file
469+
\\ No newline at end of file
469470
+This is file1
470471
+Experimental change
471472
diff --git a/file2 b/file2

src/iterFormatHunkUnified.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export async function* iterFormatUnifiedDiffHunkUnified(
1414
): AsyncIterable<FormattedString> {
1515
const lineWidth = context.SCREEN_WIDTH;
1616

17-
let [
18-
{ fileName: fileNameA, lines: hunkLinesA, startLineNo: lineNoA },
19-
{ fileName: fileNameB, lines: hunkLinesB, startLineNo: lineNoB },
17+
const [
18+
{ fileName: fileNameA, lines: hunkLinesA },
19+
{ fileName: fileNameB, lines: hunkLinesB },
2020
] = hunkParts;
21+
let [{ startLineNo: lineNoA }, { startLineNo: lineNoB }] = hunkParts;
2122

2223
let indexA = 0,
2324
indexB = 0;
@@ -108,7 +109,7 @@ export async function* iterFormatCombinedDiffHunkUnified(
108109

109110
// The final hunk part shows the current state of the file, so we just
110111
// display that with additions and deletions highlighted.
111-
let { fileName, lines, startLineNo } = hunkParts[hunkParts.length - 1];
112+
const { fileName, lines, startLineNo } = hunkParts[hunkParts.length - 1];
112113
let lineNo = startLineNo;
113114
let numDeletes = 0;
114115

src/themes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function hexToRgba(hex: string): ColorRgba {
8282
hex = hex.slice(1);
8383

8484
let hexNo = parseInt(hex, 16);
85-
let bits = hex.length === 3 ? 4 : 8;
85+
const bits = hex.length === 3 ? 4 : 8;
8686

8787
let a = 255;
8888
if (hex.length === 8) {

src/transformContentsStreaming.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { iterReplaceTabsWithSpaces } from './iterReplaceTabsWithSpaces';
55
import { iterSideBySideDiffs } from './iterSideBySideDiffs';
66
import { iterWithNewlines } from './iterWithNewlines';
77

8-
export async function transformContentsStreaming(
8+
export function transformContentsStreaming(
99
context: Context,
1010
input: Readable,
1111
output: Writable

src/zip.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function* zip<T extends Array<any>>(
1+
export function* zip<T extends Array<unknown>>(
22
...iterables: { [K in keyof T]: Iterable<T[K]> }
33
): Iterable<{ [K in keyof T]: T[K] | undefined }> {
44
const iterators = iterables.map((iterable) => iterable[Symbol.iterator]());
@@ -18,7 +18,7 @@ export function* zip<T extends Array<any>>(
1818
}
1919
}
2020

21-
export async function* zipAsync<T extends Array<any>>(
21+
export async function* zipAsync<T extends Array<unknown>>(
2222
...iterables: { [K in keyof T]: AsyncIterable<T[K]> }
2323
): AsyncIterable<{ [K in keyof T]: T[K] | undefined }> {
2424
const iterators = iterables.map((iterable) =>

todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141
- [ ] Support custom themes
4242
- [x] Calculate correct display widths, e.g. https://github.com/microsoft/MS-DOS/commit/29a0f9c130b6883080046b830e27403a289de72d
4343
- [ ] Add a theme without background colors
44-
- [ ] Add eslint rule to check for async/await gotchas
44+
- [x] Add eslint rule to check for async/await gotchas

0 commit comments

Comments
 (0)