From b1987f6017dd8820d8c720c679c9e4bf8024fd65 Mon Sep 17 00:00:00 2001 From: Cory Smith Date: Sat, 22 Oct 2016 11:17:14 -0600 Subject: [PATCH] =?UTF-8?q?jshint=20=E2=80=94>=20semistandard=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jshintrc | 31 ------------------------------- .npmignore | 1 - package.json | 17 +++++++++++++---- src/index.js | 43 +++++++++++++++++++++---------------------- test/index.test.js | 8 ++------ 5 files changed, 36 insertions(+), 64 deletions(-) delete mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 7fc982f..0000000 --- a/.jshintrc +++ /dev/null @@ -1,31 +0,0 @@ -{ - "node": true, - "esnext": true, - "bitwise": true, - "camelcase": true, - "curly": true, - "eqeqeq": true, - "immed": true, - "indent": 2, - "latedef": "nofunc", - "newcap": false, - "noarg": true, - "quotmark": "single", - "regexp": true, - "undef": true, - "unused": true, - "strict": false, - "trailing": true, - "smarttabs": true, - "white": false, - "node": true, - "browser": true, - "globals": { - "it": true, - "describe": true, - "before": true, - "beforeEach": true, - "after": true, - "afterEach": true - } -} diff --git a/.npmignore b/.npmignore index 6783ec1..8557440 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,4 @@ .editorconfig -.jshintrc .travis.yml .babelrc .idea/ diff --git a/package.json b/package.json index 5333bb2..23a8e11 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,19 @@ "release:major": "npm run add-dist; npm version major && npm publish", "compile": "rimraf lib/ && babel -d lib/ src/", "watch": "babel --watch -d lib/ src/", - "jshint": "jshint src/. test/. --config", + "lint": "eslint-if-supported semistandard --fix", "mocha": "mocha test/ --compilers js:babel-core/register", - "test": "npm run compile && npm run jshint && npm run mocha", + "test": "npm run compile && npm run lint && npm run mocha", "start": "node example/app" }, + "semistandard": { + "env": [ + "mocha" + ], + "ignore": [ + "/lib" + ] + }, "directories": { "lib": "lib" }, @@ -57,15 +65,16 @@ "babelify": "^7.2.0", "body-parser": "^1.15.0", "browserify": "^13.0.0", + "eslint-if-supported": "^1.0.1", "feathers": "^2.0.0", "feathers-errors": "^2.0.1", "feathers-rest": "^1.2.2", "feathers-service-tests": "^0.8.0", "feathers-socketio": "^1.3.3", - "jshint": "^2.9.1", "localstorage-memory": "^1.0.2", "mocha": "^3.0.0", "nsp": "^2.2.0", - "rimraf": "^2.5.2" + "rimraf": "^2.5.2", + "semistandard": "^9.1.0" } } diff --git a/src/index.js b/src/index.js index 6bfbd73..f90a7f4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import { Service } from 'feathers-memory'; class LocalStorage extends Service { - constructor(options = {}) { + constructor (options = {}) { super(options); this._storageKey = options.name || 'feathers'; this._storage = options.storage || (typeof window !== 'undefined' && window.localStorage); @@ -13,8 +13,8 @@ class LocalStorage extends Service { } } - ready() { - if(!this.store) { + ready () { + if (!this.store) { return Promise.resolve(this._storage.getItem(this._storageKey)) .then(str => JSON.parse(str || '{}')) .then(store => { @@ -22,8 +22,7 @@ class LocalStorage extends Service { const last = store[keys[keys.length - 1]]; // Current id is the id of the last item - this._uId = (keys.length && typeof last[this.id] !== 'undefined') ? - last[this.id] + 1 : 0; + this._uId = (keys.length && typeof last[this.id] !== 'undefined') ? last[this.id] + 1 : 0; return (this.store = store); }); @@ -32,8 +31,8 @@ class LocalStorage extends Service { return Promise.resolve(this.store); } - flush(data) { - if(!this._timeout) { + flush (data) { + if (!this._timeout) { this._timeout = setTimeout(() => { this._storage.setItem(this._storageKey, JSON.stringify(this.store)); delete this._timeout; @@ -43,41 +42,41 @@ class LocalStorage extends Service { return data; } - execute(method, ... args) { + execute (method, ...args) { return this.ready() - .then(() => super[method](... args)); + .then(() => super[method](...args)); } - find(... args) { - return this.execute('find', ... args); + find (...args) { + return this.execute('find', ...args); } - get(... args) { - return this.execute('get', ... args); + get (...args) { + return this.execute('get', ...args); } - create(... args) { - return this.execute('create', ... args) + create (...args) { + return this.execute('create', ...args) .then(data => this.flush(data)); } - patch(... args) { - return this.execute('patch', ... args) + patch (...args) { + return this.execute('patch', ...args) .then(data => this.flush(data)); } - update(... args) { - return this.execute('update', ... args) + update (...args) { + return this.execute('update', ...args) .then(data => this.flush(data)); } - remove(... args) { - return this.execute('remove', ... args) + remove (...args) { + return this.execute('remove', ...args) .then(data => this.flush(data)); } } -export default function init(options) { +export default function init (options) { return new LocalStorage(options); } diff --git a/test/index.test.js b/test/index.test.js index a9734fb..9813437 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,5 +1,3 @@ -/*jshint expr: true*/ - import { base, example } from 'feathers-service-tests'; import errors from 'feathers-errors'; import feathers from 'feathers'; @@ -38,7 +36,6 @@ describe('Feathers Localstorage Service', () => { })).then(() => { return new Promise((resolve) => { setTimeout(() => { - const data = JSON.parse(storage.getItem(name)); assert.deepEqual(data, { 0: { @@ -63,7 +60,6 @@ describe('Feathers Localstorage Service', () => { }).then(() => { return new Promise((resolve) => { setTimeout(() => { - const data = JSON.parse(storage.getItem(name)); assert.deepEqual(data, { 2: { @@ -95,8 +91,8 @@ describe('Feathers Localstorage Service', () => { return messageService.find().then((data) => { assert.deepEqual(data, { 0: { - id: 0, - text: 'test 0' + id: 0, + text: 'test 0' } }); });