diff --git a/src/LanguageServer.spec.ts b/src/LanguageServer.spec.ts index ed594703b..59b84c1ae 100644 --- a/src/LanguageServer.spec.ts +++ b/src/LanguageServer.spec.ts @@ -228,7 +228,7 @@ describe('LanguageServer', () => { it('sends diagnostics that were triggered by the program instead of vscode', async () => { server['connection'] = server['createConnection'](); await server['createProject'](workspacePath); - let stub: SinonStub; + let stub: SinonStub | undefined; const promise = new Promise((resolve) => { stub = sinon.stub(connection, 'sendDiagnostics').callsFake(resolve as any); }); @@ -240,7 +240,7 @@ describe('LanguageServer', () => { `); program.validate(); await promise; - expect(stub.called).to.be.true; + expect(stub!.called).to.be.true; }); }); @@ -836,7 +836,7 @@ describe('LanguageServer', () => { expect(symbols.length).to.equal(1); const classSymbol = symbols[0]; expect(classSymbol.name).to.equal('MyFirstClass'); - const classChildrenSymbols = classSymbol.children; + const classChildrenSymbols = classSymbol.children!; expect(classChildrenSymbols.length).to.equal(2); expect(classChildrenSymbols[0].name).to.equal('pi'); expect(classChildrenSymbols[1].name).to.equal('buildAwesome'); @@ -866,7 +866,7 @@ describe('LanguageServer', () => { expect(symbols.length).to.equal(1); const namespaceSymbol = symbols[0]; expect(namespaceSymbol.name).to.equal('MyFirstNamespace'); - const classChildrenSymbols = namespaceSymbol.children; + const classChildrenSymbols = namespaceSymbol.children!; expect(classChildrenSymbols.length).to.equal(2); expect(classChildrenSymbols[0].name).to.equal('MyFirstNamespace.pi'); expect(classChildrenSymbols[1].name).to.equal('MyFirstNamespace.buildAwesome'); diff --git a/src/PluginInterface.spec.ts b/src/PluginInterface.spec.ts index 47fd4fea1..1e839829a 100644 --- a/src/PluginInterface.spec.ts +++ b/src/PluginInterface.spec.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/prefer-ts-expect-error */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ import { expect } from './chai-config.spec'; import * as sinon from 'sinon'; import { Logger } from './Logger'; @@ -16,8 +18,10 @@ describe('PluginInterface', () => { name: 'allows adding a plugin', beforePublish: beforePublish }; + //@ts-ignore the current definition of `emit` doesn't like this third argument pluginInterface.emit('beforePublish', undefined, []); pluginInterface.add(plugin); + //@ts-ignore the current definition of `emit` doesn't like this third argument pluginInterface.emit('beforePublish', undefined, []); expect(beforePublish.callCount).to.equal(1); }); @@ -39,6 +43,7 @@ describe('PluginInterface', () => { }; pluginInterface.add(plugin); pluginInterface.add(plugin); + //@ts-ignore the current definition of `emit` doesn't like this third argument pluginInterface.emit('beforePublish', undefined, []); expect(beforePublish.callCount).to.equal(1); pluginInterface.remove(plugin); @@ -52,9 +57,11 @@ describe('PluginInterface', () => { beforePublish: beforePublish }; pluginInterface.add(plugin); + //@ts-ignore the current definition of `emit` doesn't like this third argument pluginInterface.emit('beforePublish', undefined, []); expect(beforePublish.callCount).to.equal(1); pluginInterface.remove(plugin); + //@ts-ignore the current definition of `emit` doesn't like this third argument pluginInterface.emit('beforePublish', undefined, []); expect(beforePublish.callCount).to.equal(1); }); diff --git a/src/Program.spec.ts b/src/Program.spec.ts index 04b405980..3d0cf0aaf 100644 --- a/src/Program.spec.ts +++ b/src/Program.spec.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { assert, expect } from './chai-config.spec'; import * as pick from 'object.pick'; import * as sinonImport from 'sinon'; @@ -21,6 +23,7 @@ import { isBrsFile } from './astUtils/reflection'; import type { LiteralExpression } from './parser/Expression'; import type { AstEditor } from './astUtils/AstEditor'; import { tempDir, rootDir, stagingDir } from './testHelpers.spec'; +import type { BsDiagnostic } from './interfaces'; let sinon = sinonImport.createSandbox(); @@ -263,11 +266,11 @@ describe('Program', () => { }); it('allows adding diagnostics', () => { - const expected = [{ + const expected: BsDiagnostic[] = [{ message: 'message', file: undefined, range: undefined - }]; + }] as any; program.addDiagnostics(expected); const actual = (program as any).diagnostics; expect(actual).to.deep.equal(expected); @@ -720,7 +723,7 @@ describe('Program', () => { describe('reloadFile', () => { it('picks up new files in a scope when an xml file is loaded', () => { - program.options.ignoreErrorCodes.push(1013); + program.options.ignoreErrorCodes!.push(1013); program.setFile('components/component1.xml', trim` @@ -766,7 +769,7 @@ describe('Program', () => { }); it('reloads referenced fles when xml file changes', () => { - program.options.ignoreErrorCodes.push(1013); + program.options.ignoreErrorCodes!.push(1013); program.setFile('components/component1.brs', ''); let xmlFile = program.setFile('components/component1.xml', trim` @@ -1735,19 +1738,19 @@ describe('Program', () => { }); it('does not create map by default', async () => { - fsExtra.ensureDirSync(program.options.stagingDir); + fsExtra.ensureDirSync(program.options.stagingDir!); program.setFile('source/main.brs', ` sub main() end sub `); program.validate(); - await program.transpile([], program.options.stagingDir); + await program.transpile([], program.options.stagingDir!); expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs`)).is.true; expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs.map`)).is.false; }); it('creates sourcemap for brs and xml files', async () => { - fsExtra.ensureDirSync(program.options.stagingDir); + fsExtra.ensureDirSync(program.options.stagingDir!); program.setFile('source/main.brs', ` sub main() end sub @@ -1770,27 +1773,27 @@ describe('Program', () => { dest: s`components/comp1.xml` }]; program.options.sourceMap = true; - await program.transpile(filePaths, program.options.stagingDir); + await program.transpile(filePaths, program.options.stagingDir!); expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs.map`)).is.true; expect(fsExtra.pathExistsSync(s`${stagingDir}/components/comp1.xml.map`)).is.true; }); it('copies the bslib.brs file', async () => { - fsExtra.ensureDirSync(program.options.stagingDir); + fsExtra.ensureDirSync(program.options.stagingDir!); program.validate(); - await program.transpile([], program.options.stagingDir); + await program.transpile([], program.options.stagingDir!); expect(fsExtra.pathExistsSync(s`${stagingDir}/source/bslib.brs`)).is.true; }); it('copies the bslib.brs file to optionally specified directory', async () => { - fsExtra.ensureDirSync(program.options.stagingDir); + fsExtra.ensureDirSync(program.options.stagingDir!); program.options.bslibDestinationDir = 'source/opt'; program.validate(); - await program.transpile([], program.options.stagingDir); + await program.transpile([], program.options.stagingDir!); expect(fsExtra.pathExistsSync(s`${stagingDir}/source/opt/bslib.brs`)).is.true; }); @@ -1873,7 +1876,7 @@ describe('Program', () => { }, { src: s`${rootDir}/source/main.bs`, dest: 'source/main.bs' - }], program.options.stagingDir); + }], program.options.stagingDir!); //entries should now be in alphabetic order expect( @@ -1960,7 +1963,7 @@ describe('Program', () => { print "hello world" end sub `); - let literalExpression: LiteralExpression; + let literalExpression: LiteralExpression | undefined; //replace all strings with "goodbye world" program.plugins.add({ name: 'TestPlugin', @@ -1989,7 +1992,7 @@ describe('Program', () => { ); //our literalExpression should have been restored to its original value - expect(literalExpression.token.text).to.eql('"hello world"'); + expect(literalExpression!.token.text).to.eql('"hello world"'); }); it('handles AstEditor for beforeProgramTranspile', async () => { @@ -1998,7 +2001,7 @@ describe('Program', () => { print "hello world" end sub `); - let literalExpression: LiteralExpression; + let literalExpression: LiteralExpression | undefined; //replace all strings with "goodbye world" program.plugins.add({ name: 'TestPlugin', @@ -2025,7 +2028,7 @@ describe('Program', () => { ); //our literalExpression should have been restored to its original value - expect(literalExpression.token.text).to.eql('"hello world"'); + expect(literalExpression!.token.text).to.eql('"hello world"'); }); it('copies bslib.brs when no ropm version was found', async () => { @@ -2046,7 +2049,7 @@ describe('Program', () => { print SOURCE_LINE_NUM end sub `); - await program.transpile([], program.options.stagingDir); + await program.transpile([], program.options.stagingDir!); expect(trimMap( fsExtra.readFileSync(s`${stagingDir}/source/logger.brs`).toString() )).to.eql(trim` @@ -2062,7 +2065,7 @@ describe('Program', () => { print "logInfo" end sub `); - await program.transpile([], program.options.stagingDir); + await program.transpile([], program.options.stagingDir!); expect(trimMap( fsExtra.readFileSync(s`${stagingDir}/source/logger.brs`).toString() )).to.eql(trim` @@ -2078,7 +2081,7 @@ describe('Program', () => { `); - await program.transpile([], program.options.stagingDir); + await program.transpile([], program.options.stagingDir!); expect(trimMap( fsExtra.readFileSync(s`${stagingDir}/components/Component1.xml`).toString() )).to.eql(trim` @@ -2096,7 +2099,7 @@ describe('Program', () => { `); - await program.transpile([], program.options.stagingDir); + await program.transpile([], program.options.stagingDir!); expect(trimMap( fsExtra.readFileSync(s`${stagingDir}/components/Component1.xml`).toString() )).to.eql(trim` diff --git a/src/ProgramBuilder.spec.ts b/src/ProgramBuilder.spec.ts index 9f2403411..63ac78bd8 100644 --- a/src/ProgramBuilder.spec.ts +++ b/src/ProgramBuilder.spec.ts @@ -274,7 +274,7 @@ describe('ProgramBuilder', () => { let diagnostics = createBsDiagnostic('p1', ['m1']); let f1 = diagnostics[0].file as BrsFile; - f1.fileContents = null; + (f1.fileContents as any) = null; sinon.stub(builder, 'getDiagnostics').returns(diagnostics); sinon.stub(builder.program, 'getFile').returns(f1); @@ -292,7 +292,7 @@ describe('ProgramBuilder', () => { let diagnostics = createBsDiagnostic('p1', ['m1']); sinon.stub(builder, 'getDiagnostics').returns(diagnostics); - sinon.stub(builder.program, 'getFile').returns(null); + sinon.stub(builder.program, 'getFile').returns(null as any); let printStub = sinon.stub(diagnosticUtils, 'printDiagnostic'); @@ -351,8 +351,8 @@ describe('ProgramBuilder', () => { }); function createBsDiagnostic(filePath: string, messages: string[]): BsDiagnostic[] { - let file = new BrsFile(filePath, filePath, null); - let diagnostics = []; + let file = new BrsFile(filePath, filePath, null as any); + let diagnostics: BsDiagnostic[] = []; for (let message of messages) { let d = createDiagnostic(file, 1, message); d.file = file; diff --git a/src/Scope.spec.ts b/src/Scope.spec.ts index fb7a915de..c28100774 100644 --- a/src/Scope.spec.ts +++ b/src/Scope.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { expect } from './chai-config.spec'; import * as sinonImport from 'sinon'; import { Position, Range } from 'vscode-languageserver'; @@ -9,7 +10,7 @@ import PluginInterface from './PluginInterface'; import { expectDiagnostics, expectZeroDiagnostics, trim } from './testHelpers.spec'; import { Logger } from './Logger'; import type { BrsFile } from './files/BrsFile'; -import type { FunctionStatement, NamespaceStatement } from './parser/Statement'; +import type { NamespaceStatement } from './parser/Statement'; import type { OnScopeValidateEvent } from './interfaces'; describe('Scope', () => { @@ -30,7 +31,7 @@ describe('Scope', () => { it('getEnumMemberFileLink does not crash on undefined name', () => { program.setFile('source/main.bs', ``); const scope = program.getScopesForFile('source/main.bs')[0]; - scope.getEnumMemberFileLink(null); + scope.getEnumMemberFileLink(null as any); //test passes if this doesn't explode }); @@ -1481,7 +1482,7 @@ describe('Scope', () => { `); program.setFile(s`components/child.brs`, ``); program.validate(); - let childScope = program.getComponentScope('child'); + let childScope = program.getComponentScope('child')!; expect(childScope.getAllCallables().map(x => x.callable.name)).not.to.include('parentSub'); program.setFile('components/parent.xml', trim` @@ -1542,7 +1543,7 @@ describe('Scope', () => { end function end namespace `); - delete ((file.ast.statements[0] as NamespaceStatement).body.statements[0] as FunctionStatement).name; + delete ((file.ast.statements[0] as NamespaceStatement).body.statements[0] as any).name; program.validate(); program['scopes']['source'].buildNamespaceLookup(); }); diff --git a/src/Scope.ts b/src/Scope.ts index 3804ccec7..7302a1f3d 100644 --- a/src/Scope.ts +++ b/src/Scope.ts @@ -917,8 +917,8 @@ export class Scope { } private validateClasses() { - let validator = new BsClassValidator(); - validator.validate(this); + let validator = new BsClassValidator(this); + validator.validate(); this.diagnostics.push(...validator.diagnostics); } diff --git a/src/Stopwatch.ts b/src/Stopwatch.ts index 9c743102d..2866e9a2e 100644 --- a/src/Stopwatch.ts +++ b/src/Stopwatch.ts @@ -6,7 +6,7 @@ export class Stopwatch { /** * The number of milliseconds when the stopwatch was started. */ - private startTime: number; + private startTime: number | undefined; start() { this.startTime = performance.now(); } @@ -17,7 +17,7 @@ export class Stopwatch { this.startTime = undefined; } reset() { - this.totalMilliseconds = undefined; + this.totalMilliseconds = 0; this.startTime = undefined; } getDurationText() { diff --git a/src/SymbolTable.spec.ts b/src/SymbolTable.spec.ts index 8267c6822..48bcbfd3d 100644 --- a/src/SymbolTable.spec.ts +++ b/src/SymbolTable.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { SymbolTable } from './SymbolTable'; import { expect } from './chai-config.spec'; import { StringType } from './types/StringType'; @@ -13,36 +14,36 @@ describe('SymbolTable', () => { it('is case insensitive', () => { const st = new SymbolTable('Child'); - st.addSymbol('foo', null, new StringType()); - expect(st.getSymbol('FOO').length).eq(1); - expect(st.getSymbol('FOO')[0].type.toString()).eq('string'); + st.addSymbol('foo', null as any, new StringType()); + expect(st.getSymbol('FOO')!.length).eq(1); + expect(st.getSymbol('FOO')![0].type.toString()).eq('string'); }); it('stores all previous symbols', () => { const st = new SymbolTable('Child'); - st.addSymbol('foo', null, new StringType()); - st.addSymbol('foo', null, new IntegerType()); - expect(st.getSymbol('FOO').length).eq(2); + st.addSymbol('foo', null as any, new StringType()); + st.addSymbol('foo', null as any, new IntegerType()); + expect(st.getSymbol('FOO')!.length).eq(2); }); it('reads from parent symbol table if not found in current', () => { const st = new SymbolTable('Child', () => parent); - parent.addSymbol('foo', null, new StringType()); - expect(st.getSymbol('foo')[0].type.toString()).eq('string'); + parent.addSymbol('foo', null as any, new StringType()); + expect(st.getSymbol('foo')![0].type.toString()).eq('string'); }); it('reads from current table if it exists', () => { const st = new SymbolTable('Child', () => parent); - parent.addSymbol('foo', null, new StringType()); - st.addSymbol('foo', null, new IntegerType()); - expect(st.getSymbol('foo')[0].type.toString()).eq('integer'); + parent.addSymbol('foo', null as any, new StringType()); + st.addSymbol('foo', null as any, new IntegerType()); + expect(st.getSymbol('foo')![0].type.toString()).eq('integer'); }); it('correct checks if a symbol is in the table using hasSymbol', () => { const child = new SymbolTable('Child', () => parent); - parent.addSymbol('foo', null, new StringType()); - child.addSymbol('bar', null, new IntegerType()); + parent.addSymbol('foo', null as any, new StringType()); + child.addSymbol('bar', null as any, new IntegerType()); expect(parent.hasSymbol('foo')).to.be.true; expect(parent.hasSymbol('bar')).to.be.false; expect(child.hasSymbol('foo')).to.be.true; @@ -54,25 +55,25 @@ describe('SymbolTable', () => { it('adds each symbol to the table', () => { const st = new SymbolTable('Child'); - st.addSymbol('foo', null, new StringType()); + st.addSymbol('foo', null as any, new StringType()); const otherTable = new SymbolTable('OtherTable'); - otherTable.addSymbol('bar', null, new IntegerType()); - otherTable.addSymbol('foo', null, new IntegerType()); + otherTable.addSymbol('bar', null as any, new IntegerType()); + otherTable.addSymbol('foo', null as any, new IntegerType()); st.mergeSymbolTable(otherTable); }); }); it('searches siblings before parents', () => { - parent.addSymbol('alpha', null, new StringType()); + parent.addSymbol('alpha', null as any, new StringType()); const child = new SymbolTable('Child', () => parent); const sibling = new SymbolTable('Sibling'); child.addSibling(sibling); - sibling.addSymbol('alpha', null, new BooleanType()); + sibling.addSymbol('alpha', null as any, new BooleanType()); expect( - child.getSymbol('alpha').map(x => x.type.toTypeString()) + child.getSymbol('alpha')!.map(x => x.type.toTypeString()) ).to.eql([ 'boolean' ]); diff --git a/src/XmlScope.spec.ts b/src/XmlScope.spec.ts index a8141c609..3e0e97959 100644 --- a/src/XmlScope.spec.ts +++ b/src/XmlScope.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { expect } from './chai-config.spec'; import { Position, Range } from 'vscode-languageserver'; import { DiagnosticMessages } from './DiagnosticMessages'; @@ -40,7 +41,7 @@ describe('XmlScope', () => { `); - let childScope = program.getComponentScope('Child'); + let childScope = program.getComponentScope('Child')!; program.validate(); @@ -86,7 +87,7 @@ describe('XmlScope', () => { `); program.validate(); - expect(program.getComponentScope('Child').getOwnFiles()[0]).to.equal(xmlFile); + expect(program.getComponentScope('Child')!.getOwnFiles()[0]).to.equal(xmlFile); }); }); @@ -113,7 +114,7 @@ describe('XmlScope', () => { end sub `); program.validate(); - let childScope = program.getComponentScope('child'); + let childScope = program.getComponentScope('child')!; expectDiagnostics(childScope, [{ ...DiagnosticMessages.xmlFunctionNotFound('func2'), range: Range.create(4, 24, 4, 29) @@ -157,7 +158,7 @@ describe('XmlScope', () => { end sub `); program.validate(); - expectDiagnostics(program.getComponentScope('child'), [{ + expectDiagnostics(program.getComponentScope('child')!, [{ ...DiagnosticMessages.xmlInvalidFieldType('no'), range: Range.create(4, 33, 4, 35) }, { diff --git a/src/astUtils/AstEditor.spec.ts b/src/astUtils/AstEditor.spec.ts index c1e1bda28..31da12a18 100644 --- a/src/astUtils/AstEditor.spec.ts +++ b/src/astUtils/AstEditor.spec.ts @@ -124,7 +124,7 @@ describe('AstEditor', () => { it('restores array after being removed', () => { editor.removeFromArray(obj.hobbies, 0); - editor.setProperty(obj, 'hobbies', undefined); + editor.setProperty(obj, 'hobbies', undefined as any); expect(obj.hobbies).to.be.undefined; editor.undoAll(); expect(obj.hobbies).to.eql(['gaming', 'reading', 'cycling']); @@ -139,7 +139,7 @@ describe('AstEditor', () => { editor.removeFromArray(obj.hobbies, 0); editor.removeFromArray(obj.hobbies, 0); editor.removeFromArray(obj.hobbies, 0); - editor.setProperty(obj, 'hobbies', undefined); + editor.setProperty(obj, 'hobbies', undefined as any); expect(obj).to.eql({ name: 'bob', @@ -294,9 +294,9 @@ describe('AstEditor', () => { it('edit handles missing functions', () => { //missing undo - editor.edit((data) => { }, undefined); + editor.edit((data) => { }, undefined as any); //missing edit - editor.edit(undefined, (data) => { }); + editor.edit(undefined as any, (data) => { }); //test passes if no exceptions were thrown }); diff --git a/src/astUtils/stackedVisitor.spec.ts b/src/astUtils/stackedVisitor.spec.ts index 1b0c1d0b1..3b978aa16 100644 --- a/src/astUtils/stackedVisitor.spec.ts +++ b/src/astUtils/stackedVisitor.spec.ts @@ -43,7 +43,7 @@ describe('createStackedVisitor', () => { assert(stack !== undefined, 'stack is undefined'); actual.push(`${stack.length ? stack.map(e => e.id).join('/') + '/' : ''}${item.id}`); }); - visitStruct(test1Struct, undefined, stackedVisitor); + visitStruct(test1Struct, undefined as any, stackedVisitor); expect(actual).to.deep.equal([ '1', '1/2', @@ -73,7 +73,7 @@ describe('createStackedVisitor', () => { assert(stack !== undefined, 'stack is undefined'); actual.push(`<${stack.map(e => e.id).join('/')}:${popped.id}`); }); - visitStruct(test1Struct, undefined, stackedVisitor); + visitStruct(test1Struct, undefined as any, stackedVisitor); expect(actual).to.deep.equal([ '>1:1', '>1/3:3', diff --git a/src/bscPlugin/codeActions/CodeActionsProcessor.spec.ts b/src/bscPlugin/codeActions/CodeActionsProcessor.spec.ts index f5e83ada5..56b3bcb26 100644 --- a/src/bscPlugin/codeActions/CodeActionsProcessor.spec.ts +++ b/src/bscPlugin/codeActions/CodeActionsProcessor.spec.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { expect } from '../../chai-config.spec'; import { URI } from 'vscode-uri'; import type { Range } from 'vscode-languageserver'; @@ -93,7 +95,7 @@ describe('CodeActionsProcessor', () => { util.createRange(1, 5, 1, 5) ); expect( - codeActions[0].edit.changes[URI.file(s`${rootDir}/components/comp1.xml`).toString()][0].range + codeActions[0].edit!.changes![URI.file(s`${rootDir}/components/comp1.xml`).toString()][0].range ).to.eql( util.createRange(1, 51, 1, 51) ); diff --git a/src/bscPlugin/hover/HoverProcessor.ts b/src/bscPlugin/hover/HoverProcessor.ts index 951d6d9d1..5f4c1f8f1 100644 --- a/src/bscPlugin/hover/HoverProcessor.ts +++ b/src/bscPlugin/hover/HoverProcessor.ts @@ -17,7 +17,7 @@ export class HoverProcessor { } public process() { - let hover: Hover; + let hover: Hover | null | undefined; if (isBrsFile(this.event.file)) { hover = this.getBrsFileHover(this.event.file); } else if (isXmlFile(this.event.file)) { @@ -40,7 +40,7 @@ export class HoverProcessor { return parts.join('\n'); } - private getBrsFileHover(file: BrsFile): Hover { + private getBrsFileHover(file: BrsFile): Hover | null | undefined { const scope = this.event.scopes[0]; const fence = (code: string) => util.mdFence(code, 'brightscript'); //get the token at the position @@ -127,6 +127,9 @@ export class HoverProcessor { */ private getTokenDocumentation(tokens: Token[], token?: Token) { const comments = [] as Token[]; + if (!token) { + return undefined; + } const idx = tokens?.indexOf(token); if (!idx || idx === -1) { return undefined; @@ -150,7 +153,7 @@ export class HoverProcessor { } } - private getXmlFileHover(file: XmlFile) { + private getXmlFileHover(file: XmlFile): Hover | undefined { //TODO add xml hovers return undefined; } diff --git a/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.ts b/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.ts index fc3232826..def2ffde1 100644 --- a/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.ts +++ b/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { expect } from '../../chai-config.spec'; import { SemanticTokenModifiers, SemanticTokenTypes } from 'vscode-languageserver-protocol'; import type { BrsFile } from '../../files/BrsFile'; @@ -25,7 +26,7 @@ describe('BrsFileSemanticTokensProcessor', () => { expectZeroDiagnostics(program); } const result = util.sortByRange( - program.getSemanticTokens(file.srcPath) + program.getSemanticTokens(file.srcPath)! ); //sort modifiers diff --git a/src/bscPlugin/validation/BrsFileValidator.spec.ts b/src/bscPlugin/validation/BrsFileValidator.spec.ts index d345e78ad..ad89123a3 100644 --- a/src/bscPlugin/validation/BrsFileValidator.spec.ts +++ b/src/bscPlugin/validation/BrsFileValidator.spec.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { expect } from '../../chai-config.spec'; import type { BrsFile } from '../../files/BrsFile'; import type { AALiteralExpression, DottedGetExpression } from '../../parser/Expression'; @@ -44,11 +46,11 @@ describe('BrsFileValidator', () => { end class end namespace `); - const namespace = ast.findChild(isNamespaceStatement); - const deltaClass = namespace.findChild(isClassStatement); + const namespace = ast.findChild(isNamespaceStatement)!; + const deltaClass = namespace.findChild(isClassStatement)!; expect(deltaClass.parent).to.equal(namespace.body); - const charlie = (deltaClass.parentClassName.expression as DottedGetExpression); + const charlie = (deltaClass.parentClassName!.expression as DottedGetExpression); expect(charlie.parent).to.equal(deltaClass.parentClassName); const bravo = charlie.obj as DottedGetExpression; diff --git a/src/diagnosticUtils.ts b/src/diagnosticUtils.ts index bf88de752..0a8835039 100644 --- a/src/diagnosticUtils.ts +++ b/src/diagnosticUtils.ts @@ -13,7 +13,7 @@ export function getPrintDiagnosticOptions(options: BsConfig) { let emitFullPaths = options?.emitFullPaths === true; - let diagnosticLevel = options?.diagnosticLevel || 'warn'; + let diagnosticLevel = options?.diagnosticLevel ?? 'warn'; let diagnosticSeverityMap = {} as Record; diagnosticSeverityMap.info = DiagnosticSeverity.Information; @@ -56,7 +56,7 @@ export function getPrintDiagnosticOptions(options: BsConfig) { export function printDiagnostic( options: ReturnType, severity: DiagnosticSeverity, - filePath: string, + filePath: string | undefined, lines: string[], diagnostic: BsDiagnostic, relatedInformation?: Array<{ range: Range; filePath: string; message: string }> @@ -150,7 +150,7 @@ export function getDiagnosticLine(diagnostic: BsDiagnostic, diagnosticLine: stri /** * Given a diagnostic, compute the range for the squiggly */ -export function getDiagnosticSquigglyText(line: string, startCharacter: number, endCharacter: number) { +export function getDiagnosticSquigglyText(line: string | undefined, startCharacter: number | undefined, endCharacter: number | undefined) { let squiggle: string; //fill the entire line if ( diff --git a/src/files/BrsFile.Class.spec.ts b/src/files/BrsFile.Class.spec.ts index dad7a61c6..f42076535 100644 --- a/src/files/BrsFile.Class.spec.ts +++ b/src/files/BrsFile.Class.spec.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import * as sinonImport from 'sinon'; import { Program } from '../Program'; @@ -112,7 +114,7 @@ describe('BrsFile BrighterScript classes', () => { expectZeroDiagnostics(program); let duckClass = file.parser.references.classStatements.find(x => x.name.text.toLowerCase() === 'duck'); expect(duckClass).to.exist; - expect(duckClass.memberMap['move']).to.exist; + expect(duckClass!.memberMap['move']).to.exist; }); it('supports various namespace configurations', () => { diff --git a/src/files/BrsFile.spec.ts b/src/files/BrsFile.spec.ts index 9a71d26ad..6733d0dc0 100644 --- a/src/files/BrsFile.spec.ts +++ b/src/files/BrsFile.spec.ts @@ -1,7 +1,9 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { assert, expect } from '../chai-config.spec'; import * as sinonImport from 'sinon'; import { CompletionItemKind, Position, Range } from 'vscode-languageserver'; -import type { Callable, CommentFlag, VariableDeclaration } from '../interfaces'; +import type { BsDiagnostic, Callable, CommentFlag, VariableDeclaration } from '../interfaces'; import { Program } from '../Program'; import { BooleanType } from '../types/BooleanType'; import { DynamicType } from '../types/DynamicType'; @@ -156,10 +158,10 @@ describe('BrsFile', () => { }); it('allows adding diagnostics', () => { - const expected = [{ + const expected: BsDiagnostic[] = [{ message: 'message', - file: undefined, - range: undefined + file: undefined as any, + range: undefined as any }]; file.addDiagnostics(expected); expectDiagnostics(file, expected); @@ -1334,10 +1336,10 @@ describe('BrsFile', () => { `); expect(file.callables.length).to.equal(2); expect(file.callables[0].name).to.equal('DoA'); - expect(file.callables[0].nameRange.start.line).to.equal(1); + expect(file.callables[0].nameRange!.start.line).to.equal(1); expect(file.callables[1].name).to.equal('DoA'); - expect(file.callables[1].nameRange.start.line).to.equal(5); + expect(file.callables[1].nameRange!.start.line).to.equal(5); }); it('finds function call line and column numbers', () => { @@ -2331,7 +2333,7 @@ describe('BrsFile', () => { testTranspile( 'sub main()\n name = "john \nend sub', 'sub main()\n name = "john "\nend sub', - null, + null as any, 'source/main.bs', false ); @@ -2559,7 +2561,7 @@ describe('BrsFile', () => { person = {} stuff = [] end sub - `, null, 'trim'); + `, null as any, 'trim'); }); it('does not add leading or trailing newlines', () => { @@ -2612,8 +2614,8 @@ describe('BrsFile', () => { kind: token.kind, start: Position.create( //convert source-map 1-based line to token 0-based line - originalPosition.line - 1, - originalPosition.column + originalPosition.line! - 1, + originalPosition.column! ) }; }); @@ -3398,7 +3400,7 @@ describe('BrsFile', () => { `); const parser = file['_parser']; //clear the private _parser instance - file['_parser'] = undefined; + file['_parser'] = undefined as any; //force the file to get a new instance of parser const newParser = file.parser; @@ -3514,7 +3516,7 @@ describe('BrsFile', () => { end sub `); program.validate(); - sinon.stub(util, 'getAllDottedGetParts').returns(null); + sinon.stub(util, 'getAllDottedGetParts').returns(null as any); // print alpha.be|ta expect(program.getDefinition(file.srcPath, Position.create(2, 34))).to.eql([]); }); diff --git a/src/files/XmlFile.spec.ts b/src/files/XmlFile.spec.ts index 610a9e50a..c914abb8f 100644 --- a/src/files/XmlFile.spec.ts +++ b/src/files/XmlFile.spec.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { assert, expect } from '../chai-config.spec'; import * as path from 'path'; import * as sinonImport from 'sinon'; @@ -59,13 +61,13 @@ describe('XmlFile', () => { program.plugins.add({ name: 'allows modifying the parsed XML model', afterFileParse: () => { - let child = file.parser.ast.component.children.children[0]; + let child = file.parser.ast.component!.children.children[0]; expect(child.attributes).to.have.lengthOf(4); - child.setAttribute('text', undefined); - expect(child.getAttribute('id').value.text).to.equal('one'); + child.setAttribute('text', undefined as any); + expect(child.getAttribute('id')!.value.text).to.equal('one'); expect(child.attributes).to.have.lengthOf(3); - child.setAttribute('text3', undefined); - expect(child.getAttribute('id').value.text).to.equal('one'); + child.setAttribute('text3', undefined as any); + expect(child.getAttribute('id')!.value.text).to.equal('one'); expect(child.attributes).to.have.lengthOf(2); } }); @@ -489,10 +491,10 @@ describe('XmlFile', () => { }); it('allows adding diagnostics', () => { - const expected = [{ + const expected: BsDiagnostic[] = [{ message: 'message', - file: undefined, - range: undefined + file: undefined as any, + range: undefined as any }]; file.addDiagnostics(expected); expectDiagnostics(file, expected); @@ -829,7 +831,7 @@ describe('XmlFile', () => {