Skip to content

Commit

Permalink
Add eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
smialy committed Mar 24, 2018
1 parent 35aadb1 commit 557b695
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 109 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ addons:
chrome: stable
firefox: latest

# before_install:
# - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- make bootstrap

script:
- make lint
- make test
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ clean:

test:
./node_modules/.bin/lerna run test

lint:
./node_modules/.bin/lerna run lint
30 changes: 30 additions & 0 deletions packages/sjs-di/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
1 change: 1 addition & 0 deletions packages/sjs-di/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 3 additions & 1 deletion packages/sjs-di/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
"url": "git+https://github.com/smialy/sjs.git"
},
"scripts": {
"test": "karma start --single-run"
"test": "karma start --single-run",
"lint": "eslint src test"
},
"license": "MIT",
"homepage": "https://github.com/smialy/sjs#readme",
"devDependencies": {
"eslint": "^4.19.1",
"karma": "^2.0.0",
"karma-chrome-launcher": "^2.1.1",
"karma-firefox-launcher": "^1.0.1",
Expand Down
5 changes: 0 additions & 5 deletions packages/sjs-di/src/cointainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ export class Container {
return Reflect.construct(fn, args);
}
}
function createType(fn, ...args) {
let obj = Object.create(fn.prototype);
fn.apply(obj, args);
return obj;
}
function validateKey(key) {
if (key === null || key === undefined) {
throw new TypeError('Key cannot be null or undefined');
Expand Down
4 changes: 2 additions & 2 deletions packages/sjs-di/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export class InstanceResolver {
constructor(instance) {
this.instance = instance;
}
get(container, key) {
get() {
return this.instance;
}
}
Expand All @@ -11,7 +11,7 @@ export class SingletonResolver {
this.fn = fn;
this.instance = null;
}
get(container, key) {
get(container) {
if (!this.instance) {
this.instance = container.createInstance(this.fn);
}
Expand Down
6 changes: 0 additions & 6 deletions packages/sjs-di/ts/cointainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ export class Container {
}
}

function createType(fn: Function, ...args: any[]): any {
let obj = Object.create(fn.prototype);
fn.apply(obj, args);
return obj;
}

function validateKey(key: any) {
if (key === null || key === undefined) {
throw new TypeError('Key cannot be null or undefined');
Expand Down
30 changes: 30 additions & 0 deletions packages/sjs-logging/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
3 changes: 0 additions & 3 deletions packages/sjs-logging/.jshintrc

This file was deleted.

1 change: 1 addition & 0 deletions packages/sjs-logging/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 3 additions & 1 deletion packages/sjs-logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"url": "http://github.com/smialy/sjs"
},
"scripts": {
"test": "karma start --single-run"
"test": "karma start --single-run",
"lint": "eslint src test"
},
"main": "src/index.js",
"devDependencies": {
"eslint": "^4.19.1",
"karma": "^2.0.0",
"karma-chrome-launcher": "^2.1.1",
"karma-firefox-launcher": "^1.0.1",
Expand Down
46 changes: 1 addition & 45 deletions packages/sjs-logging/src/filter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {levelToMask} from './utils';

/**
* @typedef {Object} Record
* @param {string} name
Expand All @@ -10,49 +8,6 @@ import {levelToMask} from './utils';
* @param {Error} ex
*/

/**
* Base logger
*/
export class Mask{

constructor(){
this._mask = 0;
}

/**
* Setter for level [set level()]
*
* @param {number} level
*/
set level(level) {
this._mask = levelToMask(level);
}
/**
* Getter for level [get level()]
*
* @return {number} level
*/
get level() {
return null;
}
/**
* Getter for mask [get mask()]
*
* @return {number} mask
*/
get mask() {
return this._mask;
}
/**
* Setter for mask [set mask()]
*
* @param {number} mask
*/
set mask(mask) {
this._mask = mask;
}
}

/**
* Base class for all filters
*/
Expand All @@ -79,6 +34,7 @@ export class Filter {
}
}


/**
* Filters manager
*/
Expand Down
8 changes: 4 additions & 4 deletions packages/sjs-logging/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { checkLevel } from './utils';

export class Handler extends Filterer {

/**
/**
* @param {number} [level=LEVELS.NOTSET]
*/
constructor(level=LEVELS.NOTSET) {
Expand All @@ -26,7 +26,7 @@ export class Handler extends Filterer {
return false;
}

emit(record) {}
emit() {}
flush() {}
close() {}
}
Expand All @@ -37,8 +37,8 @@ export class ConsoleHandler extends Handler {
*/
emit(record) {
console.log('[' + record.name + '] ::' + record.levelName + ':: ' + record.msg);
if (record.ex) {
console.error(record.ex);
if (record.exception) {
console.error(record.exception);
}
}
}
6 changes: 3 additions & 3 deletions packages/sjs-logging/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Manager} from './manager'
import {Manager} from './manager';

var manager = new Manager();

export default manager.getLogger();
export function getLogger(name){
return manager.getLogger(name)
export function getLogger(name) {
return manager.getLogger(name);
}
export {Filter, Filterer} from './filter';
export {Logger} from './logger';
Expand Down
30 changes: 15 additions & 15 deletions packages/sjs-logging/src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,42 @@ export class Logger extends Filterer {
* @param {string} msg
* @param {Error} ex
*/
fatal(msg, ex) {
this.log(LEVELS.FATAL, msg, ex);
fatal(msg, exception) {
this.log(LEVELS.FATAL, msg, exception);
}
/**
*
* @param {string} msg
* @param {Error} ex
*/
critical(msg, ex) {
this.log(LEVELS.CRITICAL, msg, ex);
critical(msg, exception) {
this.log(LEVELS.CRITICAL, msg, exception);
}
/**
*
* @param {string} msg
* @param {Error} ex
*/
error(msg, ex) {
this.log(LEVELS.ERROR, msg, ex);
error(msg, exception) {
this.log(LEVELS.ERROR, msg, exception);
}

/**
*
* @param {string} msg
* @param {Error} ex
*/
warn(msg, ex) {
this.log(LEVELS.WARN, msg, ex);
warn(msg, exception) {
this.log(LEVELS.WARN, msg, exception);
}

/**
*
* @param {string} msg
* @param {Error} ex
*/
warning(msg, ex) {
this.log(LEVELS.WARN, msg, ex);
warning(msg, exception) {
this.log(LEVELS.WARN, msg, exception);
}

/**
Expand All @@ -114,24 +114,24 @@ export class Logger extends Filterer {
*
* @param {Error} ex
*/
exception(ex) {
this.log(LEVELS.ERROR, ex.message, ex);
exception(exception) {
this.log(LEVELS.ERROR, exception.message, exception);
}

/**
* @param {number} level
* @param {string} msg
* @param {Error} ex
* @param {Error} exception
*/
log(level, msg, ex) {
log(level, msg, exception) {
level = checkLevel(level);
if (this._isEnabledFor(level)) {
this.handle({
name: this.name,
level,
levelName: LEVEL_NAMES[level],
msg,
ex
exception
});
}

Expand Down
7 changes: 3 additions & 4 deletions packages/sjs-logging/src/manager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {LEVELS} from './consts';
import {Logger} from './logger';
import {Mask} from './filter';
import { LEVELS } from './consts';
import { Logger } from './logger';
import { checkLevel } from './utils';


export class Manager {

constructor(root, level=LEVELS.NOTSET) {
Expand Down Expand Up @@ -45,7 +45,6 @@ export class Manager {
if (logger.parent) {
for (let item of this._loggers.values()) {
if (item.parent && item.parent === logger.parent) {
let name = item.name;
if (item.name.substr(0, logger.name.length) === logger.name) {
item.parent = logger;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/sjs-logging/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function levelToMask(level) {
return level === LEVELS.NOTSET ? LEVELS.NOTSET : level * 2 - 1;
}

/**
*
* @param {numbe|string} level
*/
export function checkLevel(level){
let type = typeof level;
if(type === 'number'){
Expand Down
Loading

0 comments on commit 557b695

Please sign in to comment.