Skip to content

Commit edf98b6

Browse files
JustinBeckwithBenjamin E. Coe
authored andcommitted
refactor: enable noImplicitAny (#618)
1 parent 090d0fc commit edf98b6

6 files changed

Lines changed: 192 additions & 129 deletions

File tree

handwritten/logging/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"@types/pumpify": "^1.4.1",
8888
"@types/sinon": "^7.0.8",
8989
"@types/through2": "^2.0.34",
90+
"@types/tmp": "^0.1.0",
9091
"@types/uuid": "^3.4.4",
9192
"assert-rejects": "^1.0.0",
9293
"bignumber.js": "^9.0.0",
@@ -95,6 +96,7 @@
9596
"eslint-config-prettier": "^6.0.0",
9697
"eslint-plugin-node": "^10.0.0",
9798
"eslint-plugin-prettier": "^3.0.0",
99+
"execa": "^3.2.0",
98100
"google-proto-files": "^1.0.0",
99101
"gts": "^1.0.0",
100102
"http2spy": "^1.1.0",

handwritten/logging/src/log.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,19 +826,19 @@ class Log implements LogSeverityFunctions {
826826
return writeWithResource(resource);
827827
}
828828
async function writeWithResource(resource: {} | null) {
829-
let decoratedEntries;
829+
let decoratedEntries: EntryJson[];
830830
try {
831831
decoratedEntries = self.decorateEntries_(arrify(entry) as Entry[]);
832832
} catch (err) {
833833
// Ignore errors (the API will speak up if it has an issue).
834834
}
835-
self.truncateEntries(decoratedEntries);
835+
self.truncateEntries(decoratedEntries!);
836836
const projectId = await self.logging.auth.getProjectId();
837837
self.formattedName_ = Log.formatName_(projectId, self.name);
838838
const reqOpts = extend(
839839
{
840840
logName: self.formattedName_,
841-
entries: decoratedEntries,
841+
entries: decoratedEntries!,
842842
resource,
843843
},
844844
options

handwritten/logging/system-test/install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as execa from 'execa';
17+
import execa = require('execa');
1818
import * as mv from 'mv';
1919
import {ncp} from 'ncp';
2020
import * as tmp from 'tmp';

handwritten/logging/system-test/logging.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {HOST_ADDRESS} from 'gcp-metadata';
2222
import * as nock from 'nock';
2323
import {Duplex} from 'stream';
2424
import * as uuid from 'uuid';
25-
import * as http2spy from 'http2spy';
26-
import {Logging, Sink} from '../src';
25+
const http2spy = require('http2spy');
26+
import {Logging, Sink, Log, Entry} from '../src';
2727

2828
// block all attempts to chat with the metadata server (kokoro runs on GCE)
2929
nock(HOST_ADDRESS)
@@ -99,7 +99,8 @@ describe('Logging', () => {
9999
async function getAndDelete(method: Function) {
100100
const [objects] = await method();
101101
return Promise.all(
102-
objects
102+
// tslint:disable-next-line no-any
103+
(objects as any[])
103104
.filter(o => {
104105
const name = o.name || o.id;
105106
if (!name.startsWith(TESTS_PREFIX)) {
@@ -242,7 +243,10 @@ describe('Logging', () => {
242243
return {log, logEntries};
243244
}
244245

245-
function getEntriesFromLog(log, callback) {
246+
function getEntriesFromLog(
247+
log: Log,
248+
callback: (err: Error | null, entries?: Entry[]) => void
249+
) {
246250
let numAttempts = 0;
247251

248252
setTimeout(pollForMessages, WRITE_CONSISTENCY_DELAY_MS);
@@ -303,7 +307,7 @@ describe('Logging', () => {
303307

304308
getEntriesFromLog(log, (err, entries) => {
305309
assert.ifError(err);
306-
assert.strictEqual(entries.length, logEntries.length);
310+
assert.strictEqual(entries!.length, logEntries.length);
307311
done();
308312
});
309313
});
@@ -327,7 +331,8 @@ describe('Logging', () => {
327331
});
328332

329333
describe('log-specific entries', () => {
330-
let logExpected, logEntriesExpected;
334+
let logExpected: Log;
335+
let logEntriesExpected: Entry[];
331336

332337
before(done => {
333338
const {log, logEntries} = getTestLog();
@@ -339,7 +344,7 @@ describe('Logging', () => {
339344
it('should list log entries', done => {
340345
getEntriesFromLog(logExpected, (err, entries) => {
341346
assert.ifError(err);
342-
assert.strictEqual(entries.length, logEntriesExpected.length);
347+
assert.strictEqual(entries!.length, logEntriesExpected.length);
343348
done();
344349
});
345350
});
@@ -377,7 +382,7 @@ describe('Logging', () => {
377382
getEntriesFromLog(log, (err, entries) => {
378383
assert.ifError(err);
379384

380-
assert.deepStrictEqual(entries.map(x => x.data).reverse(), [
385+
assert.deepStrictEqual(entries!.map(x => x.data).reverse(), [
381386
'log entry 1',
382387
{delegate: 'my_username'},
383388
{
@@ -595,7 +600,7 @@ describe('Logging', () => {
595600
// Parse the time the resource was created using the resource id
596601
// Format 1: ${TESTS_PREFIX}-${date}-${uuid}
597602
// Format 2: ${TESTS_PREFIX}_${date}_${uuid}
598-
function getDateFromGeneratedName(name) {
603+
function getDateFromGeneratedName(name: string) {
599604
const timeCreated = name.substr(TESTS_PREFIX.length + 1).split(/-|_/g)[0];
600605
return new Date(Number(timeCreated));
601606
}

0 commit comments

Comments
 (0)