1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-21 07:29:37 +01:00

eslint update + style fixes

This commit is contained in:
Alex Kocharin 2014-02-23 21:20:50 +04:00
parent a5d0094669
commit 691d62f403
8 changed files with 95 additions and 89 deletions

@ -24,7 +24,7 @@ rules:
# name !== encodeURIComponent(name) || # name !== encodeURIComponent(name) ||
# name.toLowerCase() === "node_modules" # name.toLowerCase() === "node_modules"
# ) { # ) {
brace-style: 0 brace-style: 1
# snake_case is more readable, what's up with you guys? # snake_case is more readable, what's up with you guys?
camelcase: 0 camelcase: 0
@ -37,7 +37,7 @@ rules:
consistent-this: [1, 'self'] consistent-this: [1, 'self']
# fails good code # fails good code
curly: 0 curly: [0, 'multi']
# fails good code, where this notation is used for consistency: # fails good code, where this notation is used for consistency:
# something['foo-bar'] = 123 # something['foo-bar'] = 123
@ -55,6 +55,7 @@ rules:
# if some functions are complex, they are for a good reason, # if some functions are complex, they are for a good reason,
# ain't worth it # ain't worth it
max-depth: [0, 4] max-depth: [0, 4]
max-nested-callbacks: [0, 2]
# should it really throw for every long URL? # should it really throw for every long URL?
max-len: [0, 80, 4] max-len: [0, 80, 4]
@ -69,51 +70,31 @@ rules:
# that one makes sense # that one makes sense
new-cap: 2 new-cap: 2
new-parens: 1
no-alert: 1
# I'm writing javascript, not some weird reduced version of it # I'm writing javascript, not some weird reduced version of it
no-bitwise: 0 no-bitwise: 0
no-caller: 1
# not working around IE bugs, sorry # not working around IE bugs, sorry
no-catch-shadow: 0 no-catch-shadow: 0
# see above, IE is useful for downloading other browsers only # see above, IE is useful for downloading other browsers only
no-comma-dangle: 0 no-comma-dangle: 0
no-cond-assign: 1
# good for removing debugging code # good for removing debugging code
no-console: 2 no-console: 2
no-control-regex: 1
# good for removing debugging code # good for removing debugging code
no-debugger: 2 no-debugger: 2
no-delete-var: 1
no-div-regex: 1
no-dupe-keys: 1
# why would anyone need to check against that? # why would anyone need to check against that?
no-else-return: 0 no-else-return: 0
# sometimes empty statement contains useful comment # sometimes empty statement contains useful comment
no-empty: 0 no-empty: 0
no-empty-class: 1
no-empty-label: 1
# stupid rule # stupid rule
# "x == null" is "x === null || x === undefined" # "x == null" is "x === null || x === undefined"
no-eq-null: 0 no-eq-null: 0
no-eval: 1
no-ex-assign: 1
no-extend-native: 1
# fails good code, when parens are used for grouping: # fails good code, when parens are used for grouping:
# (req && req.headers['via']) ? req.headers['via'] + ', ' : '' # (req && req.headers['via']) ? req.headers['via'] + ', ' : ''
# not everyone remembers priority tables, you know # not everyone remembers priority tables, you know
@ -123,37 +104,14 @@ rules:
# ;['foo', 'bar'].forEach(function(x) {}) # ;['foo', 'bar'].forEach(function(x) {})
no-extra-semi: 0 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: # fails good code:
# var fs = require('fs'), # var fs = require('fs'),
# , open = fs.open # , open = fs.open
no-mixed-requires: [0, false] 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 # new Array(12) is used to pre-allocate arrays
no-new-array: 0 no-new-array: 0
no-new-func: 1
no-new-object: 1
no-new-wrappers: 1
no-obj-calls: 1
# fails good code: # fails good code:
# fs.open('/file', 0666, function(){}) # fs.open('/file', 0666, function(){})
no-octal: 0 no-octal: 0
@ -166,8 +124,6 @@ rules:
# I'm writing javascript, not some weird reduced version of it # I'm writing javascript, not some weird reduced version of it
no-plusplus: 0 no-plusplus: 0
no-proto: 1
# fails good code: # fails good code:
# if (a) { # if (a) {
# var x = 'foo' # var x = 'foo'
@ -176,19 +132,11 @@ rules:
# } # }
no-redeclare: 0 no-redeclare: 0
no-return-assign: 1
no-script-url: 1
no-self-compare: 1
# sometimes useful, often isn't # sometimes useful, often isn't
# probably worth enforcing # probably worth enforcing
no-shadow: 2 no-shadow: 2
no-shadow-restricted-names: 1 no-sync: 2
no-spaced-func: 1
# can't agree more, but it's a task for code review, not for lint
no-sync: 0
# I'm writing javascript, not some weird reduced version of it # I'm writing javascript, not some weird reduced version of it
no-ternary: 0 no-ternary: 0
@ -196,8 +144,6 @@ rules:
# the single most important rule in the entire ruleset # the single most important rule in the entire ruleset
no-undef: 2 no-undef: 2
no-undef-init: 1
# it is failing our own underscores # it is failing our own underscores
no-underscore-dangle: 0 no-underscore-dangle: 0
@ -210,13 +156,11 @@ rules:
# fails (function(_err) {}) where named argument is used to show what # fails (function(_err) {}) where named argument is used to show what
# nth function argument means # nth function argument means
no-unused-vars: 0 no-unused-vars: [0, 'local']
# fails function hoisting # fails function hoisting
no-use-before-define: 0 no-use-before-define: 0
no-with: 1
# fails foobar( (function(){}).bind(this) ) # fails foobar( (function(){}).bind(this) )
# parens are added for readability # parens are added for readability
no-wrap-func: 0 no-wrap-func: 0
@ -227,23 +171,18 @@ rules:
# var y # var y
one-var: 0 one-var: 0
# the most stupid rule I ever saw
quote-props: 0 quote-props: 0
# fails situation when different quotes are used to avoid escaping # fails situation when different quotes are used to avoid escaping
quotes: [0, 'single'] quotes: [2, 'single', 'avoid-escape']
radix: 1
# http:#blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding # 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: # fails good code where spaces are used for grouping:
# (x+y * y+z) # (x+y * y+z)
space-infix-ops: 0 space-infix-ops: 0
space-return-throw-case: 1
# typeof(something) should have braces to look like a function # typeof(something) should have braces to look like a function
# a matter of taste I suppose # a matter of taste I suppose
space-unary-word-ops: 0 space-unary-word-ops: 0
@ -252,12 +191,75 @@ rules:
# can I have a check to enforce not using it? # can I have a check to enforce not using it?
strict: 0 strict: 0
use-isnan: 1 sort-vars: 0
wrap-iife: 1
wrap-regex: 1
no-path-concat: 0 no-path-concat: 0
func-names: 0
# how can you set a return code without process.exit? # how can you set a return code without process.exit?
no-process-exit: 0 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

@ -1,5 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
/*eslint no-sync:0*/
if (process.getuid && process.getuid() === 0) { if (process.getuid && process.getuid() === 0) {
global.console.error("Sinopia doesn't need superuser privileges. Don't run it under root.") global.console.error("Sinopia doesn't need superuser privileges. Don't run it under root.")
} }

@ -4,7 +4,10 @@ var fs = require('fs')
module.exports = function create_config() { module.exports = function create_config() {
var pass = crypto.randomBytes(8).toString('base64').replace(/[=+\/]/g, '') var pass = crypto.randomBytes(8).toString('base64').replace(/[=+\/]/g, '')
, pass_digest = crypto.createHash('sha1').update(pass).digest('hex') , 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) config = config.replace('__PASSWORD__', pass_digest)
return { return {

@ -33,7 +33,7 @@ module.exports = function(config_hash) {
} else { } else {
if (!req.remoteUser) { if (!req.remoteUser) {
if (req.remoteUserError) { if (req.remoteUserError) {
var msg = "can't "+action+" restricted package, " + req.remoteUserError var msg = "can't "+action+' restricted package, ' + req.remoteUserError
} else { } else {
var msg = "can't "+action+" restricted package without auth, did you forget 'npm set always-auth true'?" 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 // npmjs.org sets 10h expire
expires: new Date(Date.now() + 10*60*60*1000) 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) { app.get('/-/user/:org_couchdb_user', function(req, res, next) {

@ -29,11 +29,11 @@ module.exports.setup = function(logs) {
if (target.format === 'pretty') { if (target.format === 'pretty') {
// making fake stream for prettypritting // making fake stream for prettypritting
stream.write = function(obj) { 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 { } else {
stream.write = function(obj) { 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') { } else if (target.type === 'file') {
@ -42,7 +42,7 @@ module.exports.setup = function(logs) {
Logger.emit('error', err) Logger.emit('error', err)
}) })
stream.write = function(obj) { stream.write = function(obj) {
dest.write(JSON.stringify(obj, Logger.safeCycles()) + "\n") dest.write(JSON.stringify(obj, Logger.safeCycles()) + '\n')
} }
} else { } else {
throw new Error('wrong target type for a log') 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 if (target.level === 'http') target.level = 35
streams.push({ streams.push({
type: "raw", type: 'raw',
level: target.level || 35, level: target.level || 35,
stream: stream, stream: stream,
}) })
@ -141,9 +141,9 @@ function print(type, msg, obj, colors) {
// ^^--- black magic... kidding, just "colors ? 0 : 1" // ^^--- black magic... kidding, just "colors ? 0 : 1"
if (colors) { 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 { } else {
return " " + (pad(type)) + " " + sub + " " + finalmsg return ' ' + (pad(type)) + ' ' + sub + ' ' + finalmsg
} }
} }

@ -64,7 +64,7 @@ module.exports.middleware = function(req, res, next) {
var _writeHead = res.writeHead var _writeHead = res.writeHead
res.writeHead = function(status) { res.writeHead = function(status) {
if (status in images) { 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) _writeHead.apply(res, arguments)
} }

@ -8,14 +8,14 @@ module.exports.validate_name = function(name) {
if (typeof(name) !== 'string') return false if (typeof(name) !== 'string') return false
name = name.toLowerCase() name = name.toLowerCase()
if ( if (
name.charAt(0) === "." || // ".bin", etc. name.charAt(0) === '.' || // ".bin", etc.
name.charAt(0) === "-" || // "-" is reserved by couchdb name.charAt(0) === '-' || // "-" is reserved by couchdb
name.match(/[\/@\s\+%:]/) || name.match(/[\/@\s\+%:]/) ||
name !== encodeURIComponent(name) || name !== encodeURIComponent(name) ||
name === "node_modules" || name === 'node_modules' ||
name === "__proto__" || name === '__proto__' ||
name === "package.json" || name === 'package.json' ||
name === "favicon.ico" name === 'favicon.ico'
) { ) {
return false return false
} else { } else {

@ -36,7 +36,6 @@ devDependencies:
# linting tools # linting tools
eslint: 'eslint/eslint' eslint: 'eslint/eslint'
#eslint-stylish: '*'
# for debugging memory leaks, it'll be require()'d if # for debugging memory leaks, it'll be require()'d if
# installed, but I don't want it to be installed everytime # installed, but I don't want it to be installed everytime