Skip to content

Commit 828061e

Browse files
committed
fix: linter issues
1 parent bde95b7 commit 828061e

12 files changed

+72
-36
lines changed

.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,9 @@
5151
"files": ["*.mjs"],
5252
"parserOptions": {"sourceType": "module"}
5353

54+
},{
55+
"files": ["*.ts"],
56+
"parserOptions": {"sourceType": "module"}
57+
5458
}]
5559
}

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"mocha-sinon": "^2.1.0",
6363
"mongodb-mock-server": "^2.0.1",
6464
"nyc": "^15.1.0",
65-
"prettier": "^2.0.5",
65+
"prettier": "2.1.1",
6666
"rimraf": "^3.0.2",
6767
"semver": "^5.5.0",
6868
"sinon": "^4.3.0",

src/gridfs-stream/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { GridFSBucketWriteStream, GridFSBucketWriteStreamOptions, GridFSChunk } from './upload';
1010
import { executeLegacyOperation, Callback, getTopology } from '../utils';
1111
import { WriteConcernOptions, WriteConcern } from '../write_concern';
12-
import type { Document, ObjectId } from '../bson';
12+
import type { ObjectId } from '../bson';
1313
import type { Db } from '../db';
1414
import type { ReadPreference } from '../read_preference';
1515
import type { Collection } from '../collection';

src/mongo_types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ export type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & { _id: InferIdType<
2525
* `TSchema['_id'] extends ObjectId` which translated to "Is the _id property ObjectId?"
2626
* we instead ask "Does ObjectId look like (have the same shape) as the _id?"
2727
*/
28-
export type OptionalId<TSchema extends { _id?: any }> = ObjectId extends TSchema['_id']
29-
? // a Schema with ObjectId _id type or "any" or "indexed type" provided
30-
EnhancedOmit<TSchema, '_id'> & { _id?: InferIdType<TSchema> }
31-
: // a Schema provided but _id type is not ObjectId
32-
WithId<TSchema>;
28+
export type OptionalId<TSchema extends { _id?: any }> = ObjectId extends TSchema['_id'] // a Schema with ObjectId _id type or "any" or "indexed type" provided
29+
? EnhancedOmit<TSchema, '_id'> & { _id?: InferIdType<TSchema> } // a Schema provided but _id type is not ObjectId
30+
: WithId<TSchema>;
3331

3432
/** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
3533
export type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion
@@ -45,6 +43,7 @@ export type WithoutId<TSchema> = Omit<TSchema, '_id'>;
4543
export type Query<TSchema> = Partial<TSchema> & Document;
4644

4745
/** A MongoDB UpdateQuery is set of operators @public */
46+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4847
export type UpdateQuery<TSchema> = Document; // TODO
4948

5049
/** @see https://docs.mongodb.com/manual/reference/operator/aggregation/meta/#proj._S_meta @public */

test/types/.eslintrc.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 2018
5+
},
6+
"plugins": [
7+
"@typescript-eslint",
8+
"prettier",
9+
"eslint-plugin-tsdoc"
10+
],
11+
"extends": [
12+
"eslint:recommended",
13+
"plugin:@typescript-eslint/eslint-recommended",
14+
"plugin:@typescript-eslint/recommended",
15+
"prettier/@typescript-eslint",
16+
"plugin:prettier/recommended"
17+
],
18+
"env": {
19+
"node": true,
20+
"mocha": false,
21+
"es6": true
22+
},
23+
"rules": {
24+
"prettier/prettier": "error",
25+
"tsdoc/syntax": "warn",
26+
"typescript-eslint/no-explicit-any": "off"
27+
}
28+
}

test/types/distinct.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ const db = new Db(new MongoClient(''), '');
88
const collection = db.collection<Movie>('');
99

1010
// Ensure distinct takes all keys of the schema plus '_id'
11-
let x = (null as unknown) as Parameters<typeof collection.distinct>[0];
11+
const x = (null as unknown) as Parameters<typeof collection.distinct>[0];
1212
expectType<'_id' | keyof Movie>(x);

test/types/indexed_schema.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const randomKeysIncludeIdC = new Collection<RandomKeysToNumberIncludingId>(db, '
1818
expectType<InsertRes<number>>(randomKeysIncludeIdC.insertOne({ a: 2, randomKey: 23, _id: 23 }));
1919
expectError(randomKeysIncludeIdC.insertOne({ a: 2, randomKey: 23 }));
2020

21-
let arg1: Parameters<typeof randomKeysIncludeIdC.findOne>[0] = null as any;
21+
const arg1 = (null as unknown) as Parameters<typeof randomKeysIncludeIdC.findOne>[0];
2222
expectAssignable<Partial<RandomKeysToNumberIncludingId>>(arg1);
2323

2424
////////////////////////////////////////////////////////////////////////////////////////////////////

test/types/mongodb.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectDeprecated, expectType, expectNotType, expectError, expectAssignable } from 'tsd';
1+
import { expectDeprecated, expectType } from 'tsd';
22

33
import { Collection } from '../../src//collection';
44
import { AggregationCursor } from '../../src//cursor/aggregation_cursor';

test/types/union_schema.test-d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectType, expectError, expectNotType } from 'tsd';
1+
import { expectType, expectError, expectNotType, expectNotAssignable } from 'tsd';
22

33
import { Collection } from '../../src/collection';
44
import { ObjectId } from '../../src/bson';
@@ -21,7 +21,8 @@ interface Rectangle {
2121
type Shape = Circle | Rectangle;
2222

2323
type c = Collection<Shape>;
24-
type i = Parameters<c['insertOne']>[0];
24+
// should not insert a portion of a type
25+
expectNotAssignable<Parameters<c['insertOne']>[0]>({ height: 2 });
2526

2627
const shapesC = new Collection<Shape>(db, '');
2728
expectType<InsertRes>(shapesC.insertOne({ radius: 4 }));

test/unit/type_check.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const tsd = require('tsd');
4+
const { expect } = require('chai');
5+
6+
describe('Exported Types', () => {
7+
it('should be as expected', async () => {
8+
const diagnostics = await tsd();
9+
if (diagnostics.length !== 0) {
10+
const messages = diagnostics
11+
.map(d => `${d.fileName}:${d.line}:${d.column} - [${d.severity}]: ${d.message}`)
12+
.join('\n');
13+
expect.fail('\n' + messages);
14+
}
15+
});
16+
});

test/unit/type_check.test.ts

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

0 commit comments

Comments
 (0)