diff --git a/.eslintignore b/.eslintignore index 09b31fe..a4ac7b3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,5 @@ **/node_modules -src/**/doc/* +**/.coverage build/ docs/ protos/ diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..7821534 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 73eeec2..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -extends: - - 'eslint:recommended' - - 'plugin:node/recommended' - - prettier -plugins: - - node - - prettier -rules: - prettier/prettier: error - block-scoped-var: error - eqeqeq: error - no-warning-comments: warn - no-var: error - prefer-const: error diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c5cbc55..e8f5ba6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [8, 10, 12, 13] + node: [10, 12, 13] steps: - uses: actions/checkout@v1 - uses: actions/setup-node@v1 diff --git a/.prettierignore b/.prettierignore index f6fac98..a4ac7b3 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,5 @@ -node_modules/* -samples/node_modules/* -src/**/doc/* +**/node_modules +**/.coverage +build/ +docs/ +protos/ diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index df6eac0..0000000 --- a/.prettierrc +++ /dev/null @@ -1,8 +0,0 @@ ---- -bracketSpacing: false -printWidth: 80 -semi: true -singleQuote: true -tabWidth: 2 -trailingComma: es5 -useTabs: false diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..08cba37 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,17 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +module.exports = { + ...require('gts/.prettierrc.json') +} diff --git a/package.json b/package.json index 52fedd2..8dc51d2 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,12 @@ "repository": "googleapis/nodejs-paginator", "scripts": { "test": "c8 mocha build/test", - "lint": "gts check", - "clean": "gts clean", "compile": "tsc -p .", "fix": "gts fix", + "prelint": "cd samples; npm link ../; npm i", + "lint": "gts check", "prepare": "npm run compile", "pretest": "npm run compile", - "posttest": "npm run lint", "docs": "compodoc src/", "presystem-test": "npm run compile", "samples-test": "cd samples/ && npm link ../ && npm test && cd ../", @@ -36,11 +35,11 @@ "@types/proxyquire": "^1.3.28", "@types/sinon": "^7.0.0", "@types/uuid": "^7.0.0", + "c8": "^7.0.0", "codecov": "^3.0.4", - "gts": "^1.0.0", + "gts": "2.0.0-alpha.4", "linkinator": "^2.0.0", - "mocha": "^7.0.0", - "c8": "^7.0.0", + "mocha": "^7.1.1", "proxyquire": "^2.0.1", "sinon": "^9.0.0", "typescript": "^3.8.3", diff --git a/samples/package.json b/samples/package.json index 89e298a..5ff0f2f 100644 --- a/samples/package.json +++ b/samples/package.json @@ -3,7 +3,7 @@ "license": "Apache-2.0", "author": "Google LLC", "engines": { - "node": ">=8" + "node": ">=10" }, "repository": "googleapis/nodejs-paginator", "private": true, diff --git a/src/index.ts b/src/index.ts index 1c300f2..bc7adbc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -91,7 +91,7 @@ export class Paginator { Class.prototype[methodName + '_'] = originalMethod; // overwrite the original to auto-paginate - // tslint:disable-next-line:no-any + /* eslint-disable @typescript-eslint/no-explicit-any */ Class.prototype[methodName] = function(...args: any[]) { const parsedArguments = paginator.parseArguments_(args); return paginator.run_(parsedArguments, originalMethod.bind(this)); @@ -111,12 +111,12 @@ export class Paginator { * @param {string} methodName - Name of the method to streamify. * @return {function} - Wrapped function. */ - // tslint:disable-next-line:no-any + /* eslint-disable @typescript-eslint/no-explicit-any */ streamify(methodName: string) { return function( // tslint:disable-next-line:no-any this: {[index: string]: Function}, - // tslint:disable-next-line:no-any + /* eslint-disable @typescript-eslint/no-explicit-any */ ...args: any[] ): ResourceStream { const parsedArguments = paginator.parseArguments_(args); @@ -134,7 +134,7 @@ export class Paginator { * @param {array} args - The original `arguments` pseduo-array that the original * method received. */ - // tslint:disable-next-line:no-any + /* eslint-disable @typescript-eslint/no-explicit-any */ parseArguments_(args: any[]) { let query: string | ParsedArguments | undefined; let autoPaginate = true; @@ -255,7 +255,7 @@ export class Paginator { * and returns `nextQuery` to receive more results. * @return {stream} - Readable object stream. */ - // tslint:disable-next-line:no-any + /* eslint-disable @typescript-eslint/no-explicit-any */ runAsStream_( parsedArguments: ParsedArguments, originalMethod: Function diff --git a/src/resource-stream.ts b/src/resource-stream.ts index a2249f4..77ee762 100644 --- a/src/resource-stream.ts +++ b/src/resource-stream.ts @@ -47,7 +47,7 @@ export class ResourceStream extends Transform implements ResourceEvents { this._requestsMade = 0; this._resultsToSend = args.maxResults === -1 ? Infinity : args.maxResults!; } - // tslint:disable-next-line:no-any + /* eslint-disable @typescript-eslint/no-explicit-any */ end(...args: any[]) { this._ended = true; return super.end(...args); diff --git a/test/index.ts b/test/index.ts index ff66e7f..b09d844 100644 --- a/test/index.ts +++ b/test/index.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach, afterEach} from 'mocha'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; import {PassThrough, Transform} from 'stream'; @@ -22,13 +22,16 @@ import * as P from '../src'; import {paginator, ParsedArguments} from '../src'; const util = { - noop: () => {}, + noop: () => { + // do nothing + }, }; class FakeResourceStream extends Transform { calledWith: IArguments; constructor() { super({objectMode: true}); + /* eslint-disable-next-line prefer-rest-params */ this.calledWith = arguments; } } @@ -39,18 +42,21 @@ const p = proxyquire('../src', { const sandbox = sinon.createSandbox(); +// eslint-disable-next-line no-undef afterEach(() => { sandbox.restore(); }); -// tslint:disable-next-line no-any +/* eslint-disable @typescript-eslint/no-explicit-any */ function createFakeStream() { return new PassThrough({objectMode: true}) as P.ResourceStream; } describe('paginator', () => { const UUID = uuid.v1(); - function FakeClass() {} + function FakeClass() { + // do nothing + } beforeEach(() => { FakeClass.prototype.methodToExtend = () => { @@ -75,7 +81,6 @@ describe('paginator', () => { it('should accept an array or string method names', () => { const originalMethod = FakeClass.prototype.methodToExtend; - FakeClass.prototype.anotherMethodToExtend = () => {}; const anotherMethod = FakeClass.prototype.anotherMethodToExtend; const methodsToExtend = ['methodToExtend', 'anotherMethodToExtend']; paginator.extend(FakeClass, methodsToExtend); @@ -117,7 +122,7 @@ describe('paginator', () => { return this.uuid; }; - // tslint:disable-next-line:no-any + /* eslint-disable @typescript-eslint/no-explicit-any */ const cls = new (FakeClass as any)(); cls.uuid = uuid.v1(); @@ -159,7 +164,7 @@ describe('paginator', () => { return args as ParsedArguments; }); sandbox.stub(paginator, 'runAsStream_').callsFake(createFakeStream); - FakeClass.prototype.streamMethod.apply(FakeClass.prototype, fakeArgs); + FakeClass.prototype.streamMethod(...fakeArgs); }); it('should run the method as a stream', done => { diff --git a/test/resource-stream.ts b/test/resource-stream.ts index 10a1da1..64d1790 100644 --- a/test/resource-stream.ts +++ b/test/resource-stream.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach, afterEach} from 'mocha'; import * as sinon from 'sinon'; import {Transform} from 'stream'; diff --git a/tsconfig.json b/tsconfig.json index b10ee49..8b14ad9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "./node_modules/gts/tsconfig-google.json", "compilerOptions": { + "lib": ["es2018", "dom"], "rootDir": ".", "outDir": "build" },