From a1adde254e31a79eb6adabc349e1ac390a2f1ee1 Mon Sep 17 00:00:00 2001 From: Devin Leaman Date: Sun, 15 Oct 2017 03:04:24 -0500 Subject: [PATCH] Replaced eslint with Standard for formatting I replaced the eslint coding style with Standard as I genuinely believe it to be the superior style. Primarily due to the lack of project specific settings, you cannot change the coding style so it's always the same. This means I updated the package.json to include the correct dependency and added a script called format. Running npm format will use Standard to automatically fix many formatting errors. I also added Josh and myself to the package.json as contributors. --- .eslintrc.js | 122 ------------------ index.js | 38 +++--- package.json | 12 +- src/data.js | 74 +++++------ .../wow/data/character/achievement.js | 55 ++++---- 5 files changed, 91 insertions(+), 210 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5bbfe77..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,122 +0,0 @@ -module.exports = { - 'extends': 'eslint:recommended', - 'env': { - 'es6': true, - 'node': true, - 'browser': false - }, - 'parserOptions': { - 'ecmaVersion': 6, - 'sourceType': 'module', - 'ecmaFeatures': { - 'modules': true - } - }, - 'rules': { - 'array-bracket-spacing': ['error', 'never'], - 'block-scoped-var': 'error', - 'brace-style': ['error', '1tbs', { - 'allowSingleLine': false - }], - 'comma-dangle': ['error', { - 'arrays': 'always-multiline', - 'objects': 'always-multiline', - 'imports': 'always-multiline', - 'exports': 'always-multiline', - 'functions': 'never', - }], - 'comma-spacing': 'error', - 'comma-style': ['error', 'last'], - 'computed-property-spacing': ['error', 'never'], - 'curly': ['error', 'all'], - 'eol-last': 'error', - 'eqeqeq': ['error', 'smart'], - 'guard-for-in': 'error', - 'indent': ['error', 2, { - 'SwitchCase': 1 - }], - 'key-spacing': ['error', { - 'beforeColon': false, - 'afterColon': true - }], - 'linebreak-style': ['error', 'unix'], - 'lines-around-comment': ['error', { - 'beforeBlockComment': true, - 'afterBlockComment': false - }], - 'new-parens': 'error', - 'no-array-constructor': 'error', - 'no-caller': 'error', - 'no-catch-shadow': 'error', - 'no-console': ['error', { allow: ['log'] }], - 'no-dupe-keys': 'error', - 'no-empty': 'error', - 'no-eval': 'error', - 'no-extend-native': 'error', - 'no-extra-bind': 'error', - 'no-extra-parens': ['error', 'functions'], - 'no-implied-eval': 'error', - 'no-iterator': 'error', - 'no-label-var': 'error', - 'no-labels': 'error', - 'no-lone-blocks': 'error', - 'no-loop-func': 'error', - 'no-mixed-spaces-and-tabs': 'error', - 'no-multi-spaces': 'error', - 'no-multi-str': 'error', - 'no-native-reassign': 'error', - 'no-nested-ternary': 'error', - 'no-new-func': 'error', - 'no-new-object': 'error', - 'no-new-wrappers': 'error', - 'no-octal-escape': 'error', - 'no-process-exit': 'error', - 'no-proto': 'error', - 'no-return-assign': 'error', - 'no-script-url': 'error', - 'no-sequences': 'error', - 'no-shadow-restricted-names': 'error', - 'no-spaced-func': 'error', - 'no-trailing-spaces': 'error', - 'no-undef-init': 'error', - 'no-undefined': 'error', - 'no-unused-vars': ['error', { - 'vars': 'all', - 'args': 'none' - }], - 'no-with': 'error', - 'object-curly-spacing': ['error', 'always'], - 'one-var': ['error', 'never'], - 'quote-props': ['error', 'consistent-as-needed'], - 'quotes': ['error', 'single', 'avoid-escape'], - 'semi': ['error', 'always'], - 'semi-spacing': ['error', { - 'before': false, - 'after': true - }], - 'space-before-blocks': ['error', 'always'], - 'space-before-function-paren': ['error', { - 'anonymous': 'always', - 'named': 'always' - }], - 'space-in-parens': ['error', 'never'], - 'space-infix-ops': 'error', - 'space-unary-ops': ['error', { - 'words': true, - 'nonwords': false - }], - 'spaced-comment': ['error', 'always'], - 'strict': ['error', 'global'], - 'yoda': ['error', 'never'], - 'max-nested-callbacks': [1, 5], - 'valid-jsdoc': [1, { - 'prefer': { - 'arg': 'param', - 'argument': 'param', - 'class': 'constructor', - 'property': 'prop', - 'returns': 'return' - } - }] - } -} diff --git a/index.js b/index.js index 218a159..14823dd 100755 --- a/index.js +++ b/index.js @@ -1,10 +1,10 @@ #! /usr/bin/env node -const _ = require('lodash'); -const Yargs = require('yargs'); +const _ = require('lodash') +const Yargs = require('yargs') -const Pkg = require('./package.json'); -const Data = require('./src/data'); +const Pkg = require('./package.json') +const Data = require('./src/data') // https://gist.github.com/zambon/8b2d207bd21cf4fcd47b96cd6d7f99c2 _.mixin({ @@ -12,13 +12,13 @@ _.mixin({ (obj, fn) => map(_.mapValues(obj, (v) => { if (_.isPlainObject(v)) { - return _.deeply(map)(v, fn); + return _.deeply(map)(v, fn) } else if (_.isArray(v)) { - return _.map(v, item => _.deeply(map)(item, fn)); + return _.map(v, item => _.deeply(map)(item, fn)) } - return v; - }), fn), -}); + return v + }), fn) +}) module.exports = Yargs .command({ @@ -26,21 +26,21 @@ module.exports = Yargs desc: 'Set a config variable', builder: (yargs) => yargs.default('value', 'false'), handler: (argv) => { - switch(argv.key) { + switch (argv.key) { case 'all': - Data.run(); - break; + Data.run() + break case 'community': case 'comm': - Data.run('community'); - break; + Data.run('community') + break case 'community-oauth-profile': case 'comm-oauth-prof': - Data.run('community-oauth-profile'); - break; + Data.run('community-oauth-profile') + break case 'game-data': - Data.run('game-data'); - break; + Data.run('game-data') + break default: console.log('Command not found...') } @@ -51,4 +51,4 @@ module.exports = Yargs .help('help') .alias('help', 'h') .demandCommand() - .argv; + .argv diff --git a/package.json b/package.json index 4f63161..5a24242 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,18 @@ "description": "Command Line Interface for TargetDummy", "main": "index.js", "scripts": { - "lint": "./node_modules/.bin/eslint -c .eslintrc.js .", + "format": "standard --fix", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Ben Weier ", + "contributors": [{ + "name": "Devin Leaman (Alcha)", + "email": "admin@paranoiddevs.com", + "url": "https://paranoiddevs.com" + }, { + "name": "Josh Weiss", + "url": "https://github.com/coder4life" + }], "license": "MIT", "repository": { "type": "git", @@ -31,6 +39,6 @@ "targetdummy-test-data": "index.js" }, "devDependencies": { - "eslint": "^4.7.2" + "standard": "10.0.3" } } diff --git a/src/data.js b/src/data.js index 7ffa5a2..e3eaef7 100644 --- a/src/data.js +++ b/src/data.js @@ -1,69 +1,65 @@ -const FS = require('fs'); -const Glob = require('glob'); -const Path = require('path'); -const YamlJS = require('js-yaml'); +const FS = require('fs') +const Glob = require('glob') +const Path = require('path') +const YamlJS = require('js-yaml') class Data { - - constructor(options) { - - this.type = this.constructor.name; + constructor (options) { + this.type = this.constructor.name } - get response() { - return this._response; + get response () { + return this._response } - set response(response) { - this._response = response; + set response (response) { + this._response = response } - static instances() { - const data = []; + static instances () { + const data = [] // Load All Data Classes Glob.sync('./src/data/**/*.js').forEach(file => { - data.push(require(Path.resolve(file))); - }); - return data; + data.push(require(Path.resolve(file))) + }) + return data } - static scoped(name = null) { - const data = []; + static scoped (name = null) { + const data = [] this.instances().forEach(item => { - if(item.scope === name) { - data.push(item); + if (item.scope === name) { + data.push(item) } else { - data.push(item); + data.push(item) } - }); - return data; + }) + return data } - static run(scoped = null) { + static run (scoped = null) { this.scoped(scoped).forEach(data => { return data.request() .then(result => { - data.store(result); - }); - }); + data.store(result) + }) + }) } - static getStorage(filePath, extension) { + static getStorage (filePath, extension) { if (FS.existsSync(filePath + extension)) { - if(extension === 'js') { - return JSON.parse(FS.readFileSync(filePath + '.' + extension, 'utf8')); - } else if(extension === 'yaml') { - return YamlJS.safeLoad(FS.readFileSync(filePath + '.' + extension, 'utf8')); + if (extension === 'js') { + return JSON.parse(FS.readFileSync(filePath + '.' + extension, 'utf8')) + } else if (extension === 'yaml') { + return YamlJS.safeLoad(FS.readFileSync(filePath + '.' + extension, 'utf8')) } else { - return false; + return false } } else { - FS.openSync(filePath + extension, 'a'); - return false; + FS.openSync(filePath + extension, 'a') + return false } } - - } -module.exports = Data; +module.exports = Data diff --git a/src/data/community/wow/data/character/achievement.js b/src/data/community/wow/data/character/achievement.js index 1ea65b3..efebc49 100644 --- a/src/data/community/wow/data/character/achievement.js +++ b/src/data/community/wow/data/character/achievement.js @@ -1,41 +1,40 @@ -const _ =require('lodash'); -const AppRoot = require('app-root-path'); -const BlizzardJS = require('blizzard.js').initialize({apikey: 'api_key_goes_here_for_now'}); -const Sequelize = require('sequelize'); +const _ = require('lodash') +const AppRoot = require('app-root-path') +const BlizzardJS = require('blizzard.js').initialize({apikey: 'api_key_goes_here_for_now'}) +const Sequelize = require('sequelize') -const Data = require(AppRoot + '/src/data'); +const Data = require(AppRoot + '/src/data') class AchievementCharacterDataWowCommunityData extends Data { - constructor(options) { - super(); - this.name = 'Achievement Character Data World of Warcraft Community Data'; - this.description = 'The achievement data from the World of Warcraft community data endpoints.'; - this.scope = 'community'; - this.dataPath = 'data/community/wow/data/'; - this.dataFilename = 'character-achievements'; + constructor (options) { + super() + this.name = 'Achievement Character Data World of Warcraft Community Data' + this.description = 'The achievement data from the World of Warcraft community data endpoints.' + this.scope = 'community' + this.dataPath = 'data/community/wow/data/' + this.dataFilename = 'character-achievements' } - request() { - return BlizzardJS.wow.data('character-achievements', { origin: 'us' }) + request () { + return BlizzardJS.wow.data('character-achievements', { origin: 'us' }) .then(response => { - return response; - }); + return response + }) } - store(source) { - let filePath = AppRoot + '/' + this.dataPath + this.dataFilename; - let yamlData = Data.getStorage(filePath); - if(source) { - //console.log(source.data); - let requestData = _.flatMapDeep(source.data, ['id']); - console.log(requestData); - /*requestData.forEach(item => { + store (source) { + let filePath = AppRoot + '/' + this.dataPath + this.dataFilename + let yamlData = Data.getStorage(filePath) + if (source) { + // console.log(source.data); + let requestData = _.flatMapDeep(source.data, ['id']) + console.log(requestData) + /* requestData.forEach(item => { console.log(item); - });*/ - return true; + }); */ + return true } } - } -module.exports = new AchievementCharacterDataWowCommunityData(); +module.exports = new AchievementCharacterDataWowCommunityData()