From 691d62f403de7bad1fb989931195d643602e4513 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Sun, 23 Feb 2014 21:20:50 +0400 Subject: [PATCH] eslint update + style fixes --- .eslint.yaml | 146 +++++++++++++++++++++++---------------------- lib/cli.js | 2 + lib/config_gen.js | 5 +- lib/index.js | 4 +- lib/logger.js | 12 ++-- lib/status-cats.js | 2 +- lib/utils.js | 12 ++-- package.yaml | 1 - 8 files changed, 95 insertions(+), 89 deletions(-) diff --git a/.eslint.yaml b/.eslint.yaml index 8e491c02a..2ef858cca 100644 --- a/.eslint.yaml +++ b/.eslint.yaml @@ -24,7 +24,7 @@ rules: # name !== encodeURIComponent(name) || # name.toLowerCase() === "node_modules" # ) { - brace-style: 0 + brace-style: 1 # snake_case is more readable, what's up with you guys? camelcase: 0 @@ -37,7 +37,7 @@ rules: consistent-this: [1, 'self'] # fails good code - curly: 0 + curly: [0, 'multi'] # fails good code, where this notation is used for consistency: # something['foo-bar'] = 123 @@ -55,6 +55,7 @@ rules: # if some functions are complex, they are for a good reason, # ain't worth it max-depth: [0, 4] + max-nested-callbacks: [0, 2] # should it really throw for every long URL? max-len: [0, 80, 4] @@ -69,51 +70,31 @@ rules: # that one makes sense new-cap: 2 - new-parens: 1 - no-alert: 1 - # I'm writing javascript, not some weird reduced version of it no-bitwise: 0 - no-caller: 1 - # not working around IE bugs, sorry no-catch-shadow: 0 # see above, IE is useful for downloading other browsers only no-comma-dangle: 0 - no-cond-assign: 1 - # good for removing debugging code no-console: 2 - no-control-regex: 1 - # good for removing debugging code no-debugger: 2 - no-delete-var: 1 - no-div-regex: 1 - no-dupe-keys: 1 - # why would anyone need to check against that? no-else-return: 0 # sometimes empty statement contains useful comment no-empty: 0 - no-empty-class: 1 - no-empty-label: 1 - # stupid rule # "x == null" is "x === null || x === undefined" no-eq-null: 0 - no-eval: 1 - no-ex-assign: 1 - no-extend-native: 1 - # fails good code, when parens are used for grouping: # (req && req.headers['via']) ? req.headers['via'] + ', ' : '' # not everyone remembers priority tables, you know @@ -123,37 +104,14 @@ rules: # ;['foo', 'bar'].forEach(function(x) {}) no-extra-semi: 0 - no-fallthrough: 1 - no-floating-decimal: 1 - no-func-assign: 1 - no-global-strict: 1 - no-implied-eval: 1 - no-invalid-regexp: 1 - no-iterator: 1 - no-label-var: 1 - no-loop-func: 1 - # fails good code: # var fs = require('fs'), # , open = fs.open no-mixed-requires: [0, false] - no-multi-str: 1 - no-native-reassign: 1 - no-negated-in-lhs: 1 - - no-nested-ternary: 1 - - no-new: 1 - # new Array(12) is used to pre-allocate arrays no-new-array: 0 - no-new-func: 1 - no-new-object: 1 - no-new-wrappers: 1 - no-obj-calls: 1 - # fails good code: # fs.open('/file', 0666, function(){}) no-octal: 0 @@ -166,8 +124,6 @@ rules: # I'm writing javascript, not some weird reduced version of it no-plusplus: 0 - no-proto: 1 - # fails good code: # if (a) { # var x = 'foo' @@ -176,19 +132,11 @@ rules: # } no-redeclare: 0 - no-return-assign: 1 - no-script-url: 1 - no-self-compare: 1 - # sometimes useful, often isn't # probably worth enforcing no-shadow: 2 - no-shadow-restricted-names: 1 - no-spaced-func: 1 - - # can't agree more, but it's a task for code review, not for lint - no-sync: 0 + no-sync: 2 # I'm writing javascript, not some weird reduced version of it no-ternary: 0 @@ -196,8 +144,6 @@ rules: # the single most important rule in the entire ruleset no-undef: 2 - no-undef-init: 1 - # it is failing our own underscores no-underscore-dangle: 0 @@ -210,13 +156,11 @@ rules: # fails (function(_err) {}) where named argument is used to show what # nth function argument means - no-unused-vars: 0 + no-unused-vars: [0, 'local'] # fails function hoisting no-use-before-define: 0 - no-with: 1 - # fails foobar( (function(){}).bind(this) ) # parens are added for readability no-wrap-func: 0 @@ -227,23 +171,18 @@ rules: # var y one-var: 0 - # the most stupid rule I ever saw quote-props: 0 # fails situation when different quotes are used to avoid escaping - quotes: [0, 'single'] - - radix: 1 + quotes: [2, 'single', 'avoid-escape'] # http:#blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding - semi: 0 + semi: [2, 'never'] # fails good code where spaces are used for grouping: # (x+y * y+z) space-infix-ops: 0 - space-return-throw-case: 1 - # typeof(something) should have braces to look like a function # a matter of taste I suppose space-unary-word-ops: 0 @@ -252,12 +191,75 @@ rules: # can I have a check to enforce not using it? strict: 0 - use-isnan: 1 - wrap-iife: 1 - wrap-regex: 1 - + sort-vars: 0 no-path-concat: 0 + func-names: 0 # how can you set a return code without process.exit? no-process-exit: 0 + # both styles are useful + func-style: [0, 'declaration'] + + # fails while(1) {...} + no-constant-condition: 0 + + consistent-return: 1 + new-parens: 1 + no-alert: 1 + no-array-constructor: 1 + no-caller: 1 + no-cond-assign: 1 + no-control-regex: 1 + no-delete-var: 1 + no-div-regex: 1 + no-dupe-keys: 1 + no-empty-class: 1 + no-empty-label: 1 + no-eval: 1 + no-ex-assign: 1 + no-extend-native: 1 + no-extra-boolean-cast: 1 + no-extra-strict: 1 + no-fallthrough: 1 + no-floating-decimal: 1 + no-func-assign: 1 + no-global-strict: 1 + no-implied-eval: 1 + no-invalid-regexp: 1 + no-iterator: 1 + no-labels: 1 + no-label-var: 1 + no-lone-blocks: 1 + no-loop-func: 1 + no-multi-str: 1 + no-native-reassign: 1 + no-negated-in-lhs: 1 + no-nested-ternary: 1 + no-new: 1 + no-new-func: 1 + no-new-object: 1 + no-new-wrappers: 1 + no-obj-calls: 1 + no-octal: 1 + no-proto: 1 + no-regex-spaces: 1 + no-return-assign: 1 + no-script-url: 1 + no-self-compare: 1 + no-shadow: 1 + no-shadow-restricted-names: 1 + no-spaced-func: 1 + no-sparse-arrays: 1 + no-sync: 1 + no-undef: 1 + no-undef-init: 1 + no-unreachable: 1 + no-with: 1 + no-yoda: 1 + radix: 1 + space-return-throw-case: 1 + use-isnan: 1 + valid-jsdoc: 1 + wrap-iife: 1 + wrap-regex: 1 diff --git a/lib/cli.js b/lib/cli.js index f20b58b0b..b329c4c78 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +/*eslint no-sync:0*/ + if (process.getuid && process.getuid() === 0) { global.console.error("Sinopia doesn't need superuser privileges. Don't run it under root.") } diff --git a/lib/config_gen.js b/lib/config_gen.js index f0c4bf037..420ff3f7b 100644 --- a/lib/config_gen.js +++ b/lib/config_gen.js @@ -4,7 +4,10 @@ var fs = require('fs') module.exports = function create_config() { var pass = crypto.randomBytes(8).toString('base64').replace(/[=+\/]/g, '') , pass_digest = crypto.createHash('sha1').update(pass).digest('hex') - , config = fs.readFileSync(require.resolve('./config_def.yaml'), 'utf8') + + /*eslint no-sync:0*/ + var config = fs.readFileSync(require.resolve('./config_def.yaml'), 'utf8') + config = config.replace('__PASSWORD__', pass_digest) return { diff --git a/lib/index.js b/lib/index.js index a33491762..96b61171c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -33,7 +33,7 @@ module.exports = function(config_hash) { } else { if (!req.remoteUser) { if (req.remoteUserError) { - var msg = "can't "+action+" restricted package, " + req.remoteUserError + var msg = "can't "+action+' restricted package, ' + req.remoteUserError } else { var msg = "can't "+action+" restricted package without auth, did you forget 'npm set always-auth true'?" } @@ -179,7 +179,7 @@ module.exports = function(config_hash) { // npmjs.org sets 10h expire expires: new Date(Date.now() + 10*60*60*1000) }) - res.send({"ok":true,"name":"somebody","roles":[]}) + res.send({'ok':true,'name':'somebody','roles':[]}) }) app.get('/-/user/:org_couchdb_user', function(req, res, next) { diff --git a/lib/logger.js b/lib/logger.js index a5984f859..e4e99be6a 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -29,11 +29,11 @@ module.exports.setup = function(logs) { if (target.format === 'pretty') { // making fake stream for prettypritting stream.write = function(obj) { - dest.write(print(obj.level, obj.msg, obj, dest.isTTY) + "\n") + dest.write(print(obj.level, obj.msg, obj, dest.isTTY) + '\n') } } else { stream.write = function(obj) { - dest.write(JSON.stringify(obj, Logger.safeCycles()) + "\n") + dest.write(JSON.stringify(obj, Logger.safeCycles()) + '\n') } } } else if (target.type === 'file') { @@ -42,7 +42,7 @@ module.exports.setup = function(logs) { Logger.emit('error', err) }) stream.write = function(obj) { - dest.write(JSON.stringify(obj, Logger.safeCycles()) + "\n") + dest.write(JSON.stringify(obj, Logger.safeCycles()) + '\n') } } else { throw new Error('wrong target type for a log') @@ -50,7 +50,7 @@ module.exports.setup = function(logs) { if (target.level === 'http') target.level = 35 streams.push({ - type: "raw", + type: 'raw', level: target.level || 35, stream: stream, }) @@ -141,9 +141,9 @@ function print(type, msg, obj, colors) { // ^^--- black magic... kidding, just "colors ? 0 : 1" if (colors) { - return " \033[" + levels[type] + "m" + (pad(type)) + "\033[39m " + sub + " " + finalmsg + return ' \033[' + levels[type] + 'm' + (pad(type)) + '\033[39m ' + sub + ' ' + finalmsg } else { - return " " + (pad(type)) + " " + sub + " " + finalmsg + return ' ' + (pad(type)) + ' ' + sub + ' ' + finalmsg } } diff --git a/lib/status-cats.js b/lib/status-cats.js index 5f39588b4..2cb66c6a8 100644 --- a/lib/status-cats.js +++ b/lib/status-cats.js @@ -64,7 +64,7 @@ module.exports.middleware = function(req, res, next) { var _writeHead = res.writeHead res.writeHead = function(status) { if (status in images) { - res.setHeader("X-Status-Cat", module.exports.get_image(status)) + res.setHeader('X-Status-Cat', module.exports.get_image(status)) } _writeHead.apply(res, arguments) } diff --git a/lib/utils.js b/lib/utils.js index 7a964ff6d..ca7eac8c6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -8,14 +8,14 @@ module.exports.validate_name = function(name) { if (typeof(name) !== 'string') return false name = name.toLowerCase() if ( - name.charAt(0) === "." || // ".bin", etc. - name.charAt(0) === "-" || // "-" is reserved by couchdb + name.charAt(0) === '.' || // ".bin", etc. + name.charAt(0) === '-' || // "-" is reserved by couchdb name.match(/[\/@\s\+%:]/) || name !== encodeURIComponent(name) || - name === "node_modules" || - name === "__proto__" || - name === "package.json" || - name === "favicon.ico" + name === 'node_modules' || + name === '__proto__' || + name === 'package.json' || + name === 'favicon.ico' ) { return false } else { diff --git a/package.yaml b/package.yaml index fe4651f80..49d046f26 100644 --- a/package.yaml +++ b/package.yaml @@ -36,7 +36,6 @@ devDependencies: # linting tools eslint: 'eslint/eslint' - #eslint-stylish: '*' # for debugging memory leaks, it'll be require()'d if # installed, but I don't want it to be installed everytime