Skip to content

Commit

Permalink
chore: check for lint errors on PR, fail on unused variables (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm authored Feb 5, 2024
2 parents f40e93c + 5d0dbf0 commit 4e5aa13
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 58 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ module.exports = {
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'jsdoc/tag-lines': 'off', // not documented on jsdoc plugin site, unsure how to correct.
"@typescript-eslint/no-unused-vars": ["error", { "args": "all", "argsIgnorePattern": "^_" }],
},
};
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
git diff --cached --quiet
- name: Check Formatting
run: yarn prettier:check
- name: Linting
run: yarn lint
- name: Build
run: yarn build
- name: Run tests
Expand Down
1 change: 0 additions & 1 deletion src/api/documents/v0/collection-group-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { DocumentServiceClient } from '@nitric/api/proto/document/v1/document_grpc_pb';
import { InvalidArgumentError } from '../../errors';
import { CollectionRef } from './collection-ref';
import { MAX_COLLECTION_DEPTH } from './constants';
import { DocumentRef, DocumentStructure } from './document-ref';
Expand Down
2 changes: 1 addition & 1 deletion src/api/documents/v0/document-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
DocumentDeleteRequest,
} from '@nitric/api/proto/document/v1/document_pb';
import { DocumentServiceClient } from '@nitric/api/proto/document/v1/document_grpc_pb';
import { fromGrpcError, InvalidArgumentError } from '../../errors';
import { fromGrpcError } from '../../errors';
import { CollectionRef } from './collection-ref';
import { MAX_COLLECTION_DEPTH } from './constants';

Expand Down
4 changes: 3 additions & 1 deletion src/api/documents/v0/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class Documents {
* @param name The name of the collection (required)
* @returns The Collection instance
*/
public collection<T extends DocumentStructure>(name: string) {
public collection<T extends DocumentStructure>(
name: string
): CollectionRef<T> {
return new CollectionRef<T>(this.documentClient, name);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/api/documents/v0/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { Map as ProtobufMap } from 'google-protobuf';
import { DocumentRef, DocumentStructure } from './document-ref';
import { CollectionRef } from './collection-ref';
import { DocumentSnapshot } from './document-snapshot';
import { fromGrpcError, InvalidArgumentError } from '../../errors';
import { fromGrpcError } from '../../errors';
import { ServiceError } from '@grpc/grpc-js';

type PagingToken = Map<string, string>;
Expand Down Expand Up @@ -146,7 +146,7 @@ export class Query<T extends DocumentStructure> {
return this;
}

public async fetch() {
public async fetch(): Promise<FetchResponse<T>> {
const request = new DocumentQueryRequest();

request.setCollection(this.collection['toWire']());
Expand Down Expand Up @@ -203,7 +203,7 @@ export class Query<T extends DocumentStructure> {
});
}

protected getStreamRequest() {
protected getStreamRequest(): DocumentQueryStreamRequest {
const request = new DocumentQueryStreamRequest();

request.setCollection(this.collection['toWire']());
Expand Down Expand Up @@ -247,7 +247,7 @@ export class Query<T extends DocumentStructure> {

const transform = new Transform({
objectMode: true,
transform: (result: DocumentQueryStreamResponse, encoding, callback) => {
transform: (result: DocumentQueryStreamResponse, _encoding, callback) => {
const doc = result.getDocument();

callback(
Expand Down
5 changes: 1 addition & 4 deletions src/api/errors/cancelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {
ErrorDetails,
ErrorScope,
} from '@nitric/sdk/gen/proto/error/v1/error_pb';
import { ErrorDetails } from '@nitric/sdk/gen/proto/error/v1/error_pb';
import { NitricPluginError } from './plugin-error';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/events/v0/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { Struct } from 'google-protobuf/google/protobuf/struct_pb';
import * as grpc from '@grpc/grpc-js';
import { NitricEvent } from '../../../types';
import { fromGrpcError, InvalidArgumentError } from '../../errors';
import { fromGrpcError } from '../../errors';

/**
* Construct event and topic service clients.
Expand Down
7 changes: 1 addition & 6 deletions src/api/queues/v0/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import { QueueServiceClient } from '@nitric/api/proto/queue/v1/queue_grpc_pb';
import {
NitricTask as NitricTaskPb,
QueueSendRequest,
QueueSendBatchRequest,
QueueReceiveRequest,
QueueCompleteRequest,
Expand All @@ -23,11 +22,7 @@ import { SERVICE_BIND } from '../../../constants';
import * as grpc from '@grpc/grpc-js';
import { NitricTask } from '../../../types';
import { Struct } from 'google-protobuf/google/protobuf/struct_pb';
import {
fromGrpcError,
InvalidArgumentError,
InternalError,
} from '../../errors';
import { fromGrpcError } from '../../errors';

/**
* A message that has failed to be enqueued
Expand Down
2 changes: 1 addition & 1 deletion src/api/secrets/v0/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
Secret as GrpcSecret,
} from '@nitric/api/proto/secret/v1/secret_pb';
import * as grpc from '@grpc/grpc-js';
import { fromGrpcError, InvalidArgumentError } from '../../errors';
import { fromGrpcError } from '../../errors';

const ENCODER = new TextEncoder();
const DECODER = new TextDecoder();
Expand Down
10 changes: 3 additions & 7 deletions src/api/storage/v0/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ import {
StorageExistsRequest,
} from '@nitric/api/proto/storage/v1/storage_pb';
import * as grpc from '@grpc/grpc-js';
import { fromGrpcError, InvalidArgumentError } from '../../errors';
import { fromGrpcError } from '../../errors';
import { FileNotificationMiddleware } from '@nitric/sdk/faas';
import {
BucketNotificationMiddleware,
FileNotificationMiddleware,
} from '@nitric/sdk/faas';
import {
BucketNotification,
BucketNotificationType,
FileNotification,
} from '@nitric/sdk/resources';
Expand Down Expand Up @@ -97,7 +93,7 @@ export class Bucket {
});
}

public file(name: string) {
public file(name: string): File {
if (!name) {
throw new Error('A file name/path is required to use a File.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/websocket/v0/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Websocket {
sendRequest.setData(payload);

return new Promise((res, rej) => {
this.client.send(sendRequest, (error, data) => {
this.client.send(sendRequest, (error, _data) => {
if (error) {
rej(fromGrpcError(error));
}
Expand Down
11 changes: 6 additions & 5 deletions src/faas/v0/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
BucketNotificationWorkerOptions,
FileNotificationWorkerOptions,
SubscriptionWorkerOptions,
bucket,
} from '@nitric/sdk';
import { FaasWorkerOptions } from './start';

Expand Down Expand Up @@ -244,7 +243,9 @@ export class HttpResponse {
*
* @returns HttpContext with body property set with an encoded JSON string and json headers set.
*/
get json() {
get json(): (
data: string | number | boolean | Record<string, any>
) => HttpContext {
return jsonResponse(this.ctx);
}
}
Expand Down Expand Up @@ -288,7 +289,7 @@ export class HttpContext extends TriggerContext<HttpRequest, HttpResponse> {

static fromGrpcTriggerRequest(
trigger: TriggerRequest,
options?: ApiWorkerOptions
_options?: ApiWorkerOptions
): HttpContext {
const http = trigger.getHttp();
const ctx = new HttpContext();
Expand Down Expand Up @@ -443,7 +444,7 @@ export class EventContext<T> extends TriggerContext<

static fromGrpcTriggerRequest(
trigger: TriggerRequest,
options?: SubscriptionWorkerOptions
_options?: SubscriptionWorkerOptions
): EventContext<unknown> {
const topic = trigger.getTopic();
const ctx = new EventContext();
Expand Down Expand Up @@ -482,7 +483,7 @@ export class BucketNotificationContext extends TriggerContext<

static fromGrpcTriggerRequest(
trigger: TriggerRequest,
options?: BucketNotificationWorkerOptions
_options?: BucketNotificationWorkerOptions
): BucketNotificationContext {
const ctx = new BucketNotificationContext();
const bucketConfig = trigger.getNotification().getBucket();
Expand Down
2 changes: 1 addition & 1 deletion src/faas/v0/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const json = (): HttpMiddleware => (ctx: HttpContext, next) => {
*/
export const jsonResponse =
(ctx: HttpContext) =>
(data: string | number | boolean | Record<string, any>) => {
(data: string | number | boolean | Record<string, any>): HttpContext => {
ctx.res.body = new TextEncoder().encode(JSON.stringify(data));
ctx.res.headers['Content-Type'] = ['application/json'];

Expand Down
1 change: 0 additions & 1 deletion src/faas/v0/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
HttpWorker,
WebsocketResponseContext,
WebsocketWorker,
WebsocketEvent,
} from '@nitric/api/proto/faas/v1/faas_pb';

import {
Expand Down
1 change: 0 additions & 1 deletion src/faas/v0/traceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import {
ConsoleSpanExporter,
BatchSpanProcessor,
NodeTracerProvider,
NoopSpanProcessor,
Expand Down
11 changes: 7 additions & 4 deletions src/resources/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ResourceDeclareResponse,
ResourceDetailsResponse,
ResourceType,
ResourceTypeMap,
} from '@nitric/api/proto/resource/v1/resource_pb';
import resourceClient from './client';
import { storage, Bucket } from '../api/storage';
Expand Down Expand Up @@ -84,7 +85,7 @@ export class BucketNotification {
constructor(
bucket: string,
notificationType: BucketNotificationType,
notificationPrefixFilter,
notificationPrefixFilter: string,
...middleware: BucketNotificationMiddleware[]
) {
this.faas = new Faas(
Expand All @@ -108,7 +109,7 @@ export class FileNotification {
constructor(
bucket: Bucket,
notificationType: BucketNotificationType,
notificationPrefixFilter,
notificationPrefixFilter: string,
...middleware: FileNotificationMiddleware[]
) {
this.faas = new Faas(
Expand Down Expand Up @@ -195,10 +196,11 @@ export class BucketResource extends SecureResource<BucketPermission> {
}, []);
}

protected resourceType() {
protected resourceType(): ResourceTypeMap[keyof ResourceTypeMap] {
return ResourceType.BUCKET;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected unwrapDetails(resp: ResourceDetailsResponse): never {
throw new Error('details unimplemented for bucket');
}
Expand All @@ -208,7 +210,8 @@ export class BucketResource extends SecureResource<BucketPermission> {
*
* e.g. const imgs = resources.bucket('image').for('writing')
*
* @param perms the required permission set
* @param perm the access that the currently scoped function is requesting to this resource.
* @param perms additional access that the currently scoped function is requesting to this resource.
* @returns a usable bucket reference
*/
public for(perm: BucketPermission, ...perms: BucketPermission[]): Bucket {
Expand Down
20 changes: 15 additions & 5 deletions src/resources/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ import {
ResourceType,
Action,
ResourceDetailsResponse,
ResourceTypeMap,
ActionMap,
} from '@nitric/api/proto/resource/v1/resource_pb';
import { fromGrpcError } from '../api/errors';
import { documents } from '../api/documents';
import resourceClient from './client';
import { make, SecureResource } from './common';
import { DocumentStructure } from '../api/documents/v0/document-ref';
import { CollectionRef } from '../api/documents/v0/collection-ref';

type CollectionPermission = 'reading' | 'writing' | 'deleting';

Expand Down Expand Up @@ -51,7 +54,7 @@ export class CollectionResource<
return new Promise<Resource>((resolve, reject) => {
resourceClient.declare(
req,
(error, response: ResourceDeclareResponse) => {
(error, _response: ResourceDeclareResponse) => {
if (error) {
reject(fromGrpcError(error));
} else {
Expand All @@ -62,7 +65,9 @@ export class CollectionResource<
});
}

protected permsToActions(...perms: CollectionPermission[]) {
protected permsToActions(
...perms: CollectionPermission[]
): ActionMap[keyof ActionMap][] {
let actions = perms.reduce((actions, perm) => {
switch (perm) {
case 'reading':
Expand Down Expand Up @@ -91,10 +96,11 @@ export class CollectionResource<
return actions;
}

protected resourceType() {
protected resourceType(): ResourceTypeMap[keyof ResourceTypeMap] {
return ResourceType.COLLECTION;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected unwrapDetails(resp: ResourceDetailsResponse): never {
throw new Error('details unimplemented for collection');
}
Expand All @@ -104,10 +110,14 @@ export class CollectionResource<
*
* e.g. const customers = resources.collection('customers').for('reading', 'writing')
*
* @param perms the required permission set
* @param perm the access that the currently scoped function is requesting to this resource.
* @param perms additional access that the currently scoped function is requesting to this resource.
* @returns a usable collection reference
*/
public for(perm: CollectionPermission, ...perms: CollectionPermission[]) {
public for(
perm: CollectionPermission,
...perms: CollectionPermission[]
): CollectionRef<T> {
this.registerPolicy(perm, ...perms);

return documents().collection<T>(this.name);
Expand Down
2 changes: 1 addition & 1 deletion src/resources/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class HttpWorker {
export const http = (
app: NodeApplication | ListenerFunction,
callback?: () => void
) => {
): void => {
const unknownApp = app as any;

const nodeApp =
Expand Down
8 changes: 5 additions & 3 deletions src/resources/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ResourceType,
Action,
ResourceDeclareResponse,
ResourceTypeMap,
} from '@nitric/api/proto/resource/v1/resource_pb';
import resourceClient from './client';
import { queues, Queue } from '../api/';
Expand Down Expand Up @@ -76,11 +77,11 @@ export class QueueResource<
return actions;
}

protected resourceType() {
protected resourceType(): ResourceTypeMap[keyof ResourceTypeMap] {
return ResourceType.QUEUE;
}

protected unwrapDetails(resp: ResourceDeclareResponse): never {
protected unwrapDetails(_resp: ResourceDeclareResponse): never {
throw new Error('details unimplemented for queue');
}

Expand All @@ -89,7 +90,8 @@ export class QueueResource<
*
* e.g. const taskQueue = resources.queue('work').for('sending')
*
* @param perms the access that the currently scoped function is requesting to this resource.
* @param perm the access that the currently scoped function is requesting to this resource.
* @param perms additional access that the currently scoped function is requesting to this resource.
* @returns a useable queue.
*/
public for(perm: QueuePermission, ...perms: QueuePermission[]): Queue<T> {
Expand Down
Loading

0 comments on commit 4e5aa13

Please sign in to comment.