Skip to content

Commit 3f1dece

Browse files
authored
chore: add type-powered eslint rules (#62)
1 parent 0becdaa commit 3f1dece

18 files changed

+160
-351
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dist
22
coverage
33
package-lock.json
44
tests/tmp
5+
src/common/atlas/openapi.d.ts

.prettierrc.json

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"singleQuote": false,
66
"printWidth": 120,
77
"overrides": [
8+
{
9+
"files": "*.ts",
10+
"options": {
11+
"insertPragma": false,
12+
"proseWrap": "preserve"
13+
}
14+
},
815
{
916
"files": "*.json",
1017
"options": {

eslint.config.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,31 @@ import globals from "globals";
44
import tseslint from "typescript-eslint";
55
import eslintConfigPrettier from "eslint-config-prettier/flat";
66

7+
const files = ["src/**/*.ts", "scripts/**/*.ts", "tests/**/*.test.ts", "eslint.config.js", "jest.config.js"];
8+
79
export default defineConfig([
8-
{ files: ["src/**/*.ts"], plugins: { js }, extends: ["js/recommended"] },
9-
{ files: ["src/**/*.ts"], languageOptions: { globals: globals.node } },
10-
tseslint.configs.recommended,
10+
{ files, plugins: { js }, extends: ["js/recommended"] },
11+
{ files, languageOptions: { globals: globals.node } },
12+
tseslint.configs.recommendedTypeChecked,
13+
{
14+
languageOptions: {
15+
parserOptions: {
16+
projectService: true,
17+
tsconfigRootDir: import.meta.dirname,
18+
},
19+
},
20+
},
21+
{
22+
files,
23+
rules: {
24+
"@typescript-eslint/switch-exhaustiveness-check": "error",
25+
},
26+
},
27+
// Ignore features specific to TypeScript resolved rules
28+
tseslint.config({
29+
// TODO: Configure tests and scripts to work with this.
30+
ignores: ["eslint.config.js", "jest.config.js", "tests/**/*.ts", "scripts/**/*.ts"],
31+
}),
32+
globalIgnores(["node_modules", "dist", "src/common/atlas/openapi.d.ts"]),
1133
eslintConfigPrettier,
12-
globalIgnores(["node_modules", "dist"]),
1334
]);

package-lock.json

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
"prepare": "npm run build",
2020
"build:clean": "rm -rf dist",
2121
"build:compile": "tsc",
22-
"build:addshebang": "echo '#!/usr/bin/env node' > dist/index2.js && cat dist/index.js >> dist/index2.js && mv dist/index2.js dist/index.js",
2322
"build:chmod": "chmod +x dist/index.js",
24-
"build": "npm run build:clean && npm run build:compile && npm run build:addshebang && npm run build:chmod",
23+
"build": "npm run build:clean && npm run build:compile && npm run build:chmod",
2524
"inspect": "npm run build && mcp-inspector -- dist/index.js",
2625
"prettier": "prettier",
2726
"check": "npm run build && npm run check:lint && npm run check:format",
@@ -38,6 +37,7 @@
3837
"@modelcontextprotocol/inspector": "^0.8.2",
3938
"@modelcontextprotocol/sdk": "^1.8.0",
4039
"@redocly/cli": "^1.34.2",
40+
"@types/express": "^5.0.1",
4141
"@types/jest": "^29.5.14",
4242
"@types/node": "^22.14.0",
4343
"@types/simple-oauth2": "^5.0.7",
@@ -60,7 +60,6 @@
6060
"dependencies": {
6161
"@mongodb-js/devtools-connect": "^3.7.2",
6262
"@mongosh/service-provider-node-driver": "^3.6.0",
63-
"@types/express": "^5.0.1",
6463
"bson": "^6.10.3",
6564
"mongodb": "^6.15.0",
6665
"mongodb-log-writer": "^2.4.1",

src/common/atlas/apiClient.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export class ApiClient {
112112
this.client.use(this.errorMiddleware());
113113
}
114114

115-
async getIpInfo() {
115+
public async getIpInfo(): Promise<{
116+
currentIpv4Address: string;
117+
}> {
116118
const accessToken = await this.getAccessToken();
117119

118120
const endpoint = "api/private/ipinfo";
@@ -130,10 +132,9 @@ export class ApiClient {
130132
throw await ApiClientError.fromResponse(response);
131133
}
132134

133-
const responseBody = await response.json();
134-
return responseBody as {
135+
return (await response.json()) as Promise<{
135136
currentIpv4Address: string;
136-
};
137+
}>;
137138
}
138139

139140
async listProjects(options?: FetchOptions<operations["listProjects"]>) {

0 commit comments

Comments
 (0)