From 557b695bf67ff18038282d02b60de256f9575d36 Mon Sep 17 00:00:00 2001
From: Piotr Smialkowski
Date: Sat, 24 Mar 2018 20:17:17 +0100
Subject: [PATCH] Add eslint
---
.travis.yml | 4 +-
Makefile | 3 ++
packages/sjs-di/.eslintrc.json | 30 +++++++++++++++
packages/sjs-di/.npmrc | 1 +
packages/sjs-di/package.json | 4 +-
packages/sjs-di/src/cointainer.js | 5 ---
packages/sjs-di/src/resolvers.js | 4 +-
packages/sjs-di/ts/cointainer.ts | 6 ---
packages/sjs-logging/.eslintrc.json | 30 +++++++++++++++
packages/sjs-logging/.jshintrc | 3 --
packages/sjs-logging/.npmrc | 1 +
packages/sjs-logging/package.json | 4 +-
packages/sjs-logging/src/filter.js | 46 +----------------------
packages/sjs-logging/src/handler.js | 8 ++--
packages/sjs-logging/src/index.js | 6 +--
packages/sjs-logging/src/logger.js | 30 +++++++--------
packages/sjs-logging/src/manager.js | 7 ++--
packages/sjs-logging/src/utils.js | 4 ++
packages/sjs-logging/tests/filter.test.js | 17 ---------
19 files changed, 104 insertions(+), 109 deletions(-)
create mode 100644 packages/sjs-di/.eslintrc.json
create mode 100644 packages/sjs-di/.npmrc
create mode 100644 packages/sjs-logging/.eslintrc.json
delete mode 100644 packages/sjs-logging/.jshintrc
create mode 100644 packages/sjs-logging/.npmrc
diff --git a/.travis.yml b/.travis.yml
index 060eb5a..63817ed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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
diff --git a/Makefile b/Makefile
index 416a3b3..3fd13c8 100644
--- a/Makefile
+++ b/Makefile
@@ -12,3 +12,6 @@ clean:
test:
./node_modules/.bin/lerna run test
+
+lint:
+ ./node_modules/.bin/lerna run lint
diff --git a/packages/sjs-di/.eslintrc.json b/packages/sjs-di/.eslintrc.json
new file mode 100644
index 0000000..7870608
--- /dev/null
+++ b/packages/sjs-di/.eslintrc.json
@@ -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"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/packages/sjs-di/.npmrc b/packages/sjs-di/.npmrc
new file mode 100644
index 0000000..9cf9495
--- /dev/null
+++ b/packages/sjs-di/.npmrc
@@ -0,0 +1 @@
+package-lock=false
\ No newline at end of file
diff --git a/packages/sjs-di/package.json b/packages/sjs-di/package.json
index 353edb3..98025ab 100644
--- a/packages/sjs-di/package.json
+++ b/packages/sjs-di/package.json
@@ -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",
diff --git a/packages/sjs-di/src/cointainer.js b/packages/sjs-di/src/cointainer.js
index 49922b1..d53d1fb 100644
--- a/packages/sjs-di/src/cointainer.js
+++ b/packages/sjs-di/src/cointainer.js
@@ -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');
diff --git a/packages/sjs-di/src/resolvers.js b/packages/sjs-di/src/resolvers.js
index 62fb570..70bd47b 100644
--- a/packages/sjs-di/src/resolvers.js
+++ b/packages/sjs-di/src/resolvers.js
@@ -2,7 +2,7 @@ export class InstanceResolver {
constructor(instance) {
this.instance = instance;
}
- get(container, key) {
+ get() {
return this.instance;
}
}
@@ -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);
}
diff --git a/packages/sjs-di/ts/cointainer.ts b/packages/sjs-di/ts/cointainer.ts
index fcd5f3b..bdd3ecd 100644
--- a/packages/sjs-di/ts/cointainer.ts
+++ b/packages/sjs-di/ts/cointainer.ts
@@ -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');
diff --git a/packages/sjs-logging/.eslintrc.json b/packages/sjs-logging/.eslintrc.json
new file mode 100644
index 0000000..7870608
--- /dev/null
+++ b/packages/sjs-logging/.eslintrc.json
@@ -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"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/packages/sjs-logging/.jshintrc b/packages/sjs-logging/.jshintrc
deleted file mode 100644
index 92964f9..0000000
--- a/packages/sjs-logging/.jshintrc
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "esversion":6
-}
diff --git a/packages/sjs-logging/.npmrc b/packages/sjs-logging/.npmrc
new file mode 100644
index 0000000..9cf9495
--- /dev/null
+++ b/packages/sjs-logging/.npmrc
@@ -0,0 +1 @@
+package-lock=false
\ No newline at end of file
diff --git a/packages/sjs-logging/package.json b/packages/sjs-logging/package.json
index a0725f2..ef1c607 100644
--- a/packages/sjs-logging/package.json
+++ b/packages/sjs-logging/package.json
@@ -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",
diff --git a/packages/sjs-logging/src/filter.js b/packages/sjs-logging/src/filter.js
index 6ac21fc..7e01aea 100644
--- a/packages/sjs-logging/src/filter.js
+++ b/packages/sjs-logging/src/filter.js
@@ -1,5 +1,3 @@
-import {levelToMask} from './utils';
-
/**
* @typedef {Object} Record
* @param {string} name
@@ -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
*/
@@ -79,6 +34,7 @@ export class Filter {
}
}
+
/**
* Filters manager
*/
diff --git a/packages/sjs-logging/src/handler.js b/packages/sjs-logging/src/handler.js
index b229e2a..64e78d4 100644
--- a/packages/sjs-logging/src/handler.js
+++ b/packages/sjs-logging/src/handler.js
@@ -5,7 +5,7 @@ import { checkLevel } from './utils';
export class Handler extends Filterer {
- /**
+ /**
* @param {number} [level=LEVELS.NOTSET]
*/
constructor(level=LEVELS.NOTSET) {
@@ -26,7 +26,7 @@ export class Handler extends Filterer {
return false;
}
- emit(record) {}
+ emit() {}
flush() {}
close() {}
}
@@ -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);
}
}
}
diff --git a/packages/sjs-logging/src/index.js b/packages/sjs-logging/src/index.js
index 2fa1a17..19f5671 100644
--- a/packages/sjs-logging/src/index.js
+++ b/packages/sjs-logging/src/index.js
@@ -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';
diff --git a/packages/sjs-logging/src/logger.js b/packages/sjs-logging/src/logger.js
index dfa64dc..5841040 100644
--- a/packages/sjs-logging/src/logger.js
+++ b/packages/sjs-logging/src/logger.js
@@ -56,24 +56,24 @@ 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);
}
/**
@@ -81,8 +81,8 @@ export class Logger extends Filterer {
* @param {string} msg
* @param {Error} ex
*/
- warn(msg, ex) {
- this.log(LEVELS.WARN, msg, ex);
+ warn(msg, exception) {
+ this.log(LEVELS.WARN, msg, exception);
}
/**
@@ -90,8 +90,8 @@ export class Logger extends Filterer {
* @param {string} msg
* @param {Error} ex
*/
- warning(msg, ex) {
- this.log(LEVELS.WARN, msg, ex);
+ warning(msg, exception) {
+ this.log(LEVELS.WARN, msg, exception);
}
/**
@@ -114,16 +114,16 @@ 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({
@@ -131,7 +131,7 @@ export class Logger extends Filterer {
level,
levelName: LEVEL_NAMES[level],
msg,
- ex
+ exception
});
}
diff --git a/packages/sjs-logging/src/manager.js b/packages/sjs-logging/src/manager.js
index d8ed499..510d11f 100644
--- a/packages/sjs-logging/src/manager.js
+++ b/packages/sjs-logging/src/manager.js
@@ -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) {
@@ -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;
}
diff --git a/packages/sjs-logging/src/utils.js b/packages/sjs-logging/src/utils.js
index 842b88d..35673aa 100644
--- a/packages/sjs-logging/src/utils.js
+++ b/packages/sjs-logging/src/utils.js
@@ -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'){
diff --git a/packages/sjs-logging/tests/filter.test.js b/packages/sjs-logging/tests/filter.test.js
index c1b3440..30f33a7 100644
--- a/packages/sjs-logging/tests/filter.test.js
+++ b/packages/sjs-logging/tests/filter.test.js
@@ -3,27 +3,10 @@ import {
LEVEL_NAMES
} from '../src/consts';
import {
- Mask,
Filter,
Filterer
} from '../src/filter';
-QUnit.module('sjs-logging.Mask');
-
-QUnit.test('default Mask', assert => {
- var mask = new Mask();
- assert.equal(null, mask.level);
- assert.equal(0, mask.mask);
-});
-
-QUnit.test('set level', assert => {
- var mask = new Mask();
- for(let i = 1; i <= 16; i*=2){
- mask.level = i;
- //example: 1000(8) => 1111(15)
- assert.equal(i*2-1, mask.mask);
- }
-});
QUnit.module('sjs-logging.Filters');