Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#36: update eslint config #59

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
410 changes: 73 additions & 337 deletions .eslintrc.json

Large diffs are not rendered by default.

85 changes: 43 additions & 42 deletions js/__loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
(() => {
// from https://github.com/runtimejs/runtime-module-loader/blob/master/index.js
class Loader {
constructor (existsFileFn, readFileFn, evalScriptFn, builtins = {}, builtinsResolveFrom = '/') {
constructor(existsFileFn, readFileFn, evalScriptFn, builtins = {}, builtinsResolveFrom = '/') {
const cache = {};
const builtinsResolveFromComponents = builtinsResolveFrom.split('/');

function throwError (err) {
function throwError(err) {
throw err;
}

function endsWith (str, suffix) {
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

function normalizePath (components) {
function normalizePath(components) {
const r = [];

for (const p of components) {
Expand Down Expand Up @@ -59,7 +59,7 @@
return r;
}

function loadAsFile (path) {
function loadAsFile(path) {
if (existsFileFn(path)) return path;
if (existsFileFn(`${path}.js`)) return `${path}.js`;
if (existsFileFn(`${path}.json`)) return `${path}.json`;
Expand All @@ -68,7 +68,7 @@
return null;
}

function getPackageMain (packageJsonFile) {
function getPackageMain(packageJsonFile) {
const json = readFileFn(packageJsonFile);
let parsed = null;

Expand All @@ -88,7 +88,7 @@
return parsed.main || 'index.js';
}

function loadAsDirectory (path, ignoreJson) {
function loadAsDirectory(path, ignoreJson) {
let mainFile = 'index';
let dir = false;

Expand Down Expand Up @@ -117,7 +117,7 @@
return null;
}

function loadNodeModules (dirComponents, parts) {
function loadNodeModules(dirComponents, parts) {
let count = dirComponents.length;

while (count-- > 0) {
Expand Down Expand Up @@ -151,7 +151,7 @@
return null;
}

function resolve (module, pathOpt = '') {
function resolve(module, pathOpt = '') {
let path = String(pathOpt);

let resolveFrom = module.dirComponents;
Expand Down Expand Up @@ -187,18 +187,18 @@
return loadNodeModules(resolveFrom, pathComponents);
}

function register (path, code) {
function register(path, code) {
// Add virtual module
const currentModule = global.module;

const module = new Module(path.split("/"));
const module = new Module(path.split('/'));
module.virtual = code;
cache[path] = module;
return module;
}

class Module {
constructor (pathComponents) {
constructor(pathComponents) {
this.dirComponents = pathComponents.slice(0, -1);
this.pathComponents = pathComponents;
this.filename = pathComponents.join('/');
Expand All @@ -208,7 +208,7 @@
this.require.register = register;
this.virtual = null;
}
require (path, nocache = false) {
require(path, nocache = false) {
let module = this;
const resolvedPath = resolve(module, path);

Expand Down Expand Up @@ -250,15 +250,16 @@
/* eslint-disable max-len */
evalScriptFn(
`((require,exports,module,__filename,__dirname) => {${content}})(((m) => {function require(path){return m.require(path)};require.cache=m.require.cache;require.register=m.require.register;return require})(global.module),global.module.exports,global.module,global.module.filename,global.module.dirname)`,
displayPath);
displayPath,
);
/* eslint-enable max-len */
}

global.module = currentModule;

return module.exports;
}
resolve (module = this, pathOpt) {
resolve(module = this, pathOpt) {
return resolve(module, pathOpt);
}
}
Expand All @@ -280,37 +281,37 @@
files[file] = true;
}

function fileExists (path) {
function fileExists(path) {
return Boolean(files[path]);
}

const runtimePackagePath = __SYSCALL.initrdGetKernelIndex().split('/')
.slice(0, -1)
.join('/');
const loader = new Loader(fileExists, __SYSCALL.initrdReadFile, __SYSCALL.eval, {
'assert': 'assert',
'events': 'events',
'buffer': 'buffer',
'process': './modules/process.js',
'console': './modules/console.js',
'constants': 'constants-browserify',
'fs': './modules/fs.js',
'os': './modules/os.js',
'net': './modules/net.js',
'dns': './modules/dns.js',
assert: 'assert',
events: 'events',
buffer: 'buffer',
process: './modules/process.js',
console: './modules/console.js',
constants: 'constants-browserify',
fs: './modules/fs.js',
os: './modules/os.js',
net: './modules/net.js',
dns: './modules/dns.js',
// http: 'http-node',
'punycode': 'punycode',
'querystring': 'querystring-es3',
'string_decoder': 'string_decoder',
'path': 'path-browserify',
'url': 'url',
'stream': './modules/stream.js',
'inherits': './modules/inherits.js',
'sys': 'util/util.js',
'util': 'util/util.js',
'http': './modules/http.js',
'logger': './modules/logger.js',
'errors': './modules/errors.js',
punycode: 'punycode',
querystring: 'querystring-es3',
string_decoder: 'string_decoder',
path: 'path-browserify',
url: 'url',
stream: './modules/stream.js',
inherits: './modules/inherits.js',
sys: 'util/util.js',
util: 'util/util.js',
http: './modules/http.js',
logger: './modules/logger.js',
errors: './modules/errors.js',
/* eslint-enable camelcase */
}, runtimePackagePath);

Expand All @@ -321,25 +322,25 @@
const stream = loader.require('stream');

class StdoutStream extends stream.Writable {
_write (chunk, encoding, callback) {
_write(chunk, encoding, callback) {
__SYSCALL.write(String(chunk));
callback();
}
}
class StderrStream extends stream.Writable {
_write (chunk, encoding, callback) {
_write(chunk, encoding, callback) {
__SYSCALL.write(String(chunk));
callback();
}
}
class TermoutStream extends stream.Writable {
_write (chunk, encoding, callback) {
_write(chunk, encoding, callback) {
runtime.stdio.defaultStdio.write(String(chunk));
callback();
}
}
class TermerrStream extends stream.Writable {
_write (chunk, encoding, callback) {
_write(chunk, encoding, callback) {
runtime.stdio.defaultStdio.writeError(String(chunk));
callback();
}
Expand Down
3 changes: 2 additions & 1 deletion js/apps/brainfuck/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
'use strict';

const Brainfuck = require('./interpreter');

let io;

function main (_args, api, res) {
function main(_args, api, res) {
const args = _args.split(/\s+/);

io = api.stdio;
Expand Down
29 changes: 14 additions & 15 deletions js/apps/brainfuck/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

class Brainfuck {
constructor () {
constructor() {
this._input = [];
this._output = [];
this._data = [];
Expand All @@ -16,43 +16,43 @@ class Brainfuck {
// this.ops =
}

get ops () {
get ops() {
const self = this;

return {
'+' () {
'+': function () {
self._data[self._ptr] = self._data[self._ptr] || 0;
self._data[self._ptr]++;
self.debug('+', self._data[self._ptr], self._ptr);
},

'-' () {
'-': function () {
self._data[self._ptr] = self._data[self._ptr] || 0;
self._data[self._ptr]--;
self.debug('-', self._data[self._ptr], self._ptr);
},

'<' () {
'<': function () {
self._ptr--;
if (self._ptr < 0) {
self._ptr = 0; // Don't allow pointer to leave data array
}
self.debug('<', self._ptr);
},

'>' () {
'>': function () {
self._ptr++;
self.debug('>', self._ptr);
},

'.' () {
'.': function () {
const c = String.fromCharCode(self._data[self._ptr]);

self._output.push(c);
self.debug('.', c, self._data[self._ptr]);
},

',' () {
',': function () {
const c = self._input.shift();

if (typeof c === 'string') {
Expand All @@ -63,13 +63,13 @@ class Brainfuck {
};
}

parse (str) {
parse(str) {
this._programChars = str.split('');

return this.parseProgram();
}

parseProgram () {
parseProgram() {
const nodes = [];
let nextChar;

Expand All @@ -87,7 +87,7 @@ class Brainfuck {
return this.program(nodes);
}

program (nodes) {
program(nodes) {
const self = this;

return function (inputString) {
Expand All @@ -106,7 +106,7 @@ class Brainfuck {
}


loop (nodes) {
loop(nodes) {
const self = this;

return function () {
Expand All @@ -124,11 +124,11 @@ class Brainfuck {
};
}

parseLoop () {
parseLoop() {
const nodes = [];
let nextChar;

while (this._programChars[0] != ']') {
while (this._programChars[0] !== ']') {
nextChar = this._programChars.shift();
if (typeof nextChar === 'undefined') {
throw new Error('Missing closing bracket');
Expand All @@ -142,7 +142,6 @@ class Brainfuck {

return this.loop(nodes);
}

}

module.exports = Brainfuck;
24 changes: 13 additions & 11 deletions js/apps/composer/Cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
* Composer
* Copyright (c) 2017 PROPHESSOR
*/

'use strict';

class Cursor{
constructor(){
this.position = 0;
}
class Cursor {
static get symbol() {
return '#';
}

constructor() {
this.position = 0;
}

moveRight(){
if()this.position++;
}
static get symbol(){
return "#"
}
moveRight() {
this.position++;
}
}

module.exports = new Cursor();
module.exports = new Cursor();
6 changes: 2 additions & 4 deletions js/apps/composer/Interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ const io = $$.stdio.defaultStdio;

// ######################################################################################
class Interface {

static render () {
static render() {
io.write(`
##############################################################################
# SpeakPlay (c) PROPHESSOR 2017 #
##############################################################################\n
Press F12 to exit\n\n\n\n\n\n\n
DURATION: ${note.duration}
OCTAVE: ${note.octave}\n\n\n\n\n\n\n\n\n
`
);
`);
}
}

Expand Down
Loading