Skip to content

Commit

Permalink
fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
kunle committed Dec 11, 2018
1 parent 200e7c4 commit 11b0d76
Show file tree
Hide file tree
Showing 111 changed files with 913 additions and 991 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
@@ -0,0 +1,4 @@
/docs
.vscode
.github
/node_modules
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -9,8 +9,8 @@
"test": "jest",
"coverage": "node_modules/.bin/jest --coverage",
"link": "npm link",
"lint": "eslint ./ --color",
"lint:fix": "eslint ./ --fix"
"lint": "eslint ./src --color",
"lint:fix": "eslint ./src --fix"
},
"devDependencies": {
"eslint": "5.9.0",
Expand Down
22 changes: 10 additions & 12 deletions src/environment.js
@@ -1,52 +1,50 @@
const helperIseDeclarations = require("./helperise/registeredHelperIse.js");

class Environment {

constructor() {
constructor () {
this.vars = {};
this.iseDeclarations = {};
}

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

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

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

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

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

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

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

runHelperIse(iseName, iseArgs) {
runHelperIse (iseName, iseArgs) {
if (this.isExistHelperIse(iseName)) {
return helperIseDeclarations[iseName](iseArgs);
}
}

sope(value) {
sope (value) {
console.log(value);
}
}

module.exports = Environment;
module.exports = Environment;
16 changes: 8 additions & 8 deletions src/helperise/array_helpers/ka.js
@@ -1,13 +1,13 @@
//Get array length
function ka(args) {
// 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.`);
}
throw new Error('Yorlang system error');
throw new Error("Invalid param given to helper ise ka.");
}

throw new Error("Yorlang system error");
}

module.exports = ka;
module.exports = ka;
22 changes: 11 additions & 11 deletions src/helperise/input_output/tesibi.js
@@ -1,18 +1,18 @@
const readlineSync = require('readline-sync');
const readlineSync = require("readline-sync");

//Takes command line input
function teSibi(args) {
// Takes command line input
function teSibi (args) {
if (args instanceof Array) {
const [param] = args;
if (typeof param === "string"){
const [param, ] = args;
if (typeof param === "string") {
const input = readlineSync.question(param);
return parseFloat(input) || input;
}
}

throw new Error (`Invalid param given to helper ise teSibi.`);
}
throw new Error('Yorlang system error');
throw new Error("Invalid param given to helper ise teSibi.");
}

throw new Error("Yorlang system error");
}

module.exports = teSibi;
module.exports = teSibi;
2 changes: 1 addition & 1 deletion src/helperise/registeredHelperIse.js
Expand Up @@ -4,4 +4,4 @@ helperIseDeclarations["siLetaNla"] = require("./string_helpers/si_leta_nla.js");
helperIseDeclarations["siLetaKekere"] = require("./string_helpers/si_leta_kekere.js");
helperIseDeclarations["teSibi"] = require("./input_output/tesibi.js");

module.exports = helperIseDeclarations;
module.exports = helperIseDeclarations;
16 changes: 8 additions & 8 deletions src/helperise/string_helpers/si_leta_kekere.js
@@ -1,13 +1,13 @@
//Convert String to lower case
function siLetaKekere(args) {
// 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é.`);
}
throw new Error('Yorlang system error');
throw new Error("Invalid param given to helper ise síLẹ́tàkékeré.");
}

throw new Error("Yorlang system error");
}

module.exports = siLetaKekere;
module.exports = siLetaKekere;
16 changes: 8 additions & 8 deletions src/helperise/string_helpers/si_leta_nla.js
@@ -1,13 +1,13 @@
//Convert String to upper case
function siLetaNla(args) {
// 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á.`);
}
throw new Error('Yorlang system error');
throw new Error("Invalid param given to helper ise síLẹ́tàŃlá.");
}

throw new Error("Yorlang system error");
}

module.exports = siLetaNla;
module.exports = siLetaNla;
25 changes: 12 additions & 13 deletions src/inputstream.js
Expand Up @@ -2,27 +2,26 @@ const constants = require("./constants.js");
const fs = require("fs");

class InputStream {

constructor(fileName) {
constructor (fileName) {
this.code = this.readProgramFile(fileName);
this.line = 1;
this.column = 0;
this.position = 0;
this.yorlangFileName = fileName;
}

readProgramFile(fileName) {
readProgramFile (fileName) {
try {
return fs.readFileSync(process.cwd() +"/"+ fileName, 'utf8');
return fs.readFileSync(process.cwd() + "/" + fileName, "utf8");
} catch (e) {
throw new Error(`Could not read file: ${fileName}`);
}
}

//return the next value and also discard it from the stream
next() {
// return the next value and also discard it from the stream
next () {
const character = this.code.charAt(this.position++);

if (character === constants.SYM.NEW_LINE) {
this.column = 0; this.line++;
} else {
Expand All @@ -32,22 +31,22 @@ class InputStream {
return character;
}

//return the next value without discarding it from the stream
peek() {
// return the next value without discarding it from the stream
peek () {
return this.code.charAt(this.position);
}

throwError(msg) {
throwError (msg) {
throw new Error(`There's an error at line ${this.line} near column ${this.column} in file ${this.yorlangFileName} :\n ${msg}`);
}

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

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

module.exports = InputStream;
module.exports = InputStream;
6 changes: 3 additions & 3 deletions src/interpreters/helpers/woke_helper.js
@@ -1,10 +1,10 @@
const constants = require("../../constants.js");

class WokeHelper {
static isWokeVariable(context, tiName) {
class WokeHelper {
static isWokeVariable (context, tiName) {
const wokeList = context.environment().getJeki(context.getCurrentScope(), constants.KW.WOKE);
return wokeList != undefined && wokeList.indexOf(tiName) != -1;
}
}

module.exports = WokeHelper;
module.exports = WokeHelper;
9 changes: 4 additions & 5 deletions src/interpreters/ibase.js
@@ -1,14 +1,13 @@
class IBase {

constructor() {
constructor () {
if (this.constructor == IBase) {
throw new Error("Cannot instantiate abstract class IBase");
}
}

interpreteNode(node) {
throw new Error(`Class of type IBase must implement interpreteNode()`);
interpreteNode (node) {
throw new Error("Class of type IBase must implement interpreteNode()");
}
}

module.exports = IBase;
module.exports = IBase;
7 changes: 3 additions & 4 deletions src/interpreters/inodeand.js
Expand Up @@ -2,11 +2,10 @@ const IBase = require("./ibase.js");
const constants = require("../constants.js");

class INodeAnd extends IBase {

interpreteNode(node) {
interpreteNode (node) {
return this.evaluateNode(node.left) !== constants.KW.IRO && this.evaluateNode(node.right) !== constants.KW.IRO
? constants.KW.OOTO : constants.KW.IRO;
? constants.KW.OOTO : constants.KW.IRO;
}
}

module.exports = new INodeAnd();
module.exports = new INodeAnd();
5 changes: 2 additions & 3 deletions src/interpreters/inodearray.js
@@ -1,7 +1,6 @@
const IBase = require("./ibase.js");
class INodeArray extends IBase {

interpreteNode(arrayNode) {
interpreteNode (arrayNode) {
const arr = [];

arrayNode.body.forEach(arrayItemNode => {
Expand All @@ -12,4 +11,4 @@ class INodeArray extends IBase {
}
}

module.exports = new INodeArray();
module.exports = new INodeArray();
17 changes: 8 additions & 9 deletions src/interpreters/inodearrayelem.js
Expand Up @@ -2,21 +2,20 @@ const IBase = require("./ibase.js");
const contansts = require("../constants.js");

class INodeArrayElement extends IBase {

interpreteNode(node) {
const jekiNode = {name: node.name, operation: contansts.GET_JEKI}
interpreteNode (node) {
const jekiNode = { name: node.name, operation: contansts.GET_JEKI, };
const arrayLiteral = this.evaluateNode(jekiNode);

return INodeArrayElement.getArrayElement(this, node, arrayLiteral);
}

static getArrayElement(context, node, arrayLiteral) {
let arrayElement, isOnedimensionalArray = true;
static getArrayElement (context, node, arrayLiteral) {
let arrayElement; let isOnedimensionalArray = true;

node.indexNodes.map(indexNode => { //if this callback run more than once, then the array is multi-dimensional
node.indexNodes.map(indexNode => { // if this callback run more than once, then the array is multi-dimensional
const index = context.evaluateNode(indexNode);

if (typeof index == "number") {
if (typeof index === "number") {
arrayElement = (isOnedimensionalArray) ? arrayLiteral[index] : arrayElement[index];
isOnedimensionalArray = false;
} else {
Expand All @@ -30,4 +29,4 @@ class INodeArrayElement extends IBase {
}
}

module.exports = new INodeArrayElement();
module.exports = new INodeArrayElement();

0 comments on commit 11b0d76

Please sign in to comment.