Skip to content

Commit fdf3b83

Browse files
author
williamd5
authored
Merge pull request #61 from cloudnode-pro/stricter-compiler-options
Stricter TypeScript compiler options
2 parents ac98707 + f77ee61 commit fdf3b83

File tree

10 files changed

+38
-41
lines changed

10 files changed

+38
-41
lines changed

browser/Cloudnode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Cloudnode {
9191
const text = await response.text();
9292
let data;
9393
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
94-
data = JSON.parse(text, (key, value) => {
94+
data = JSON.parse(text, (_key, value) => {
9595
// parse dates
9696
if (/^\d{4}-\d{2}-\d{2}T(?:\d{2}:){2}\d{2}(?:\.\d+)?(?:[a-zA-Z]+|\+\d{2}:\d{2})?$/.test(value))
9797
return new Date(value);

gen/DocSchema.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ interface DocSchema {
77
}
88

99
namespace DocSchema {
10-
export class Entry {
10+
export abstract class Entry {
1111
public name: string;
1212
public readonly type: string;
1313
public readonly typeName?: string;
1414
public readonly isStatic?: true;
1515

16-
constructor(name: string, type: string, isStatic?: true, alwaysTypeName?: true) {
16+
protected constructor(name: string, type: string, isStatic?: true, alwaysTypeName?: true) {
1717
this.name = name;
1818
this.type = type;
1919
this.isStatic = isStatic;
@@ -28,9 +28,7 @@ namespace DocSchema {
2828
return this.displayName.toLowerCase().replace(/[^a-z\d\s]/g, "").replace(/\s+/g, "-");
2929
}
3030

31-
public content(config: Config, schema: Schema): string {
32-
return "";
33-
}
31+
public abstract content(config: Config, schema: Schema): string;
3432
}
3533

3634
export class Property extends Entry {

gen/browser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export async function createBrowserSDK(config: Config): Promise<void> {
1010
// remove imports at beginning of file and export default at end of file
1111
const browserJs = mainJs.replace(/^import.*$/gm, "").replace(/^export default \w+;$/gm, "");
1212
// evaluate the code to verify it works
13-
const fetch = () => {};
1413
eval(browserJs);
1514
// create folder `/browser` if it doesn't exist
1615
try {

gen/docs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function generateDocSchema (schema: Schema, config: Config, pkg: Package)
6363
}
6464
// make operations into methods
6565
const operationMethods = operations.map(operation => {
66-
const returns = {type: getReturnType(operation, schema, config), description: getReturnDescription(operation, schema, config)};
66+
const returns = {type: getReturnType(operation, schema, config), description: getReturnDescription(operation)};
6767
const throws = getThrows(operation, schema, config).map(type => ({type}));
6868
const pathParams = Object.entries(operation.parameters.path ?? {}).map(([name, parameter]) => new DocSchema.Parameter(name, parameter.type, parameter.description, parameter.required, parameter.default));
6969
const queryParams = Object.entries(operation.parameters.query ?? {}).map(([name, parameter]) => new DocSchema.Parameter(name, parameter.type, parameter.description, parameter.required, parameter.default));
@@ -178,7 +178,7 @@ export function linkType (type: string, config: Config, schema: Schema): string
178178
else {
179179
// if it includes a generic, link the generic
180180
const parts = typeName.match(/<(.*)>/);
181-
if (parts) return `${link(typeName.slice(0, parts.index))}<${fullLink(parts[1])}>`;
181+
if (parts && parts[1]) return `${link(typeName.slice(0, parts.index))}<${fullLink(parts[1])}>`;
182182
}
183183
return link(typeName);
184184
};
@@ -233,8 +233,8 @@ export function generateMarkdownDocs (config: Config, schema: Schema, docSchema:
233233
export async function generateReadme (docMD: string, config: Config, pkg: Package): Promise<void> {
234234
const template = await fs.readFile("README.template.md", "utf8");
235235
// check if project builds successfully
236-
const buildStatus = await new Promise((resolve, reject) => {
237-
child_process.exec("npm run build", (error, stdout, stderr) => {
236+
const buildStatus = await new Promise((resolve) => {
237+
child_process.exec("npm run build", (error) => {
238238
resolve(!error);
239239
});
240240
});

gen/source.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default async (schema: Schema, config: Config, pkg: Package) => {
4444
const operations: FlatOperation[] = [];
4545
for (const [name, operation] of input) {
4646
const returnType = getReturnType(operation, schema, config);
47-
const returnDescription = getReturnDescription(operation, schema, config);
47+
const returnDescription = getReturnDescription(operation);
4848
const toFlatParam = ([name, parameter]: [string, Schema.Operation.Parameter]): NamedParameter => {
4949
const ts = `${name}${!parameter.required && !parameter.default ? "?: " : ": "}${parameter.type}${parameter.default ? ` = ${parameter.default}` : ""}`;
5050
return {name, ts, ...parameter};
@@ -86,12 +86,12 @@ export default async (schema: Schema, config: Config, pkg: Package) => {
8686

8787
// get operation namespaces
8888
const namespaces: FlatNamespace[] = [];
89-
for (const [name, namespace] of Object.entries(schema.operations).filter(([name, operation]) => operation.type === "namespace") as [string, Schema.Operation.Namespace][]) {
89+
for (const [name, namespace] of Object.entries(schema.operations).filter(([_name, operation]) => operation.type === "namespace") as [string, Schema.Operation.Namespace][]) {
9090
namespaces.push({name, operations: flatOperations(Object.entries(namespace.operations))});
9191
}
9292

9393
// get operations without namespace
94-
const operations = flatOperations(Object.entries(schema.operations).filter(([name, operation]) => operation.type !== "namespace") as [string, Schema.Operation][]);
94+
const operations = flatOperations(Object.entries(schema.operations).filter(([_name, operation]) => operation.type !== "namespace") as [string, Schema.Operation][]);
9595

9696
// load render main class from `/gen/templates/main.mustache`
9797
const mainTemplate = await fs.readFile(path.join("gen", "templates", "main.mustache"), "utf8");

gen/templates/main.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class {{config.name}} {
102102
const text = await response.text();
103103
let data: T;
104104
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
105-
data = JSON.parse(text, (key, value) => {
105+
data = JSON.parse(text, (_key, value) => {
106106
// parse dates
107107
if (/^\d{4}-\d{2}-\d{2}T(?:\d{2}:){2}\d{2}(?:\.\d+)?(?:[a-zA-Z]+|\+\d{2}:\d{2})?$/.test(value))
108108
return new Date(value);

gen/util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function getReturnType(operation: Schema.Operation, schema: Schema, confi
1919
* @param config
2020
* @returns The combined return description
2121
*/
22-
export function getReturnDescription(operation: Schema.Operation, schema: Schema, config: Config): string {
22+
export function getReturnDescription(operation: Schema.Operation): string {
2323
return operation.returns.filter(r => r.status >= 200 && r.status < 300 && r.description).map(r => r.description).join(" ");
2424
}
2525

@@ -85,11 +85,11 @@ function addExtraReturnsToOperation(operation: Schema.Operation): Schema.Operati
8585
*/
8686
export function replaceModelTypes(schema: Schema, config: Config): Schema {
8787
for (const modelID in schema.models) {
88-
const model = schema.models[modelID];
88+
const model = schema.models[modelID]!;
8989
for (const fieldID in model.fields) {
90-
const field = model.fields[fieldID];
90+
const field = model.fields[fieldID]!;
9191
if (schema.models.find(m => m.name === field.type))
92-
schema.models[modelID].fields[fieldID].type = `${config.name}.${field.type}`;
92+
schema.models[modelID]!.fields[fieldID]!.type = `${config.name}.${field.type}`;
9393
}
9494
}
9595
return schema;

src/Cloudnode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Cloudnode {
9191
const text = await response.text();
9292
let data;
9393
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
94-
data = JSON.parse(text, (key, value) => {
94+
data = JSON.parse(text, (_key, value) => {
9595
// parse dates
9696
if (/^\d{4}-\d{2}-\d{2}T(?:\d{2}:){2}\d{2}(?:\.\d+)?(?:[a-zA-Z]+|\+\d{2}:\d{2})?$/.test(value))
9797
return new Date(value);

src/Cloudnode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Cloudnode {
102102
const text = await response.text();
103103
let data: T;
104104
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
105-
data = JSON.parse(text, (key, value) => {
105+
data = JSON.parse(text, (_key, value) => {
106106
// parse dates
107107
if (/^\d{4}-\d{2}-\d{2}T(?:\d{2}:){2}\d{2}(?:\.\d+)?(?:[a-zA-Z]+|\+\d{2}:\d{2})?$/.test(value))
108108
return new Date(value);

tsconfig.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* Visit https://aka.ms/tsconfig to read more about this file */
44

55
/* Projects */
6-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
6+
"incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
77
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
88
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
99
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
@@ -53,17 +53,17 @@
5353
// "removeComments": true, /* Disable emitting comments. */
5454
// "noEmit": true, /* Disable emitting files from a compilation. */
5555
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
56-
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
56+
"importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
5757
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
5858
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
5959
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
6060
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
6161
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
6262
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
6363
// "newLine": "crlf", /* Set the newline character for emitting files. */
64-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
64+
"stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
6565
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
66-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
66+
"noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
6767
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
6868
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
6969
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
@@ -72,29 +72,29 @@
7272
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
7373
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
7474
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
75+
"preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
7676
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
7777

7878
/* Type Checking */
7979
"strict": true, /* Enable all strict type-checking options. */
80-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
83-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
84-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
85-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
80+
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81+
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82+
"strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
83+
"strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
84+
"strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
85+
"noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
8686
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
87-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
87+
"alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88+
"noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89+
"noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
9090
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
91-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
91+
"noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
9292
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
94-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
95-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
96-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
97-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
93+
"noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
94+
"noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
95+
"noPropertyAccessFromIndexSignature": false, /* Enforces using indexed accessors for keys declared using an indexed type. */
96+
"allowUnusedLabels": true, /* Disable error reporting for unused labels. */
97+
"allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
9898

9999
/* Completeness */
100100
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */

0 commit comments

Comments
 (0)