From d493535425dcd86099a47c8e8171fdd21b5e4d42 Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Sat, 19 Jan 2019 19:58:02 +0530 Subject: [PATCH 1/5] Replace array `indexOf ` checks with `includes` in src/lib --- src/lib/converter/context.ts | 4 ++-- src/lib/converter/factories/declaration.ts | 6 +++--- src/lib/converter/nodes/block.ts | 2 +- src/lib/converter/plugins/CommentPlugin.ts | 2 +- src/lib/converter/plugins/GitHubPlugin.ts | 2 +- src/lib/converter/plugins/PackagePlugin.ts | 2 +- src/lib/converter/plugins/TypePlugin.ts | 2 +- src/lib/converter/types/reference.ts | 2 +- src/lib/models/reflections/abstract.ts | 6 +++--- src/lib/output/plugins/NavigationPlugin.ts | 2 +- src/lib/output/plugins/TocPlugin.ts | 4 ++-- src/lib/output/utils/resources/helpers.ts | 2 +- src/lib/output/utils/resources/templates.ts | 2 +- src/lib/utils/options/declaration.ts | 2 +- src/lib/utils/options/sources/component.ts | 2 +- src/lib/utils/options/sources/typescript.ts | 2 +- 16 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/lib/converter/context.ts b/src/lib/converter/context.ts index b2da96fb1..ccbc15cd6 100644 --- a/src/lib/converter/context.ts +++ b/src/lib/converter/context.ts @@ -218,7 +218,7 @@ export class Context { * @param callback The callback that should be executed. */ withSourceFile(node: ts.SourceFile, callback: Function) { - let isExternal = this.fileNames.indexOf(node.fileName) === -1; + let isExternal = !this.fileNames.includes(node.fileName); if (!isExternal && this.externalPattern) { isExternal = this.externalPattern.some(mm => mm.match(node.fileName)); } @@ -322,7 +322,7 @@ export class Context { if (baseNode.symbol) { const id = this.getSymbolID(baseNode.symbol)!; - if (this.inheritedChildren && this.inheritedChildren.indexOf(id) !== -1) { + if (this.inheritedChildren && this.inheritedChildren.includes(id)) { return target; } else { this.inheritedChildren = this.inheritedChildren || []; diff --git a/src/lib/converter/factories/declaration.ts b/src/lib/converter/factories/declaration.ts index 777bd4ca7..ba997b5a8 100644 --- a/src/lib/converter/factories/declaration.ts +++ b/src/lib/converter/factories/declaration.ts @@ -81,12 +81,12 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind: // Test whether the node is static, when merging a module to a class make the node static let isConstructorProperty = false; let isStatic = false; - if (nonStaticKinds.indexOf(kind) === -1) { + if (!nonStaticKinds.includes(kind)) { isStatic = !!(modifiers & ts.ModifierFlags.Static); if (container.kind === ReflectionKind.Class) { if (node.parent && node.parent.kind === ts.SyntaxKind.Constructor) { isConstructorProperty = true; - } else if (!node.parent || nonStaticMergeKinds.indexOf(node.parent.kind) === -1) { + } else if (!node.parent || !nonStaticMergeKinds.includes(node.parent.kind)) { isStatic = true; } } @@ -179,7 +179,7 @@ function mergeDeclarations(context: Context, reflection: DeclarationReflection, if ( context.isInherit && - (context.inherited || []).indexOf(reflection.name) !== -1 && + (context.inherited || []).includes(reflection.name) && (node.parent === context.inheritParent || reflection.flags.isConstructorProperty) ) { if (!reflection.overwrites) { diff --git a/src/lib/converter/nodes/block.ts b/src/lib/converter/nodes/block.ts index dbee4a65f..06851481f 100644 --- a/src/lib/converter/nodes/block.ts +++ b/src/lib/converter/nodes/block.ts @@ -87,7 +87,7 @@ export class BlockConverter extends ConverterNodeComponent { - if (preferred.indexOf(statement.kind) !== -1) { + if (preferred.includes(statement.kind)) { this.owner.convertNode(context, statement); } else { statements.push(statement); diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index 936c5bb89..c24559c39 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -322,7 +322,7 @@ export class CommentPlugin extends ConverterComponent { }); for (let key in project.symbolMapping) { - if (project.symbolMapping.hasOwnProperty(key) && deletedIds.indexOf(project.symbolMapping[key]) !== -1) { + if (project.symbolMapping.hasOwnProperty(key) && deletedIds.includes(project.symbolMapping[key])) { delete project.symbolMapping[key]; } } diff --git a/src/lib/converter/plugins/GitHubPlugin.ts b/src/lib/converter/plugins/GitHubPlugin.ts index 34b3cd4da..b1a9695de 100644 --- a/src/lib/converter/plugins/GitHubPlugin.ts +++ b/src/lib/converter/plugins/GitHubPlugin.ts @@ -100,7 +100,7 @@ export class Repository { * @returns TRUE when the file is part of the repository, otherwise FALSE. */ contains(fileName: string): boolean { - return this.files.indexOf(fileName) !== -1; + return this.files.includes(fileName); } /** diff --git a/src/lib/converter/plugins/PackagePlugin.ts b/src/lib/converter/plugins/PackagePlugin.ts index f48fbb6df..7add757be 100644 --- a/src/lib/converter/plugins/PackagePlugin.ts +++ b/src/lib/converter/plugins/PackagePlugin.ts @@ -94,7 +94,7 @@ export class PackagePlugin extends ConverterComponent { let dirName: string, parentDir = Path.resolve(Path.dirname(fileName)); do { dirName = parentDir; - if (this.visited.indexOf(dirName) !== -1) { + if (this.visited.includes(dirName)) { break; } diff --git a/src/lib/converter/plugins/TypePlugin.ts b/src/lib/converter/plugins/TypePlugin.ts index 943e4d1c6..61a733432 100644 --- a/src/lib/converter/plugins/TypePlugin.ts +++ b/src/lib/converter/plugins/TypePlugin.ts @@ -111,7 +111,7 @@ export class TypePlugin extends ConverterComponent { } private postpone(reflection: DeclarationReflection) { - if (this.reflections.indexOf(reflection) === -1) { + if (!this.reflections.includes(reflection)) { this.reflections.push(reflection); } } diff --git a/src/lib/converter/types/reference.ts b/src/lib/converter/types/reference.ts index f10fc4b2a..5703b966f 100644 --- a/src/lib/converter/types/reference.ts +++ b/src/lib/converter/types/reference.ts @@ -112,7 +112,7 @@ export class ReferenceConverter extends ConverterTypeComponent implements TypeNo */ private convertLiteral(context: Context, symbol: ts.Symbol, node?: ts.Node): Type | undefined { for (let declaration of symbol.declarations) { - if (context.visitStack.indexOf(declaration) !== -1) { + if (context.visitStack.includes(declaration)) { if (declaration.kind === ts.SyntaxKind.TypeLiteral || declaration.kind === ts.SyntaxKind.ObjectLiteralExpression) { // TODO: Check if this type assertion is safe and document. diff --git a/src/lib/models/reflections/abstract.ts b/src/lib/models/reflections/abstract.ts index ebd331711..bd779d25b 100644 --- a/src/lib/models/reflections/abstract.ts +++ b/src/lib/models/reflections/abstract.ts @@ -219,12 +219,12 @@ export class ReflectionFlags extends Array { private setSingleFlag(flag: ReflectionFlag, set: boolean) { const name = ReflectionFlag[flag].replace(/(.)([A-Z])/g, (m, a, b) => a + ' ' + b.toLowerCase()); if (!set && this.hasFlag(flag)) { - if (relevantFlags.indexOf(flag) !== -1) { + if (relevantFlags.includes(flag)) { this.splice(this.indexOf(name), 1); } this.flags ^= flag; } else if (set && !this.hasFlag(flag)) { - if (relevantFlags.indexOf(flag) !== -1) { + if (relevantFlags.includes(flag)) { this.push(name); } this.flags |= flag; @@ -441,7 +441,7 @@ export abstract class Reflection { target._aliases = []; } let suffix = '', index = 0; - while (target._aliases.indexOf(alias + suffix) !== -1) { + while (target._aliases.includes(alias + suffix)) { suffix = '-' + (++index).toString(); } diff --git a/src/lib/output/plugins/NavigationPlugin.ts b/src/lib/output/plugins/NavigationPlugin.ts index cff0a39a9..3c24ff5ff 100644 --- a/src/lib/output/plugins/NavigationPlugin.ts +++ b/src/lib/output/plugins/NavigationPlugin.ts @@ -48,7 +48,7 @@ export class NavigationPlugin extends RendererComponent { item.isInPath = false; item.isVisible = item.isGlobals; - if (item.url === page.url || (item.dedicatedUrls && item.dedicatedUrls.indexOf(page.url) !== -1)) { + if (item.url === page.url || (item.dedicatedUrls && item.dedicatedUrls.includes(page.url))) { currentItems.push(item); } diff --git a/src/lib/output/plugins/TocPlugin.ts b/src/lib/output/plugins/TocPlugin.ts index 60730164a..becc4c84b 100644 --- a/src/lib/output/plugins/TocPlugin.ts +++ b/src/lib/output/plugins/TocPlugin.ts @@ -63,7 +63,7 @@ export class TocPlugin extends RendererComponent { } else { children.forEach((child: DeclarationReflection) => { - if (restriction && restriction.length > 0 && restriction.indexOf(child.name) === -1) { + if (restriction && restriction.length > 0 && !restriction.includes(child.name)) { return; } @@ -72,7 +72,7 @@ export class TocPlugin extends RendererComponent { } const item = NavigationItem.create(child, parent, true); - if (trail.indexOf(child) !== -1) { + if (trail.includes(child)) { item.isInPath = true; item.isCurrent = (trail[trail.length - 1] === child); TocPlugin.buildToc(child, trail, item); diff --git a/src/lib/output/utils/resources/helpers.ts b/src/lib/output/utils/resources/helpers.ts index d0c0a8dbb..b4e2ef070 100644 --- a/src/lib/output/utils/resources/helpers.ts +++ b/src/lib/output/utils/resources/helpers.ts @@ -41,7 +41,7 @@ export class HelperStack extends ResourceStack { const helpers = resources[resourceName].getHelpers(); for (let name in helpers) { - if (this.registeredNames.indexOf(name) !== -1) { + if (this.registeredNames.includes(name)) { continue; } this.registeredNames.push(name); diff --git a/src/lib/output/utils/resources/templates.ts b/src/lib/output/utils/resources/templates.ts index 5e7b50aaa..a6f485653 100644 --- a/src/lib/output/utils/resources/templates.ts +++ b/src/lib/output/utils/resources/templates.ts @@ -39,7 +39,7 @@ export class PartialStack extends TemplateStack { const resources = this.getAllResources(); for (let name in resources) { - if (this.registeredNames.indexOf(name) !== -1) { + if (this.registeredNames.includes(name)) { continue; } this.registeredNames.push(name); diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index 92ba21a41..cc881786e 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -114,7 +114,7 @@ export class OptionDeclaration { value = map.has(key) ? map.get(key) : value; } else if (key in map) { value = map[key]; - } else if (values.indexOf(value) === -1 && errorCallback) { + } else if (!values.includes(value) && errorCallback) { if (this.mapError) { errorCallback(this.mapError); } else { diff --git a/src/lib/utils/options/sources/component.ts b/src/lib/utils/options/sources/component.ts index 54ce2da42..952abb481 100644 --- a/src/lib/utils/options/sources/component.ts +++ b/src/lib/utils/options/sources/component.ts @@ -28,7 +28,7 @@ export class ComponentSource extends OptionsComponent { return; } - if (this.knownComponents.indexOf(name) === -1) { + if (!this.knownComponents.includes(name)) { this.knownComponents.push(name); this.owner.addDeclarations(component.getOptionDeclarations()); } diff --git a/src/lib/utils/options/sources/typescript.ts b/src/lib/utils/options/sources/typescript.ts index 82b0f80bc..d54377f27 100644 --- a/src/lib/utils/options/sources/typescript.ts +++ b/src/lib/utils/options/sources/typescript.ts @@ -28,7 +28,7 @@ export class TypeScriptSource extends OptionsComponent { this.declarations = []; for (let declaration of _ts.optionDeclarations) { - if (TypeScriptSource.IGNORED.indexOf(declaration.name) === -1) { + if (!TypeScriptSource.IGNORED.includes(declaration.name)) { this.addTSOption(declaration); } } From 866ca44a7f4e3508c18a7346393233deb60aab51 Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Sat, 19 Jan 2019 19:58:19 +0530 Subject: [PATCH 2/5] Replace array `indexOf ` checks with `includes` in test --- src/test/typedoc.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/typedoc.ts b/src/test/typedoc.ts index f223c4c1b..d56c25582 100644 --- a/src/test/typedoc.ts +++ b/src/test/typedoc.ts @@ -15,55 +15,55 @@ describe('TypeDoc', function() { const inputFiles = Path.join(__dirname, 'converter', 'class'); const expanded = application.expandInputFiles([inputFiles]); - Assert.notEqual(expanded.indexOf(Path.join(inputFiles, 'class.ts')), -1); - Assert.equal(expanded.indexOf(inputFiles), -1); + Assert.ok(expanded.includes(Path.join(inputFiles, 'class.ts'))); + Assert.ok(!expanded.includes(inputFiles)); }); it('expands input files', function() { const inputFiles = Path.join(__dirname, 'converter', 'class', 'class.ts'); const expanded = application.expandInputFiles([inputFiles]); - Assert.notEqual(expanded.indexOf(inputFiles), -1); + Assert.ok(expanded.includes(inputFiles)); }); it('honors the exclude argument even on a fixed directory list', function() { const inputFiles = Path.join(__dirname, 'converter', 'class'); application.options.setValue('exclude', '**/class.ts'); const expanded = application.expandInputFiles([inputFiles]); - Assert.equal(expanded.indexOf(Path.join(inputFiles, 'class.ts')), -1); - Assert.equal(expanded.indexOf(inputFiles), -1); + Assert.ok(!expanded.includes(Path.join(inputFiles, 'class.ts'))); + Assert.ok(!expanded.includes(inputFiles)); }); it('honors the exclude argument even on a fixed file list', function() { const inputFiles = Path.join(__dirname, 'converter', 'class', 'class.ts'); application.options.setValue('exclude', '**/class.ts'); const expanded = application.expandInputFiles([inputFiles]); - Assert.equal(expanded.indexOf(inputFiles), -1); + Assert.ok(!expanded.includes(inputFiles)); }); it('supports multiple excludes', function() { const inputFiles = Path.join(__dirname, 'converter'); application.options.setValue('exclude', '**/+(class|access).ts'); const expanded = application.expandInputFiles([inputFiles]); - Assert.equal(expanded.indexOf(Path.join(inputFiles, 'class', 'class.ts')), -1); - Assert.equal(expanded.indexOf(Path.join(inputFiles, 'access', 'access.ts')), -1); - Assert.equal(expanded.indexOf(inputFiles), -1); + Assert.ok(!expanded.includes(Path.join(inputFiles, 'class', 'class.ts'))); + Assert.ok(!expanded.includes(Path.join(inputFiles, 'access', 'access.ts'))); + Assert.ok(!expanded.includes(inputFiles)); }); it('supports array of excludes', function() { const inputFiles = Path.join(__dirname, 'converter'); application.options.setValue('exclude', [ '**/class.ts', '**/access.ts' ]); const expanded = application.expandInputFiles([inputFiles]); - Assert.equal(expanded.indexOf(Path.join(inputFiles, 'class', 'class.ts')), -1); - Assert.equal(expanded.indexOf(Path.join(inputFiles, 'access', 'access.ts')), -1); - Assert.equal(expanded.indexOf(inputFiles), -1); + Assert.ok(!expanded.includes(Path.join(inputFiles, 'class', 'class.ts'))); + Assert.ok(!expanded.includes(Path.join(inputFiles, 'access', 'access.ts'))); + Assert.ok(!expanded.includes(inputFiles)); }); it('supports excluding directories beginning with dots', function() { const inputFiles = __dirname; application.options.setValue('exclude', '**/+(.dot)/**'); const expanded = application.expandInputFiles([inputFiles]); - Assert.equal(expanded.indexOf(Path.join(inputFiles, '.dot', 'index.d.ts')), -1); - Assert.equal(expanded.indexOf(inputFiles), -1); + Assert.ok(!expanded.includes(Path.join(inputFiles, '.dot', 'index.d.ts'))); + Assert.ok(!expanded.includes(inputFiles)); }); it('Honors the exclude option even if a module is imported', () => { application.options.setValue('exclude', '**/b.d.ts'); From 15bdb961f5cd2bfc9fbed4f052708fe8791cc83d Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Tue, 22 Jan 2019 22:50:02 +0530 Subject: [PATCH 3/5] Replace string.indexOf with includes --- src/lib/converter/plugins/CommentPlugin.ts | 2 +- src/lib/converter/plugins/DynamicModulePlugin.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index c24559c39..5ebb9196c 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -63,7 +63,7 @@ export class CommentPlugin extends ConverterComponent { } private storeModuleComment(comment: string, reflection: Reflection) { - const isPreferred = (comment.toLowerCase().indexOf('@preferred') !== -1); + const isPreferred = (comment.toLowerCase().includes('@preferred')); if (this.comments[reflection.id]) { const info = this.comments[reflection.id]; diff --git a/src/lib/converter/plugins/DynamicModulePlugin.ts b/src/lib/converter/plugins/DynamicModulePlugin.ts index 12c1b68c3..d89080aaa 100644 --- a/src/lib/converter/plugins/DynamicModulePlugin.ts +++ b/src/lib/converter/plugins/DynamicModulePlugin.ts @@ -54,7 +54,7 @@ export class DynamicModulePlugin extends ConverterComponent { private onDeclaration(context: Context, reflection: Reflection, node?: ts.Node) { if (reflection.kindOf(ReflectionKind.ExternalModule)) { let name = reflection.name; - if (name.indexOf('/') === -1) { + if (!name.includes('/')) { return; } From 5d1131ac3300437a2e2fd40b1a31f95048beefb0 Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Tue, 22 Jan 2019 22:54:50 +0530 Subject: [PATCH 4/5] Replace `Assert.Ok` with just `Assert` function --- src/test/typedoc.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/typedoc.ts b/src/test/typedoc.ts index d56c25582..c4a103525 100644 --- a/src/test/typedoc.ts +++ b/src/test/typedoc.ts @@ -15,55 +15,55 @@ describe('TypeDoc', function() { const inputFiles = Path.join(__dirname, 'converter', 'class'); const expanded = application.expandInputFiles([inputFiles]); - Assert.ok(expanded.includes(Path.join(inputFiles, 'class.ts'))); - Assert.ok(!expanded.includes(inputFiles)); + Assert(expanded.includes(Path.join(inputFiles, 'class.ts'))); + Assert(!expanded.includes(inputFiles)); }); it('expands input files', function() { const inputFiles = Path.join(__dirname, 'converter', 'class', 'class.ts'); const expanded = application.expandInputFiles([inputFiles]); - Assert.ok(expanded.includes(inputFiles)); + Assert(expanded.includes(inputFiles)); }); it('honors the exclude argument even on a fixed directory list', function() { const inputFiles = Path.join(__dirname, 'converter', 'class'); application.options.setValue('exclude', '**/class.ts'); const expanded = application.expandInputFiles([inputFiles]); - Assert.ok(!expanded.includes(Path.join(inputFiles, 'class.ts'))); - Assert.ok(!expanded.includes(inputFiles)); + Assert(!expanded.includes(Path.join(inputFiles, 'class.ts'))); + Assert(!expanded.includes(inputFiles)); }); it('honors the exclude argument even on a fixed file list', function() { const inputFiles = Path.join(__dirname, 'converter', 'class', 'class.ts'); application.options.setValue('exclude', '**/class.ts'); const expanded = application.expandInputFiles([inputFiles]); - Assert.ok(!expanded.includes(inputFiles)); + Assert(!expanded.includes(inputFiles)); }); it('supports multiple excludes', function() { const inputFiles = Path.join(__dirname, 'converter'); application.options.setValue('exclude', '**/+(class|access).ts'); const expanded = application.expandInputFiles([inputFiles]); - Assert.ok(!expanded.includes(Path.join(inputFiles, 'class', 'class.ts'))); - Assert.ok(!expanded.includes(Path.join(inputFiles, 'access', 'access.ts'))); - Assert.ok(!expanded.includes(inputFiles)); + Assert(!expanded.includes(Path.join(inputFiles, 'class', 'class.ts'))); + Assert(!expanded.includes(Path.join(inputFiles, 'access', 'access.ts'))); + Assert(!expanded.includes(inputFiles)); }); it('supports array of excludes', function() { const inputFiles = Path.join(__dirname, 'converter'); application.options.setValue('exclude', [ '**/class.ts', '**/access.ts' ]); const expanded = application.expandInputFiles([inputFiles]); - Assert.ok(!expanded.includes(Path.join(inputFiles, 'class', 'class.ts'))); - Assert.ok(!expanded.includes(Path.join(inputFiles, 'access', 'access.ts'))); - Assert.ok(!expanded.includes(inputFiles)); + Assert(!expanded.includes(Path.join(inputFiles, 'class', 'class.ts'))); + Assert(!expanded.includes(Path.join(inputFiles, 'access', 'access.ts'))); + Assert(!expanded.includes(inputFiles)); }); it('supports excluding directories beginning with dots', function() { const inputFiles = __dirname; application.options.setValue('exclude', '**/+(.dot)/**'); const expanded = application.expandInputFiles([inputFiles]); - Assert.ok(!expanded.includes(Path.join(inputFiles, '.dot', 'index.d.ts'))); - Assert.ok(!expanded.includes(inputFiles)); + Assert(!expanded.includes(Path.join(inputFiles, '.dot', 'index.d.ts'))); + Assert(!expanded.includes(inputFiles)); }); it('Honors the exclude option even if a module is imported', () => { application.options.setValue('exclude', '**/b.d.ts'); From 215f19d5d258e4c65e6656f74847065818b7f822 Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Tue, 22 Jan 2019 23:09:14 +0530 Subject: [PATCH 5/5] Replace indexOf with includes in lib/converter.ts --- src/lib/converter/converter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index f011da057..12d0c77d0 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -312,7 +312,7 @@ export class Converter extends ChildableComponent