Skip to content

Commit 5cf2e47

Browse files
authored
Fix TsLint errors (#7)
1 parent 5a72229 commit 5cf2e47

File tree

7 files changed

+26
-24
lines changed

7 files changed

+26
-24
lines changed

src/AST/ASTExpression.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import ASTNode from './ASTNode';
77

88
// ASTExpression is the base node for expressions.
9+
10+
// tslint:disable-next-line:no-empty-interface
911
interface ASTExpression extends ASTNode {}
1012

1113
export default ASTExpression;

src/AST/ASTStatement.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import ASTNode from './ASTNode';
77

8-
/**
9-
* ASTStatement represents a statement.
10-
* All nodes in a Program are statements.
11-
*/
8+
// ASTStatement represents a statement.
9+
// All nodes in a Program are statements.
10+
11+
// tslint:disable-next-line:no-empty-interface
1212
interface ASTStatement extends ASTNode {}
1313

1414
export default ASTStatement;

src/AST/Program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ASTNode from './ASTNode';
77

88
// Program is the root node of the abstract syntax tree representing the JSL input.
99
class Program implements ASTNode {
10-
statements: Array<ASTNode>;
10+
statements: ASTNode[];
1111

1212
constructor() {
1313
this.statements = [];

src/JSLEvaluator.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class JSLEvaluator {
2424
case ASTIntegerLiteral:
2525
return this.evaluateIntegerExpression(node as ASTIntegerLiteral);
2626
default:
27-
throw `${node.tokenLiteral()} node evaluation not supported`;
27+
throw new Error(`${node.tokenLiteral()} node evaluation not supported`);
2828
}
2929
}
3030

@@ -39,7 +39,7 @@ class JSLEvaluator {
3939
private evaluateExpressionStatement(statement: ASTExpressionStatement, json: any): any {
4040
const expression = statement.expression;
4141
if (!expression) {
42-
throw `Expression: ${statement.toString()} not found`;
42+
throw new Error(`Expression: ${statement.toString()} not found`);
4343
}
4444

4545
return this.evaluate(json, expression);
@@ -49,12 +49,12 @@ class JSLEvaluator {
4949

5050
private evaluateSelectExpression(expression: ASTSelectExpression, json: any): any {
5151
if (typeof json !== 'object') {
52-
throw `Invalid nested key sequence ${expression.key}`;
52+
throw new Error(`Invalid nested key sequence ${expression.key}`);
5353
}
5454

5555
const key: string = expression.key;
5656
if (!json.hasOwnProperty(key)) {
57-
throw `Key not found in the json: ${expression.key}`;
57+
throw new Error(`Key not found in the json: ${expression.key}`);
5858
}
5959

6060
return json[key];
@@ -64,7 +64,7 @@ class JSLEvaluator {
6464
const left = expression.left;
6565
const index = expression.index;
6666
if (!left || !index) {
67-
throw `Expression: ${expression.toString()} not found`;
67+
throw new Error(`Expression: ${expression.toString()} not found`);
6868
}
6969

7070
const arr: any = this.evaluate(json, left);
@@ -73,7 +73,7 @@ class JSLEvaluator {
7373
return arr[idx];
7474
}
7575

76-
throw `cannot subscript at ${expression.toString()}[${idx}]`;
76+
throw new Error(`cannot subscript at ${expression.toString()}[${idx}]`);
7777
}
7878

7979
private evaluateIntegerExpression(expression: ASTIntegerLiteral): number {

src/Lexer.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { dot, int, ident, lbracket, rbracket, eof, Token } from './tokens';
77

88
// Lexer represents the lexical analyzer for JSON Selector Language
99
class Lexer {
10-
private input: Array<string> = [];
10+
private input: string[] = [];
1111
private position: number = 0;
1212
private readPosition: number = 0;
1313
private currentCharacter: string = '';
@@ -73,27 +73,27 @@ class Lexer {
7373

7474
// readIdentifier returns a token with an identifier as the literal
7575
private readIdentifier(): Token {
76-
let startIdx = this.position;
76+
const startIdx = this.position;
7777
while (this.isIdent(this.currentCharacter)) {
7878
this.readChar();
7979
}
8080

81-
const identfier: Array<string> = this.input.slice(startIdx, this.position);
82-
const identStr: string = identfier.join('');
81+
const identifier: string[] = this.input.slice(startIdx, this.position);
82+
const identStr: string = identifier.join('');
8383

8484
return { type: ident, literal: identStr };
8585
}
8686

8787
// readNumber returns a token with a numeric literal
8888
private readNumber(): string {
89-
let startIdx = this.position;
89+
const startIdx = this.position;
9090
while (this.isNumeric(this.currentCharacter)) {
9191
this.readChar();
9292
}
9393

94-
const number: Array<string> = this.input.slice(startIdx, this.position);
94+
const num: string[] = this.input.slice(startIdx, this.position);
9595

96-
return number.join('');
96+
return num.join('');
9797
}
9898

9999
// isIdent returns true if a character is not one of the other tokens

src/Parser.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type InfixParser = (arg?: ASTExpression) => ASTExpression | undefined;
2525

2626
class Parser {
2727
private lexer: Lexer;
28-
private errors: Array<string> = [];
28+
private errors: string[] = [];
2929

3030
private curToken!: Token;
3131
private peekToken!: Token;
@@ -53,7 +53,7 @@ class Parser {
5353
}
5454

5555
parseProgram(): Program {
56-
let program = new Program();
56+
const program = new Program();
5757

5858
while (!this.isCurToken(eof)) {
5959
const stmt = this.parseStatement();
@@ -107,7 +107,7 @@ class Parser {
107107
);
108108
}
109109

110-
private noPrefixParseFuncErr(type: String): void {
110+
private noPrefixParseFuncErr(type: string): void {
111111
this.errors.push(`prefix parse func for ${type} not found`);
112112
}
113113

@@ -178,7 +178,7 @@ class Parser {
178178
return;
179179
}
180180

181-
let idx = this.parseExpression(Precedence.lowest);
181+
const idx = this.parseExpression(Precedence.lowest);
182182
if (!this.expectPeek(rbracket)) {
183183
return;
184184
}

src/__tests__/JSLEvaluator.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ describe('JSLEvaluator', () => {
8383
fail();
8484
}
8585

86-
const testCase = 'Key not found in the json: width';
86+
const testCase = new Error('Key not found in the json: width');
8787
expect(returnedError).toEqual(testCase);
8888
});
8989

9090
it('tests with invalid jsl input', () => {
9191
const input = '..[]';
9292
const json = { data: [{}, {}, { width: 200 }] };
93-
let returnedError: Array<string> = [];
93+
let returnedError: string[] = [];
9494

9595
try {
9696
const program = JSL.compile(input);

0 commit comments

Comments
 (0)