Skip to content

Commit

Permalink
updates per PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjunker committed Jan 2, 2024
1 parent bb97a0c commit 82dabc3
Show file tree
Hide file tree
Showing 36 changed files with 58 additions and 138 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = {
'@typescript-eslint/no-implicit-any-catch': 'off',
'@typescript-eslint/no-invalid-this': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
//had to add this rule to prevent eslint from crashing
'@typescript-eslint/no-restricted-imports': ['off', {}],
Expand All @@ -61,6 +62,7 @@ module.exports = {
'@typescript-eslint/no-type-alias': 'off',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
Expand Down Expand Up @@ -240,8 +242,6 @@ module.exports = {
files: ['benchmarks/**/*.ts'],
rules: {
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'camelcase': 'off'
}
}]
Expand Down
5 changes: 0 additions & 5 deletions src/CodeActionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export class CodeActionUtil {
for (const change of obj.changes) {
const uri = URI.file(change.filePath).toString();

//justification: `edit` is defined above so we know that `edit.changes` is defined.
/* eslint-disable @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion */

//create the edit changes array for this uri
if (!edit.changes![uri]) {
edit.changes![uri] = [];
Expand All @@ -27,8 +24,6 @@ export class CodeActionUtil {
TextEdit.replace(change.range, change.newText)
);
}

/* eslint-enable @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion */
}
const action = CodeAction.create(obj.title, edit, obj.kind);
action.isPreferred = obj.isPreferred;
Expand Down
2 changes: 1 addition & 1 deletion src/DiagnosticFilterer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class DiagnosticFilterer {
let fileDiagnostics = this.byFile[filePath];
for (let i = 0; i < fileDiagnostics.length; i++) {
let diagnostic = fileDiagnostics[i];
if (diagnostic.code && filter.codes.includes(diagnostic.code)) {
if (filter.codes.includes(diagnostic.code!)) {
//remove this diagnostic
fileDiagnostics.splice(i, 1);
//repeat this loop iteration (with the new item at this index)
Expand Down
2 changes: 0 additions & 2 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
import { expect } from './chai-config.spec';
import * as fsExtra from 'fs-extra';
import * as path from 'path';
Expand Down
6 changes: 2 additions & 4 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* 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';
Expand Down Expand Up @@ -266,11 +264,11 @@ describe('Program', () => {
});

it('allows adding diagnostics', () => {
const expected: BsDiagnostic[] = [{
const expected = [{
message: 'message',
file: undefined,
range: undefined
}] as any;
}] as any as BsDiagnostic[];
program.addDiagnostics(expected);
const actual = (program as any).diagnostics;
expect(actual).to.deep.equal(expected);
Expand Down
1 change: 0 additions & 1 deletion src/Scope.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* 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';
Expand Down
1 change: 0 additions & 1 deletion src/SymbolTable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { SymbolTable } from './SymbolTable';
import { expect } from './chai-config.spec';
import { StringType } from './types/StringType';
Expand Down
1 change: 0 additions & 1 deletion src/XmlScope.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { expect } from './chai-config.spec';
import { Position, Range } from 'vscode-languageserver';
import { DiagnosticMessages } from './DiagnosticMessages';
Expand Down
2 changes: 0 additions & 2 deletions src/bscPlugin/codeActions/CodeActionsProcessor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* 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';
Expand Down
6 changes: 3 additions & 3 deletions src/bscPlugin/hover/HoverProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class HoverProcessor {
}

public process() {
let hover: Hover | null | undefined;
let hover: Hover | undefined;
if (isBrsFile(this.event.file)) {
hover = this.getBrsFileHover(this.event.file);
} else if (isXmlFile(this.event.file)) {
Expand All @@ -40,7 +40,7 @@ export class HoverProcessor {
return parts.join('\n');
}

private getBrsFileHover(file: BrsFile): Hover | null | undefined {
private getBrsFileHover(file: BrsFile): Hover | undefined {
const scope = this.event.scopes[0];
const fence = (code: string) => util.mdFence(code, 'brightscript');
//get the token at the position
Expand All @@ -56,7 +56,7 @@ export class HoverProcessor {

//throw out invalid tokens and the wrong kind of tokens
if (!token || !hoverTokenTypes.includes(token.kind)) {
return null;
return undefined;
}

const expression = file.getClosestExpression(this.event.position);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* 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';
Expand Down
2 changes: 0 additions & 2 deletions src/bscPlugin/validation/BrsFileValidator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* 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';
Expand Down
2 changes: 0 additions & 2 deletions src/files/BrsFile.Class.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* 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';
Expand Down
2 changes: 0 additions & 2 deletions src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* 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';
Expand Down
2 changes: 0 additions & 2 deletions src/files/XmlFile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* 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';
Expand Down
2 changes: 0 additions & 2 deletions src/files/tests/imports.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { expect } from '../../chai-config.spec';
import * as sinonImport from 'sinon';
import * as fsExtra from 'fs-extra';
Expand Down
1 change: 0 additions & 1 deletion src/parser/AstNode.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { util } from '../util';
import * as fsExtra from 'fs-extra';
import { Program } from '../Program';
Expand Down
10 changes: 4 additions & 6 deletions src/parser/AstNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ export abstract class AstNode {
if (node.symbolTable) {
return node.symbolTable;
}
//justification: we are following a chain of nodes until we get to one with a SymbolTable,
//and the top-level node will always have a SymbolTable
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
node = node.parent!;
}

//justification: based on the reasoning above we will always find a SymbolTable,
//but we have no way to convince the typechecker of this.
//justification: we are following a chain of nodes until we get to one with a SymbolTable,
//and the top-level node will always have a SymbolTable. So we'll never hit this undefined,
//but it is not so easy to convince the typechecker of this.
return undefined as any;
}

Expand Down Expand Up @@ -133,7 +131,7 @@ export abstract class Statement extends AstNode {
/**
* Annotations for this statement
*/
public annotations: AnnotationExpression[] = [];
public annotations: AnnotationExpression[] | undefined;
}


Expand Down
2 changes: 1 addition & 1 deletion src/parser/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class FunctionExpression extends Expression implements TypedefProvider {
super();
if (this.returnTypeToken) {
this.returnType = util.tokenToBscType(this.returnTypeToken);
} else if (this.functionType && this.functionType.text.toLowerCase() === 'sub') {
} else if (this.functionType?.text.toLowerCase() === 'sub') {
this.returnType = new VoidType();
} else {
this.returnType = DynamicType.instance;
Expand Down
2 changes: 0 additions & 2 deletions src/parser/Parser.Class.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { expect } from '../chai-config.spec';
import { DiagnosticMessages } from '../DiagnosticMessages';
import { TokenKind, AllowedLocalIdentifiers, AllowedProperties } from '../lexer/TokenKind';
Expand Down
Loading

0 comments on commit 82dabc3

Please sign in to comment.