Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix eslint issues
  • Loading branch information
kunle committed Dec 11, 2018
1 parent 11b0d76 commit 4d02f24
Show file tree
Hide file tree
Showing 31 changed files with 64 additions and 64 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -2,3 +2,4 @@
.vscode
.github
/node_modules
/src/tests
10 changes: 5 additions & 5 deletions src/environment.js
Expand Up @@ -7,33 +7,33 @@ class Environment {
}

setJeki (scope, name, value) {
if (this.vars[scope] == undefined) {
if (!this.vars[scope]) {
this.vars[scope] = {};
}

this.vars[scope][name] = value;
}

getJeki (scope, name) {
if (this.vars[scope] != undefined) { return this.vars[scope][name]; }
if (this.vars[scope]) { return this.vars[scope][name]; }
}

setIse (scope, iseName, iseNode) {
if (this.iseDeclarations[scope] == undefined) {
if (!this.iseDeclarations[scope]) {
this.iseDeclarations[scope] = {};
}

this.iseDeclarations[scope][iseName] = iseNode;
}

getIse (scope, iseName) {
if (this.iseDeclarations[scope] != undefined) {
if (this.iseDeclarations[scope]) {
return this.iseDeclarations[scope][iseName];
}
}

isExistHelperIse (iseName) {
return helperIseDeclarations[iseName] != undefined;
return helperIseDeclarations[iseName] !== undefined;
}

runHelperIse (iseName, iseArgs) {
Expand Down
2 changes: 1 addition & 1 deletion src/helperise/array_helpers/ka.js
@@ -1,7 +1,7 @@
// Get array length
function ka (args) {
if (args instanceof Array) {
const [param, ] = args;
const [ param, ] = args;
if (param instanceof Array) return param.length;

throw new Error("Invalid param given to helper ise ka.");
Expand Down
2 changes: 1 addition & 1 deletion src/helperise/input_output/tesibi.js
Expand Up @@ -3,7 +3,7 @@ const readlineSync = require("readline-sync");
// Takes command line input
function teSibi (args) {
if (args instanceof Array) {
const [param, ] = args;
const [ param, ] = args;
if (typeof param === "string") {
const input = readlineSync.question(param);
return parseFloat(input) || input;
Expand Down
2 changes: 1 addition & 1 deletion src/helperise/string_helpers/si_leta_kekere.js
@@ -1,7 +1,7 @@
// Convert String to lower case
function siLetaKekere (args) {
if (args instanceof Array) {
const [param, ] = args;
const [ param, ] = args;
if (typeof param === "string") return param.toLowerCase();

throw new Error("Invalid param given to helper ise síLẹ́tàkékeré.");
Expand Down
2 changes: 1 addition & 1 deletion src/helperise/string_helpers/si_leta_nla.js
@@ -1,7 +1,7 @@
// Convert String to upper case
function siLetaNla (args) {
if (args instanceof Array) {
const [param, ] = args;
const [ param, ] = args;
if (typeof param === "string") return param.toUpperCase();

throw new Error("Invalid param given to helper ise síLẹ́tàŃlá.");
Expand Down
4 changes: 2 additions & 2 deletions src/inputstream.js
Expand Up @@ -41,11 +41,11 @@ class InputStream {
}

isEndOfFile () {
return this.peek() == "";
return this.peek() === "";
}

isNotEndOfFile () {
return this.peek() != "";
return this.peek() !== "";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/helpers/woke_helper.js
Expand Up @@ -3,7 +3,7 @@ const constants = require("../../constants.js");
class WokeHelper {
static isWokeVariable (context, tiName) {
const wokeList = context.environment().getJeki(context.getCurrentScope(), constants.KW.WOKE);
return wokeList != undefined && wokeList.indexOf(tiName) != -1;
return wokeList && wokeList.indexOf(tiName) !== -1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/ibase.js
@@ -1,6 +1,6 @@
class IBase {
constructor () {
if (this.constructor == IBase) {
if (this.constructor === IBase) {
throw new Error("Cannot instantiate abstract class IBase");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/inodearrayelem.js
Expand Up @@ -23,7 +23,7 @@ class INodeArrayElement extends IBase {
}
});

if (arrayElement == undefined) context.throwError(`Index given for array ${node.name} does not exist`);
if (!arrayElement) context.throwError(`Index given for array ${node.name} does not exist`);

return arrayElement;
}
Expand Down
5 changes: 2 additions & 3 deletions src/interpreters/inodecallise.js
@@ -1,5 +1,4 @@
const IBase = require("./ibase.js");
const constants = require("../constants.js");

class INodeCallIse extends IBase {
interpreteNode (node) {
Expand All @@ -21,7 +20,7 @@ class INodeCallIse extends IBase {

static getIseNode (context, iseName) {
for (let index = context.scopeStack().length - 1; index >= 0; index--) {
if (context.environment().getIse(context.scopeStack()[index], iseName) != undefined) {
if (context.environment().getIse(context.scopeStack()[index], iseName) !== undefined) {
return context.environment().getIse(context.scopeStack()[index], iseName);
}
}
Expand All @@ -45,7 +44,7 @@ class INodeCallIse extends IBase {
static runIseNodeBody (context, iseNodeBody) {
for (let i = 0; i < iseNodeBody.length; i++) {
const returnedValue = context.evaluateNode(iseNodeBody[i]);
if (returnedValue != undefined) return returnedValue;
if (returnedValue !== undefined) return returnedValue;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/inodefun.js
Expand Up @@ -9,7 +9,7 @@ class INodeFun extends IBase {
for (let i = 0; i < node.body.length; i++) {
const returnedValue = this.evaluateNode(node.body[i]);
if (returnedValue === constants.KW.KURO) return;
if (returnedValue != undefined) return returnedValue;
if (returnedValue !== undefined) return returnedValue;
}

this.evaluateNode(node.increment);
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/inodegetjeki.js
Expand Up @@ -4,7 +4,7 @@ const WokeHelper = require("./helpers/woke_helper.js");
class INodeGetJeki extends IBase {
interpreteNode (node) {
for (let index = INodeGetJeki.getTopIndex(this, node.name); index >= 0; index--) {
if (this.environment().getJeki(this.scopeStack()[index], node.name) != undefined) {
if (this.environment().getJeki(this.scopeStack()[index], node.name) !== undefined) {
return this.environment().getJeki(this.scopeStack()[index], node.name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/inodeise.js
Expand Up @@ -2,7 +2,7 @@ const IBase = require("./ibase.js");

class INodeIse extends IBase {
interpreteNode (node) {
if (this.environment().getIse(this.getCurrentScope(), node.name) != undefined) { this.throwError(`Ise with name ${node.name} already exists within the ${this.getCurrentScope()} scope`); }
if (this.environment().getIse(this.getCurrentScope(), node.name) !== undefined) { this.throwError(`Ise with name ${node.name} already exists within the ${this.getCurrentScope()} scope`); }

this.environment().setIse(this.getCurrentScope(), node.name, node);
}
Expand Down
6 changes: 3 additions & 3 deletions src/interpreters/inodejeki.js
Expand Up @@ -21,7 +21,7 @@ class INodeJeki extends IBase {
const topIndex = context.scopeStack().length - 2;

for (let index = topIndex; index >= 0; index--) {
if (context.environment().getJeki(context.scopeStack()[index], node.left) != undefined) {
if (context.environment().getJeki(context.scopeStack()[index], node.left) !== undefined) {
return context.environment().setJeki(context.scopeStack()[index], node.left, INodeJeki.getValue(context, node.right));
}
}
Expand All @@ -33,7 +33,7 @@ class INodeJeki extends IBase {
for (let i = 0; i < node.left.indexNodes.length; i++) {
const arrayIndex = context.evaluateNode(node.left.indexNodes[i]);

if (arrayIndex === "" && i == node.left.indexNodes.length - 1) {
if (arrayIndex === "" && i === node.left.indexNodes.length - 1) {
// push right node to the last location in the array when index is empty
arrayLiteral.push(context.evaluateNode(node.right));
return;
Expand Down Expand Up @@ -64,7 +64,7 @@ class INodeJeki extends IBase {

static getValue (context, node) {
const value = context.evaluateNode(node);
if (value == undefined) context.throwError(`Cannot set value undefined to variable ${node.left}`);
if (value === undefined) context.throwError(`Cannot set value undefined to variable ${node.left}`);
return value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/inodenigbati.js
Expand Up @@ -7,7 +7,7 @@ class INodeNigbati extends IBase {
for (let i = 0; i < node.body.length; i++) {
const returnedValue = this.evaluateNode(node.body[i]);
if (returnedValue === constants.KW.KURO) return;
if (returnedValue != undefined) return returnedValue;
if (returnedValue !== undefined) return returnedValue;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/interpreters/inodese.js
Expand Up @@ -5,7 +5,7 @@ class INodeSe extends IBase {
interpreteNode (node) {
if (this.evaluateNode(node.condition) !== constants.KW.IRO) {
return INodeSe.runBody(this, node.then);
} else if (node.else != undefined) {
} else if (node.else !== undefined) {
return INodeSe.runBody(this, node.else);
}
}
Expand All @@ -16,7 +16,7 @@ class INodeSe extends IBase {

for (let i = 0; i < body.length; i++) {
const returnedValue = context.evaluateNode(body[i]);
if (returnedValue != undefined) return returnedValue; // it's an ise pada value or kuro statement
if (returnedValue !== undefined) return returnedValue; // it's an ise pada value or kuro statement
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/inodewoke.js
Expand Up @@ -5,7 +5,7 @@ class INodeWoke extends IBase {
interpreteNode (node) {
let woke = this.environment().getJeki(this.getCurrentScope(), constants.KW.WOKE);

if (woke == undefined) woke = node.varNames;
if (!woke) woke = node.varNames;
else woke.push(...node.varNames);

this.environment().setJeki(this.getCurrentScope(), constants.KW.WOKE, woke);
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/inodeyi.js
Expand Up @@ -27,7 +27,7 @@ class INodeYi extends IBase {
}

static canRunPadasi (IRUIndex, node) {
return (IRUIndex === node.yibody.length - 1) && (node.padasi != undefined);
return (IRUIndex === node.yibody.length - 1) && (node.padasi !== undefined);
}

static runPadasi (context, padasi) {
Expand Down
4 changes: 2 additions & 2 deletions src/interpreters/maininterpreter.js
Expand Up @@ -10,9 +10,9 @@ class MainInterpreter {
}

initScopeStack () {
const _scopeStack = ["global", ];
const _scopeStack = [ "global", ];
this.getCurrentScope = () => _scopeStack[_scopeStack.length - 1];
this.scopeStack = () => [..._scopeStack, ];
this.scopeStack = () => [ ..._scopeStack, ];
this.pushToScopeStack = (scope) => _scopeStack.push(scope);
this.popFromScopeStack = () => _scopeStack.pop();
}
Expand Down
12 changes: 6 additions & 6 deletions src/lexer.js
Expand Up @@ -44,10 +44,10 @@ class Lexer {
const stringEnd = constants.SYM.STR_QUOTE;
this.inputStream.next(); // needed to skip the opening quote symbol '"'
const str = this.readWhile((ch) => {
return ch != stringEnd;
return ch !== stringEnd;
});

if (this.inputStream.peek() == stringEnd) { this.inputStream.next(); } // needed to skip the closing quote symbol '"'
if (this.inputStream.peek() === stringEnd) this.inputStream.next();// needed to skip the closing quote symbol '"'
else { this.throwError(`Expecting '${stringEnd}' but found unexpected char`); }

return { type: constants.STRING, value: str, };
Expand All @@ -69,7 +69,7 @@ class Lexer {
readNumber () {
let hasDot = false;
const num = this.readWhile((ch) => {
if (ch == constants.SYM.PERIOD) {
if (ch === constants.SYM.PERIOD) {
if (hasDot) return false;
hasDot = true;
return true;
Expand All @@ -82,7 +82,7 @@ class Lexer {

skipComments () {
this.readWhile((ch) => {
return ch != constants.SYM.NEW_LINE;
return ch !== constants.SYM.NEW_LINE;
});
this.inputStream.next(); // skips the "\n" symbol
}
Expand All @@ -92,11 +92,11 @@ class Lexer {
if (this.inputStream.isEndOfFile()) return null;

const ch = this.inputStream.peek();
if (ch == constants.SYM.COMMENT) {
if (ch === constants.SYM.COMMENT) {
this.skipComments();
return this.readNext();
}
if (ch == constants.SYM.STR_QUOTE) return this.readString();
if (ch === constants.SYM.STR_QUOTE) return this.readString();
if (this.isDigit(ch)) return this.readNumber();
if (this.isIdentifier(ch)) return this.readIdentifier();
if (this.isPunctuation(ch)) return { type: constants.PUNCTUATION, value: this.inputStream.next(), };
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/basenode.js
@@ -1,7 +1,7 @@
class BaseNode {
// Make BaseNode act like an interface.
constructor () {
if (this.constructor == BaseNode) {
if (this.constructor === BaseNode) {
throw new Error("Cannot instantiate abstract class BaseNode");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/keywordnodes/kwnodefun.js
Expand Up @@ -40,11 +40,11 @@ class KwNodeFun extends BaseNode {
static isInValidFunIncrementStatement (funNode) {
const incrementNode = funNode.increment.right;

if ([constants.SYM.PLUS, constants.SYM.MINUS, ].indexOf(incrementNode.operation) >= 0) {
if ([ constants.SYM.PLUS, constants.SYM.MINUS, ].indexOf(incrementNode.operation) >= 0) {
// e.g fun (tí i =0; i < 10; tí i = i + 1;)
// make sure there is variable 'i' in atleast one child of the incrementNode
// i.e jeki i = i + 1 or jeki i = 1 + i or jeki i = i + i
if ([incrementNode.left.name, incrementNode.right.name, ].indexOf(funNode.init.left) >= 0) {
if ([ incrementNode.left.name, incrementNode.right.name, ].indexOf(funNode.init.left) >= 0) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/keywordnodes/kwnodegbewole.js
Expand Up @@ -9,9 +9,9 @@ class KwNodeGbeWole extends BaseNode {
const node = {};
node.operation = constants.KW.GBE_WOLE;

if (this.lexer().peek().type == constants.STRING) {
if (this.lexer().peek().type === constants.STRING) {
node.path = leafnl.getNode.call(this);
if (path.extname(node.path.value) != constants.YL_EXT) { this.throwError("Invalid yorlang file. Expected file with .yl extension"); }
if (path.extname(node.path.value) !== constants.YL_EXT) { this.throwError("Invalid yorlang file. Expected file with .yl extension"); }

this.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR);
return node;
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/keywordnodes/kwnodeise.js
Expand Up @@ -11,7 +11,7 @@ class KwNodeIse extends BaseNode {
}

static isExpectedIseDeclaration (context) {
return context.getBlockTypeStack().length == 0 || context.peekBlockTypeStack() === constants.PROGRAM ||
return context.getBlockTypeStack().length === 0 || context.peekBlockTypeStack() === constants.PROGRAM ||
context.peekBlockTypeStack() === constants.KW.ISE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/parsers/keywordnodes/kwnodeyi.js
Expand Up @@ -36,7 +36,7 @@ class KwNodeYi extends BaseNode {
}

static isNextTokenIru (context) {
return context.isNotEndOfFile() && context.lexer().peek().value == constants.KW.IRU;
return context.isNotEndOfFile() && context.lexer().peek().value === constants.KW.IRU;
}

static getPadasi (context) {
Expand Down
6 changes: 3 additions & 3 deletions src/parsers/nodeLiterals/arraynl.js
Expand Up @@ -3,7 +3,7 @@ const constants = require("../../constants.js");

class ArrayNl extends BaseNode {
getNode (arrayNameToken) {
return (arrayNameToken == undefined) ? ArrayNl.getParsedArrayLiteral(this)
return (!arrayNameToken) ? ArrayNl.getParsedArrayLiteral(this)
: ArrayNl.getParsedArrayElement(this, arrayNameToken);
}

Expand All @@ -28,7 +28,7 @@ class ArrayNl extends BaseNode {
}

static getArrayElementIndexNodes (context) {
const indexNodes = [ArrayNl.getArrayElementIndexNode(context), ];
const indexNodes = [ ArrayNl.getArrayElementIndexNode(context), ];

while (context.isNextTokenPunctuation(constants.SYM.L_SQ_BRACKET)) { // handles multi-dimensional array element
indexNodes.push(ArrayNl.getArrayElementIndexNode(context));
Expand All @@ -48,7 +48,7 @@ class ArrayNl extends BaseNode {
}

static isNotEmptyArrayIndex (context) {
return context.lexer().peek().value != constants.SYM.R_SQ_BRACKET;
return context.lexer().peek().value !== constants.SYM.R_SQ_BRACKET;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parsers/nodeLiterals/callIseNl.js
Expand Up @@ -20,7 +20,7 @@ class CallIseNl extends BaseNode {
this.parseExpression.bind(this), null
);

if (iseNameToken.value == undefined) this.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR);
if (iseNameToken.value === undefined) this.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR);

return node;
}
Expand Down

0 comments on commit 4d02f24

Please sign in to comment.