diff options
author | Maximilien Mellen <maxmellen0@gmail.com> | 2020-02-19 21:36:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 15:36:18 -0500 |
commit | 90125566bbaed8b5c6e55ca8dbc432e3433fb73c (patch) | |
tree | bf798a408b26264641260395ce8cfc9d4bb37637 /std/encoding | |
parent | 852823fa505d75d61e70e1330bbf366aa248e650 (diff) |
Enable TS strict mode by default (#3899)
Fixes #3324
Co-authored-by: Kitson Kelly <me@kitsonkelly.com>
Diffstat (limited to 'std/encoding')
-rw-r--r-- | std/encoding/base32_test.ts | 2 | ||||
-rw-r--r-- | std/encoding/csv.ts | 10 | ||||
-rw-r--r-- | std/encoding/csv_test.ts | 34 | ||||
-rw-r--r-- | std/encoding/yaml/loader/loader.ts | 6 |
4 files changed, 30 insertions, 22 deletions
diff --git a/std/encoding/base32_test.ts b/std/encoding/base32_test.ts index eb51e44ab..28550d57a 100644 --- a/std/encoding/base32_test.ts +++ b/std/encoding/base32_test.ts @@ -6,7 +6,7 @@ import { encode, decode } from "./base32.ts"; // Lifted from https://stackoverflow.com/questions/38987784 const fromHexString = (hexString: string): Uint8Array => - new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); + new Uint8Array(hexString.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16))); const toHexString = (bytes: Uint8Array): string => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), ""); diff --git a/std/encoding/csv.ts b/std/encoding/csv.ts index 1314afcaa..12336b10d 100644 --- a/std/encoding/csv.ts +++ b/std/encoding/csv.ts @@ -46,7 +46,7 @@ function chkOptions(opt: ReadOptions): void { } if ( INVALID_RUNE.includes(opt.comma) || - INVALID_RUNE.includes(opt.comment) || + (typeof opt.comment === "string" && INVALID_RUNE.includes(opt.comment)) || opt.comma === opt.comment ) { throw new Error("Invalid Delimiter"); @@ -122,7 +122,7 @@ export async function readMatrix( } ): Promise<string[][]> { const result: string[][] = []; - let _nbFields: number; + let _nbFields: number | undefined; let lineResult: string[]; let first = true; let lineIndex = 0; @@ -253,8 +253,10 @@ export async function parse( }); } if (opt.parse) { - assert(opt.parse != null, "opt.parse must be set"); - return r.map((e: string[]): unknown => opt.parse(e)); + return r.map((e: string[]): unknown => { + assert(opt.parse, "opt.parse must be set"); + return opt.parse(e); + }); } return r; } diff --git a/std/encoding/csv_test.ts b/std/encoding/csv_test.ts index 74ba8face..efea353e1 100644 --- a/std/encoding/csv_test.ts +++ b/std/encoding/csv_test.ts @@ -476,26 +476,32 @@ for (const t of testCases) { if (t.Error) { let err; try { - actual = await readMatrix(new BufReader(new StringReader(t.Input)), { - comma: comma, - comment: comment, - trimLeadingSpace: trim, - fieldsPerRecord: fieldsPerRec, - lazyQuotes: lazyquote - }); + actual = await readMatrix( + new BufReader(new StringReader(t.Input ?? "")), + { + comma: comma, + comment: comment, + trimLeadingSpace: trim, + fieldsPerRecord: fieldsPerRec, + lazyQuotes: lazyquote + } + ); } catch (e) { err = e; } assert(err); assertEquals(err.message, t.Error); } else { - actual = await readMatrix(new BufReader(new StringReader(t.Input)), { - comma: comma, - comment: comment, - trimLeadingSpace: trim, - fieldsPerRecord: fieldsPerRec, - lazyQuotes: lazyquote - }); + actual = await readMatrix( + new BufReader(new StringReader(t.Input ?? "")), + { + comma: comma, + comment: comment, + trimLeadingSpace: trim, + fieldsPerRecord: fieldsPerRec, + lazyQuotes: lazyquote + } + ); const expected = t.Output; assertEquals(actual, expected); } diff --git a/std/encoding/yaml/loader/loader.ts b/std/encoding/yaml/loader/loader.ts index 556bd5b47..7db72a01d 100644 --- a/std/encoding/yaml/loader/loader.ts +++ b/std/encoding/yaml/loader/loader.ts @@ -187,7 +187,7 @@ interface DirectiveHandlers { [directive: string]: ( state: LoaderState, name: string, - ...args: unknown[] + ...args: string[] ) => void; } @@ -362,7 +362,7 @@ function storeMappingPair( mergeMappings(state, result, valueNode[index], overridableKeys); } } else { - mergeMappings(state, result, valueNode, overridableKeys); + mergeMappings(state, result, valueNode as ArrayObject, overridableKeys); } } else { if ( @@ -1610,7 +1610,7 @@ function readDocument(state: LoaderState): void { const documentStart = state.position; let position: number, directiveName: string, - directiveArgs: unknown[], + directiveArgs: string[], hasDirectives = false, ch: number; |