diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..a146bebed8 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +*.debug.js +*.min.js +node_modules/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000000..9d86046188 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,65 @@ +{ + "rules": { + "indent": [ + 2, + 2 + ], + "quotes": [ + 2, + "single" + ], + "linebreak-style": [ + 2, + "unix" + ], + "semi": [2, "always"], + "strict": [2, "global"], + "curly": 2, + "eqeqeq": 2, + "no-eval": 2, + "guard-for-in": 2, + "no-caller": 2, + "no-else-return": 2, + "no-eq-null": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-floating-decimal": 2, + "no-implied-eval": 2, + "no-labels": 2, + "no-with": 2, + "no-loop-func": 1, + "no-native-reassign": 2, + "no-redeclare": [2, {"builtinGlobals": true}], + "no-delete-var": 2, + "no-shadow-restricted-names": 2, + "no-undef-init": 2, + "no-use-before-define": 2, + "no-unused-vars": [2, {"args": "none"}], + "no-undef": 2, + "callback-return": [2, ["callback", "cb", "next"]], + "global-require": 0, + "no-console": 0, + "require-yield": 0 + }, + "env": { + "es6": true, + "node": true, + "browser": true + }, + "globals": { + "describe": true, + "it": true, + "before": true, + "after": true, + "beforeEach": true, + "afterEach": true + }, + "parserOptions": { + "ecmaVersion": 8, + "sourceType": "script", + "ecmaFeatures": { + "jsx": true + } + }, + "extends": "eslint:recommended" +} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index e21ccb39f1..0000000000 --- a/.jshintrc +++ /dev/null @@ -1,44 +0,0 @@ -{ - "predef": [ - "phantom", - "module", - "require", - "__dirname", - "process", - "console", - "it", - "describe", - "before", - "beforeEach", - "after", - "afterEach", - "ace", - "$" - ], - - "browser": true, - "node": true, - "es5": true, - "bitwise": true, - "curly": true, - "eqeqeq": true, - "forin": false, - "immed": true, - "latedef": true, - "newcap": true, - "noarg": true, - "noempty": true, - "nonew": true, - "plusplus": false, - "undef": true, - "strict": false, - "trailing": false, - "globalstrict": true, - "nonstandard": true, - "white": true, - "indent": 2, - "expr": true, - "multistr": true, - "onevar": false, - "unused": "vars" -} diff --git a/.travis.yml b/.travis.yml index 5204f835e1..71c79429a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ env: node_js: - 4 - - 5 + - 6 - stable addons: diff --git a/Makefile b/Makefile index 8a408ea27d..00f7653956 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,12 @@ MOCHA_REPORTER = spec # NPM_REGISTRY = "--registry=http://registry.npm.taobao.org" NPM_REGISTRY = "" - all: test +lint: + @./node_modules/.bin/eslint --fix *.js api/ bin/ common/ \ + controllers/ middlewares/ models/ proxy/ + install: @npm install $(NPM_REGISTRY) @@ -18,7 +21,7 @@ pretest: mkdir public/upload; \ fi -test: install pretest +test: install pretest lint @NODE_ENV=test ./node_modules/mocha/bin/mocha \ --reporter $(MOCHA_REPORTER) \ -r should \ @@ -34,7 +37,7 @@ testfile: --timeout $(TEST_TIMEOUT) \ $(FILE) -test-cov cov: install pretest +test-cov cov: install pretest lint @NODE_ENV=test node \ node_modules/.bin/istanbul cover --preserve-comments \ ./node_modules/.bin/_mocha \ @@ -45,7 +48,6 @@ test-cov cov: install pretest --timeout $(TEST_TIMEOUT) \ $(TESTS) - build: @./node_modules/loader-builder/bin/builder views . diff --git a/api/v1/message.js b/api/v1/message.js index b5b9ede9d9..27027f06a8 100644 --- a/api/v1/message.js +++ b/api/v1/message.js @@ -1,3 +1,5 @@ +'use strict'; + var eventproxy = require('eventproxy'); var Message = require('../../proxy').Message; var at = require('../../common/at'); diff --git a/api/v1/middleware.js b/api/v1/middleware.js index c97a5f798b..4ef12ff446 100644 --- a/api/v1/middleware.js +++ b/api/v1/middleware.js @@ -1,3 +1,5 @@ +'use strict'; + var UserModel = require('../../models').User; var eventproxy = require('eventproxy'); var validator = require('validator'); @@ -37,7 +39,7 @@ var tryAuth = function (req, res, next) { UserModel.findOne({accessToken: accessToken}, ep.done(function (user) { if (!user) { - return next() + return next(); } if (user.is_block) { res.status(403); diff --git a/api/v1/reply.js b/api/v1/reply.js index 82d105c580..7ed00ca9bb 100644 --- a/api/v1/reply.js +++ b/api/v1/reply.js @@ -1,3 +1,5 @@ +'use strict'; + var eventproxy = require('eventproxy'); var validator = require('validator'); var Topic = require('../../proxy').Topic; @@ -25,7 +27,7 @@ var create = function (req, res, next) { res.status(400); return res.send({success: false, error_msg: '不是有效的话题id'}); } - + Topic.getTopic(topic_id, ep.done(function (topic) { if (!topic) { res.status(404); @@ -85,7 +87,7 @@ var ups = function (req, res, next) { res.status(400); return res.send({success: false, error_msg: '不是有效的评论id'}); } - + Reply.getReplyById(replyId, function (err, reply) { if (err) { return next(err); @@ -97,24 +99,24 @@ var ups = function (req, res, next) { if (reply.author_id.equals(userId) && !config.debug) { res.status(403); return res.send({success: false, error_msg: '不能帮自己点赞'}); + } + var action; + reply.ups = reply.ups || []; + var upIndex = reply.ups.indexOf(userId); + if (upIndex === -1) { + reply.ups.push(userId); + action = 'up'; } else { - var action; - reply.ups = reply.ups || []; - var upIndex = reply.ups.indexOf(userId); - if (upIndex === -1) { - reply.ups.push(userId); - action = 'up'; - } else { - reply.ups.splice(upIndex, 1); - action = 'down'; - } - reply.save(function () { - res.send({ - success: true, - action: action - }); - }); + reply.ups.splice(upIndex, 1); + action = 'down'; } + reply.save(function () { + res.send({ + success: true, + action: action + }); + }); + }); }; diff --git a/api/v1/tools.js b/api/v1/tools.js index 6c82cd230e..22170e1938 100644 --- a/api/v1/tools.js +++ b/api/v1/tools.js @@ -1,3 +1,5 @@ +'use strict'; + var eventproxy = require('eventproxy'); var accesstoken = function (req, res, next) { diff --git a/api/v1/topic.js b/api/v1/topic.js index 910fa071c7..eb17321e2b 100644 --- a/api/v1/topic.js +++ b/api/v1/topic.js @@ -1,3 +1,5 @@ +'use strict'; + var models = require('../../models'); var TopicModel = models.Topic; var TopicProxy = require('../../proxy').Topic; @@ -92,7 +94,7 @@ var show = function (req, res, next) { reply = _.pick(reply, ['id', 'author', 'content', 'ups', 'create_at', 'reply_id']); reply.reply_id = reply.reply_id || null; - if (reply.ups && req.user && reply.ups.indexOf(req.user.id) != -1) { + if (reply.ups && req.user && reply.ups.indexOf(req.user.id) !== -1) { reply.is_uped = true; } else { reply.is_uped = false; @@ -101,21 +103,21 @@ var show = function (req, res, next) { return reply; }); - ep.emit('full_topic', topic) + ep.emit('full_topic', topic); })); if (!req.user) { - ep.emitLater('is_collect', null) + ep.emitLater('is_collect', null); } else { - TopicCollect.getTopicCollect(req.user._id, topicId, ep.done('is_collect')) + TopicCollect.getTopicCollect(req.user._id, topicId, ep.done('is_collect')); } ep.all('full_topic', 'is_collect', function (full_topic, is_collect) { full_topic.is_collect = !!is_collect; res.send({success: true, data: full_topic}); - }) + }); }; @@ -230,7 +232,7 @@ exports.update = function (req, res, next) { }); }); } else { - res.status(403) + res.status(403); return res.send({success: false, error_msg: '对不起,你不能编辑此话题。'}); } }); diff --git a/api/v1/topic_collect.js b/api/v1/topic_collect.js index 080fd04835..66b09dd183 100644 --- a/api/v1/topic_collect.js +++ b/api/v1/topic_collect.js @@ -1,3 +1,5 @@ +'use strict'; + var eventproxy = require('eventproxy'); var TopicProxy = require('../../proxy').Topic; var TopicCollectProxy = require('../../proxy').TopicCollect; @@ -23,14 +25,14 @@ function list(req, res, next) { ep.all('collected_topics', function (collected_topics) { var ids = collected_topics.map(function (doc) { - return String(doc.topic_id) + return String(doc.topic_id); }); var query = { _id: { '$in': ids } }; TopicProxy.getTopicsByQuery(query, {}, ep.done('topics', function (topics) { topics = _.sortBy(topics, function (topic) { - return ids.indexOf(String(topic._id)) + return ids.indexOf(String(topic._id)); }); - return topics + return topics; })); }); @@ -41,10 +43,10 @@ function list(req, res, next) { return _.pick(topic, ['id', 'author_id', 'tab', 'content', 'title', 'last_reply_at', 'good', 'top', 'reply_count', 'visit_count', 'create_at', 'author']); }); - res.send({success: true, data: topics}) + res.send({success: true, data: topics}); - }) - })) + }); + })); } exports.list = list; @@ -117,8 +119,8 @@ function de_collect(req, res, next) { if (err) { return next(err); } - if (removeResult.result.n == 0) { - return res.json({success: false}) + if (removeResult.result.n === 0) { + return res.json({success: false}); } UserProxy.getUserById(req.user.id, function (err, user) { diff --git a/api/v1/user.js b/api/v1/user.js index 7696bc27f3..f319515289 100644 --- a/api/v1/user.js +++ b/api/v1/user.js @@ -1,9 +1,10 @@ +'use strict'; + var _ = require('lodash'); var eventproxy = require('eventproxy'); var UserProxy = require('../../proxy').User; var TopicProxy = require('../../proxy').Topic; var ReplyProxy = require('../../proxy').Reply; -var TopicCollect = require('../../proxy').TopicCollect; var show = function (req, res, next) { var loginname = req.params.loginname; @@ -23,7 +24,7 @@ var show = function (req, res, next) { ReplyProxy.getRepliesByAuthorId(user._id, {limit: 20, sort: '-create_at'}, ep.done(function (replies) { var topic_ids = replies.map(function (reply) { - return reply.topic_id.toString() + return reply.topic_id.toString(); }); topic_ids = _.uniq(topic_ids).slice(0, 5); // 只显示最近5条 @@ -31,7 +32,7 @@ var show = function (req, res, next) { var opt = {}; TopicProxy.getTopicsByQuery(query, opt, ep.done('recent_replies', function (recent_replies) { recent_replies = _.sortBy(recent_replies, function (topic) { - return topic_ids.indexOf(topic._id.toString()) + return topic_ids.indexOf(topic._id.toString()); }); return recent_replies; })); diff --git a/api_router_v1.js b/api_router_v1.js index 7d876cdf9b..a2b2e0de39 100644 --- a/api_router_v1.js +++ b/api_router_v1.js @@ -1,3 +1,5 @@ +'use strict'; + var express = require('express'); var topicController = require('./api/v1/topic'); var topicCollectController = require('./api/v1/topic_collect'); diff --git a/app.js b/app.js index 0c20ec938e..756b861b2e 100644 --- a/app.js +++ b/app.js @@ -5,6 +5,7 @@ /** * Module dependencies. */ +'use strict'; var config = require('./config'); @@ -15,7 +16,7 @@ if (!config.debug && config.oneapm_key) { require('colors'); var path = require('path'); var Loader = require('loader'); -var LoaderConnect = require('loader-connect') +var LoaderConnect = require('loader-connect'); var express = require('express'); var session = require('express-session'); var passport = require('passport'); @@ -29,7 +30,6 @@ var auth = require('./middlewares/auth'); var errorPageMiddleware = require('./middlewares/error_page'); var proxyMiddleware = require('./middlewares/proxy'); var RedisStore = require('connect-redis')(session); -var _ = require('lodash'); var csurf = require('csurf'); var compress = require('compression'); var bodyParser = require('body-parser'); @@ -40,7 +40,7 @@ var requestLog = require('./middlewares/request_log'); var renderMiddleware = require('./middlewares/render'); var logger = require('./common/logger'); var helmet = require('helmet'); -var bytes = require('bytes') +var bytes = require('bytes'); // 静态文件目录 @@ -137,14 +137,14 @@ if (!config.debug) { // }); // set static, dynamic helpers -_.extend(app.locals, { +Object.assign(app.locals, { config: config, Loader: Loader, assets: assets }); app.use(errorPageMiddleware.errorPage); -_.extend(app.locals, require('./common/render_helper')); +Object.assign(app.locals, require('./common/render_helper')); app.use(function (req, res, next) { res.locals.csrf = req.csrfToken ? req.csrfToken() : ''; next(); diff --git a/bin/fix_at_problem.js b/bin/fix_at_problem.js index 8374a4f654..ecfccc6218 100644 --- a/bin/fix_at_problem.js +++ b/bin/fix_at_problem.js @@ -1,7 +1,16 @@ +'use strict'; + // 一次性脚本 // 修复之前重复编辑帖子会导致重复 @someone 的渲染问题 var TopicModel = require('../models').Topic; +function fix(str) { + str = str.replace(/\[{1,}(\[@\w+)(\]\(.+?\))\2+/, function (match_text, $1, $2) { + return $1 + $2; + }); + return str; +} + TopicModel.find({content: /\[{2,}@/}).exec(function (err, topics) { topics.forEach(function (topic) { topic.content = fix(topic.content); @@ -9,10 +18,3 @@ TopicModel.find({content: /\[{2,}@/}).exec(function (err, topics) { topic.save(); }); }); - -function fix(str) { - str = str.replace(/\[{1,}(\[@\w+)(\]\(.+?\))\2+/, function (match_text, $1, $2) { - return $1 + $2; - }); - return str; -} diff --git a/bin/fix_topic_collect_count.js b/bin/fix_topic_collect_count.js index 577dfb35a1..d73e8d2a9a 100644 --- a/bin/fix_topic_collect_count.js +++ b/bin/fix_topic_collect_count.js @@ -1,61 +1,63 @@ +'use strict'; + var TopicCollect = require('../models').TopicCollect; var UserModel = require('../models').User; -var TopicModel = require('../models').Topic +var TopicModel = require('../models').Topic; // 修复用户的topic_collect计数 TopicCollect.aggregate( [{ - "$group" : - { - _id : {user_id: "$user_id"}, - count : { $sum : 1} - } + '$group' : + { + _id : {user_id: '$user_id'}, + count : { $sum : 1} + } }], function (err, result) { - result.forEach(function (row) { - var userId = row._id.user_id; - var count = row.count; - - UserModel.findOne({ - _id: userId - }, function (err, user) { - - if (!user) { - return; - } - - user.collect_topic_count = count; - user.save(function () { - console.log(user.loginname, count) - }); - }) - }) - }) + result.forEach(function (row) { + var userId = row._id.user_id; + var count = row.count; + + UserModel.findOne({ + _id: userId + }, function (err, user) { + + if (!user) { + return; + } + + user.collect_topic_count = count; + user.save(function () { + console.log(user.loginname, count); + }); + }); + }); +}); // 修复帖子的topic_collect计数 - TopicCollect.aggregate( - [{ - "$group" : - { - _id : {topic_id: "$topic_id"}, - count : { $sum : 1} - } - }], function (err, result) { - result.forEach(function (row) { - var topic_id = row._id.topic_id; - var count = row.count; - - TopicModel.findOne({ - _id: topic_id - }, function (err, topic) { - - if (!topic) { - return; - } - - topic.collect_topic_count = count; - topic.save(function () { - console.log(topic.id, count) - }); - }) - }) - }) +TopicCollect.aggregate( + [{ + '$group' : + { + _id : {topic_id: '$topic_id'}, + count : { $sum : 1} + } + }], function (err, result) { + result.forEach(function (row) { + var topic_id = row._id.topic_id; + var count = row.count; + + TopicModel.findOne({ + _id: topic_id + }, function (err, topic) { + + if (!topic) { + return; + } + + topic.collect_topic_count = count; + topic.save(function () { + console.log(topic.id, count); + }); + }); + }); +}); diff --git a/bin/generate_accesstoken.js b/bin/generate_accesstoken.js index fbe9780988..0ea6448431 100644 --- a/bin/generate_accesstoken.js +++ b/bin/generate_accesstoken.js @@ -1,3 +1,5 @@ +'use strict'; + // 一次性脚本 // 为所有老用户生成 accessToken diff --git a/common/at.js b/common/at.js index 8dbda554c9..44b9ac7462 100644 --- a/common/at.js +++ b/common/at.js @@ -5,6 +5,8 @@ * MIT Licensed */ +'use strict'; + /** * Module dependencies. */ @@ -23,12 +25,12 @@ var fetchUsers = function (text) { if (!text) { return []; } - + var ignoreRegexs = [ /```.+?```/g, // 去除单行的 ``` /^```[\s\S]+?^```/gm, // ``` 里面的是 pre 标签内容 /`[\s\S]+?`/g, // 同一行中,`some code` 中内容也不该被解析 - /^ .*/gm, // 4个空格也是 pre 标签,在这里 . 不会匹配换行 + /^ {4}.*/gm, // 4个空格也是 pre 标签,在这里 . 不会匹配换行 /\b\S*?@[^\s]*?\..+?\b/g, // somebody@gmail.com 会被去除 /\[@.+?\]\(\/.+?\)/g, // 已经被 link 的 username ]; diff --git a/common/cache.js b/common/cache.js index e8fd75abaa..b9e5a9cd1f 100644 --- a/common/cache.js +++ b/common/cache.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require('./redis'); var _ = require('lodash'); var logger = require('./logger'); @@ -37,7 +39,7 @@ var set = function (key, value, time, callback) { redis.setex(key, time, value, callback); } var duration = (new Date() - t); - logger.debug("Cache", "set", key, (duration + 'ms').green); + logger.debug('Cache', 'set', key, (duration + 'ms').green); }; exports.set = set; diff --git a/common/logger.js b/common/logger.js index ccd9908292..aef25b9dda 100644 --- a/common/logger.js +++ b/common/logger.js @@ -1,6 +1,8 @@ +'use strict'; + var config = require('../config'); -var env = process.env.NODE_ENV || "development" +var env = process.env.NODE_ENV || 'development'; var log4js = require('log4js'); @@ -12,6 +14,6 @@ log4js.configure({ }); var logger = log4js.getLogger('cheese'); -logger.setLevel(config.debug && env !== 'test' ? 'DEBUG' : 'ERROR') +logger.setLevel(config.debug && env !== 'test' ? 'DEBUG' : 'ERROR'); module.exports = logger; diff --git a/common/mail.js b/common/mail.js index a6d3b73b0a..d13b98d472 100644 --- a/common/mail.js +++ b/common/mail.js @@ -1,3 +1,5 @@ +'use strict'; + var mailer = require('nodemailer'); var smtpTransport = require('nodemailer-smtp-transport'); var config = require('../config'); @@ -5,7 +7,7 @@ var util = require('util'); var logger = require('./logger'); var transporter = mailer.createTransport(smtpTransport(config.mail_opts)); var SITE_ROOT_URL = 'http://' + config.host; -var async = require('async') +var async = require('async'); /** * Send an email @@ -24,14 +26,14 @@ var sendMail = function (data) { logger.error('send mail error', err, data); return done(err); } - return done() + return done(); }); }, function (err) { if (err) { return logger.error('send mail finally error', err, data); } - logger.info('send mail success', data) - }) + logger.info('send mail success', data); + }); }; exports.sendMail = sendMail; diff --git a/common/message.js b/common/message.js index ccc82212fc..9687af4f25 100644 --- a/common/message.js +++ b/common/message.js @@ -1,8 +1,8 @@ +'use strict'; + var models = require('../models'); var eventproxy = require('eventproxy'); var Message = models.Message; -var User = require('../proxy').User; -var messageProxy = require('../proxy/message'); var _ = require('lodash'); exports.sendReplyMessage = function (master_id, author_id, topic_id, reply_id, callback) { diff --git a/common/redis.js b/common/redis.js index 01939b070c..3ad0dd9826 100644 --- a/common/redis.js +++ b/common/redis.js @@ -1,6 +1,8 @@ +'use strict'; + var config = require('../config'); var Redis = require('ioredis'); -var logger = require('./logger') +var logger = require('./logger'); var client = new Redis({ port: config.redis_port, @@ -14,6 +16,6 @@ client.on('error', function (err) { logger.error('connect to redis error, check your redis config', err); process.exit(1); } -}) +}); exports = module.exports = client; diff --git a/common/render_helper.js b/common/render_helper.js index 73368d04ca..67c704b899 100644 --- a/common/render_helper.js +++ b/common/render_helper.js @@ -4,7 +4,7 @@ * MIT Licensed */ -"use strict"; +'use strict'; /** * Module dependencies. @@ -15,7 +15,7 @@ var _ = require('lodash'); var config = require('../config'); var validator = require('validator'); var jsxss = require('xss'); -var multiline = require('multiline') +var multiline = require('multiline'); // Set default options var md = new MarkdownIt(); diff --git a/common/store.js b/common/store.js index c29ed81753..a0dc040580 100644 --- a/common/store.js +++ b/common/store.js @@ -1,3 +1,5 @@ +'use strict'; + var qn = require('./store_qn'); var local = require('./store_local'); diff --git a/common/store_local.js b/common/store_local.js index 10bbd6e407..b2454d2f39 100644 --- a/common/store_local.js +++ b/common/store_local.js @@ -1,3 +1,5 @@ +'use strict'; + var config = require('../config'); var utility = require('utility'); var path = require('path'); diff --git a/common/store_qn.js b/common/store_qn.js index 0d3f73678e..a350cddd7d 100644 --- a/common/store_qn.js +++ b/common/store_qn.js @@ -1,3 +1,5 @@ +'use strict'; + var qn = require('qn'); var config = require('../config'); diff --git a/common/tools.js b/common/tools.js index d047c393b9..593efbe076 100644 --- a/common/tools.js +++ b/common/tools.js @@ -1,3 +1,5 @@ +'use strict'; + var bcrypt = require('bcryptjs'); var moment = require('moment'); @@ -9,10 +11,8 @@ exports.formatDate = function (date, friendly) { if (friendly) { return date.fromNow(); - } else { - return date.format('YYYY-MM-DD HH:mm'); } - + return date.format('YYYY-MM-DD HH:mm'); }; exports.validateId = function (str) { diff --git a/config.default.js b/config.default.js index f00dbf23df..9de46aa55b 100644 --- a/config.default.js +++ b/config.default.js @@ -1,6 +1,7 @@ /** * config */ +'use strict'; var path = require('path'); diff --git a/controllers/github.js b/controllers/github.js index 363cd7a4a8..26ae0a8d89 100644 --- a/controllers/github.js +++ b/controllers/github.js @@ -1,3 +1,5 @@ +'use strict'; + var Models = require('../models'); var User = Models.User; var authMiddleWare = require('../middlewares/auth'); diff --git a/controllers/message.js b/controllers/message.js index ffdaa111e8..f1066e2a01 100644 --- a/controllers/message.js +++ b/controllers/message.js @@ -1,3 +1,5 @@ +'use strict'; + var Message = require('../proxy').Message; var eventproxy = require('eventproxy'); @@ -24,7 +26,7 @@ exports.index = function (req, res, next) { Message.getMessageRelations(doc, epfill.group('message_ready')); }); }); - + Message.updateMessagesToRead(user_id, unread); }); diff --git a/controllers/reply.js b/controllers/reply.js index d41446f654..45ee7323e3 100644 --- a/controllers/reply.js +++ b/controllers/reply.js @@ -1,3 +1,5 @@ +'use strict'; + var validator = require('validator'); var _ = require('lodash'); var at = require('../common/at'); diff --git a/controllers/rss.js b/controllers/rss.js index ab105582ab..a01161375c 100644 --- a/controllers/rss.js +++ b/controllers/rss.js @@ -1,3 +1,5 @@ +'use strict'; + var config = require('../config'); var convert = require('data2xml')(); var Topic = require('../proxy').Topic; diff --git a/controllers/search.js b/controllers/search.js index d41c378208..1213d239cf 100644 --- a/controllers/search.js +++ b/controllers/search.js @@ -1,3 +1,5 @@ +'use strict'; + exports.index = function (req, res, next) { var q = req.query.q; q = encodeURIComponent(q); diff --git a/controllers/sign.js b/controllers/sign.js index 9fc076c3ec..d774259d59 100644 --- a/controllers/sign.js +++ b/controllers/sign.js @@ -1,3 +1,5 @@ +'use strict'; + var validator = require('validator'); var eventproxy = require('eventproxy'); var config = require('../config'); diff --git a/controllers/site.js b/controllers/site.js index 3ba16bb4c7..b5c0de22e9 100644 --- a/controllers/site.js +++ b/controllers/site.js @@ -5,6 +5,8 @@ * MIT Licensed */ +'use strict'; + /** * Module dependencies. */ @@ -16,7 +18,6 @@ var eventproxy = require('eventproxy'); var cache = require('../common/cache'); var xmlbuilder = require('xmlbuilder'); var renderHelper = require('../common/render_helper'); -var _ = require('lodash'); exports.index = function (req, res, next) { var page = parseInt(req.query.page, 10) || 1; @@ -29,7 +30,7 @@ exports.index = function (req, res, next) { // 取主题 var query = {}; if (!tab || tab === 'all') { - query.tab = {$ne: 'job'} + query.tab = {$ne: 'job'}; } else { if (tab === 'good') { query.good = true; @@ -145,5 +146,5 @@ exports.sitemap = function (req, res, next) { }; exports.appDownload = function (req, res, next) { - res.redirect('https://github.com/soliury/noder-react-native/blob/master/README.md') + res.redirect('https://github.com/soliury/noder-react-native/blob/master/README.md'); }; diff --git a/controllers/static.js b/controllers/static.js index b1b3f6fe67..333bd9c13e 100644 --- a/controllers/static.js +++ b/controllers/static.js @@ -1,4 +1,5 @@ -var multiline = require('multiline'); +'use strict'; + // static page // About exports.about = function (req, res, next) { @@ -21,15 +22,13 @@ exports.getstart = function (req, res) { exports.robots = function (req, res, next) { res.type('text/plain'); - res.send(multiline(function () {; -/* + res.send(` # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: # User-Agent: * # Disallow: / -*/ - })); +`); }; exports.api = function (req, res, next) { diff --git a/controllers/topic.js b/controllers/topic.js index 9f9ed16f3c..1b9c972264 100644 --- a/controllers/topic.js +++ b/controllers/topic.js @@ -2,6 +2,8 @@ * nodeclub - controllers/topic.js */ +'use strict'; + /** * Module dependencies. */ @@ -13,12 +15,11 @@ var User = require('../proxy').User; var Topic = require('../proxy').Topic; var TopicCollect = require('../proxy').TopicCollect; var EventProxy = require('eventproxy'); -var tools = require('../common/tools'); var store = require('../common/store'); var config = require('../config'); var _ = require('lodash'); var cache = require('../common/cache'); -var logger = require('../common/logger') +var logger = require('../common/logger'); /** * Topic page @@ -44,20 +45,20 @@ exports.index = function (req, res, next) { var events = ['topic', 'other_topics', 'no_reply_topics', 'is_collect']; var ep = EventProxy.create(events, function (topic, other_topics, no_reply_topics, is_collect) { - res.render('topic/index', { - topic: topic, - author_other_topics: other_topics, - no_reply_topics: no_reply_topics, - is_uped: isUped, - is_collect: is_collect, + res.render('topic/index', { + topic: topic, + author_other_topics: other_topics, + no_reply_topics: no_reply_topics, + is_uped: isUped, + is_collect: is_collect, + }); }); - }); ep.fail(next); Topic.getFullTopic(topic_id, ep.done(function (message, topic, author, replies) { if (message) { - logger.error('getFullTopic error topic_id: ' + topic_id) + logger.error('getFullTopic error topic_id: ' + topic_id); return res.renderError(message); } @@ -107,7 +108,7 @@ exports.index = function (req, res, next) { if (!currentUser) { ep.emit('is_collect', null); } else { - TopicCollect.getTopicCollect(currentUser._id, topic_id, ep.done('is_collect')) + TopicCollect.getTopicCollect(currentUser._id, topic_id, ep.done('is_collect')); } }; @@ -422,8 +423,8 @@ exports.de_collect = function (req, res, next) { if (err) { return next(err); } - if (removeResult.result.n == 0) { - return res.json({status: 'failed'}) + if (removeResult.result.n === 0) { + return res.json({status: 'failed'}); } User.getUserById(req.session.user._id, function (err, user) { @@ -446,29 +447,29 @@ exports.de_collect = function (req, res, next) { exports.upload = function (req, res, next) { var isFileLimit = false; req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { - file.on('limit', function () { - isFileLimit = true; + file.on('limit', function () { + isFileLimit = true; - res.json({ - success: false, - msg: 'File size too large. Max is ' + config.file_limit - }) + res.json({ + success: false, + msg: 'File size too large. Max is ' + config.file_limit }); + }); - store.upload(file, {filename: filename}, function (err, result) { - if (err) { - return next(err); - } - if (isFileLimit) { - return; - } - res.json({ - success: true, - url: result.url, - }); + store.upload(file, {filename: filename}, function (err, result) { + if (err) { + return next(err); + } + if (isFileLimit) { + return; + } + res.json({ + success: true, + url: result.url, }); - }); + }); + req.pipe(req.busboy); }; diff --git a/controllers/user.js b/controllers/user.js index ba997bff4c..6407a0e310 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -1,3 +1,5 @@ +'use strict'; + var User = require('../proxy').User; var Topic = require('../proxy').Topic; var Reply = require('../proxy').Reply; @@ -56,16 +58,16 @@ exports.index = function (req, res, next) { proxy.done(function (replies) { var topic_ids = replies.map(function (reply) { - return reply.topic_id.toString() - }) + return reply.topic_id.toString(); + }); topic_ids = _.uniq(topic_ids).slice(0, 5); // 只显示最近5条 var query = {_id: {'$in': topic_ids}}; var opt = {}; Topic.getTopicsByQuery(query, opt, proxy.done('recent_replies', function (recent_replies) { recent_replies = _.sortBy(recent_replies, function (topic) { - return topic_ids.indexOf(topic._id.toString()) - }) + return topic_ids.indexOf(topic._id.toString()); + }); return recent_replies; })); })); @@ -216,15 +218,15 @@ exports.listCollectedTopics = function (req, res, next) { TopicCollect.getTopicCollectsByUserId(user._id, opt, proxy.done(function (docs) { var ids = docs.map(function (doc) { - return String(doc.topic_id) - }) + return String(doc.topic_id); + }); var query = { _id: { '$in': ids } }; Topic.getTopicsByQuery(query, {}, proxy.done('topics', function (topics) { topics = _.sortBy(topics, function (topic) { - return ids.indexOf(String(topic._id)) - }) - return topics + return ids.indexOf(String(topic._id)); + }); + return topics; })); Topic.getCountByQuery(query, proxy.done(function (all_topics_count) { var pages = Math.ceil(all_topics_count / limit); @@ -317,8 +319,8 @@ exports.listReplies = function (req, res, next) { var query = {'_id': {'$in': topic_ids}}; Topic.getTopicsByQuery(query, {}, proxy.done('topics', function (topics) { topics = _.sortBy(topics, function (topic) { - return topic_ids.indexOf(topic._id.toString()) - }) + return topic_ids.indexOf(topic._id.toString()); + }); return topics; })); })); diff --git a/middlewares/auth.js b/middlewares/auth.js index 3615066859..0ee709eeb3 100644 --- a/middlewares/auth.js +++ b/middlewares/auth.js @@ -1,3 +1,5 @@ +'use strict'; + var mongoose = require('mongoose'); var UserModel = mongoose.model('User'); var Message = require('../proxy').Message; diff --git a/middlewares/conf.js b/middlewares/conf.js index 3257170746..ba1657d9cc 100644 --- a/middlewares/conf.js +++ b/middlewares/conf.js @@ -1,3 +1,5 @@ +'use strict'; + var config = require('../config'); exports.github = function (req, res, next) { diff --git a/middlewares/error_page.js b/middlewares/error_page.js index c92a4b4ded..bcb4a92a7e 100644 --- a/middlewares/error_page.js +++ b/middlewares/error_page.js @@ -1,3 +1,5 @@ +'use strict'; + // ErrorPage middleware exports.errorPage = function (req, res, next) { diff --git a/middlewares/github_strategy.js b/middlewares/github_strategy.js index 3ae932cb1e..283c03d760 100644 --- a/middlewares/github_strategy.js +++ b/middlewares/github_strategy.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = function (accessToken, refreshToken, profile, done) { profile.accessToken = accessToken; done(null, profile); diff --git a/middlewares/limit.js b/middlewares/limit.js index 64898574f2..3b6424c6df 100644 --- a/middlewares/limit.js +++ b/middlewares/limit.js @@ -1,4 +1,5 @@ -var config = require('../config'); +'use strict'; + var cache = require('../common/cache'); var moment = require('moment'); @@ -18,20 +19,22 @@ var makePerDayLimiter = function (identityName, identityFn) { if (err) { return next(err); } + count = count || 0; if (count < limitCount) { count += 1; cache.set(key, count, 60 * 60 * 24); res.set('X-RateLimit-Limit', limitCount); res.set('X-RateLimit-Remaining', limitCount - count); - next(); + return next(); + } + + res.status(403); + + if (options.showJson) { + res.send({success: false, error_msg: '频率限制:当前操作每天可以进行 ' + limitCount + ' 次'}); } else { - res.status(403); - if (options.showJson) { - res.send({success: false, error_msg: '频率限制:当前操作每天可以进行 ' + limitCount + ' 次'}); - } else { - res.render('notify/notify', { error: '频率限制:当前操作每天可以进行 ' + limitCount + ' 次'}); - } + res.render('notify/notify', { error: '频率限制:当前操作每天可以进行 ' + limitCount + ' 次'}); } }); }; @@ -45,7 +48,7 @@ exports.peruserperday = makePerDayLimiter('peruserperday', function (req) { exports.peripperday = makePerDayLimiter('peripperday', function (req) { var realIP = req.get('x-real-ip'); if (!realIP) { - throw new Error('should provice `x-real-ip` header') + throw new Error('should provice `x-real-ip` header'); } return realIP; }); diff --git a/middlewares/mongoose_log.js b/middlewares/mongoose_log.js index 67f5af8a6c..84ecbe45d2 100644 --- a/middlewares/mongoose_log.js +++ b/middlewares/mongoose_log.js @@ -1,3 +1,5 @@ +'use strict'; + var mongoose = require('mongoose'); var logger = require('../common/logger'); var config = require('../config'); @@ -6,14 +8,14 @@ if (config.debug) { var traceMQuery = function (method, info, query) { return function (err, result, millis) { if (err) { - logger.error('traceMQuery error:', err) + logger.error('traceMQuery error:', err); } var infos = []; - infos.push(query._collection.collection.name + "." + method.blue); + infos.push(query._collection.collection.name + '.' + method.blue); infos.push(JSON.stringify(info)); infos.push((millis + 'ms').green); - logger.debug("MONGO".magenta, infos.join(' ')); + logger.debug('MONGO'.magenta, infos.join(' ')); }; }; diff --git a/middlewares/proxy.js b/middlewares/proxy.js index a2102d1005..7bb994a168 100644 --- a/middlewares/proxy.js +++ b/middlewares/proxy.js @@ -1,7 +1,9 @@ +'use strict'; + var urllib = require('url'); var request = require('request'); -var logger = require('../common/logger') -var _ = require('lodash') +var logger = require('../common/logger'); +var _ = require('lodash'); var ALLOW_HOSTNAME = [ @@ -17,9 +19,9 @@ exports.proxy = function (req, res, next) { } request.get({ - url: url, - headers: _.omit(req.headers, ['cookie', 'refer']), - }) + url: url, + headers: _.omit(req.headers, ['cookie', 'refer']), + }) .on('response', function (response) { res.set(response.headers); }) diff --git a/middlewares/render.js b/middlewares/render.js index 0c10c27182..a97437534f 100644 --- a/middlewares/render.js +++ b/middlewares/render.js @@ -1,3 +1,5 @@ +'use strict'; + var logger = require('../common/logger'); // Patch res.render method to output logger @@ -10,7 +12,7 @@ exports.render = function (req, res, next) { res._render(view, options, fn); var duration = (new Date() - t); - logger.info("Render view", view, ("(" + duration + "ms)").green); + logger.info('Render view', view, ('(' + duration + 'ms)').green); }; next(); diff --git a/middlewares/request_log.js b/middlewares/request_log.js index de551f27ff..4eff90a10d 100644 --- a/middlewares/request_log.js +++ b/middlewares/request_log.js @@ -1,3 +1,5 @@ +'use strict'; + var logger = require('../common/logger'); var ignore = /^\/(public|agent)/; diff --git a/models/base_model.js b/models/base_model.js index 25e4caf0bd..14959f7adb 100644 --- a/models/base_model.js +++ b/models/base_model.js @@ -1,3 +1,5 @@ +'use strict'; + /** * 给所有的 Model 扩展功能 * http://mongoosejs.com/docs/plugins.html diff --git a/models/index.js b/models/index.js index 37ff4df38c..4a2f321b20 100644 --- a/models/index.js +++ b/models/index.js @@ -1,6 +1,8 @@ +'use strict'; + var mongoose = require('mongoose'); var config = require('../config'); -var logger = require('../common/logger') +var logger = require('../common/logger'); mongoose.connect(config.db, { server: {poolSize: 20} diff --git a/models/message.js b/models/message.js index dd03cfd226..e6fcb20eba 100644 --- a/models/message.js +++ b/models/message.js @@ -1,5 +1,7 @@ +'use strict'; + var mongoose = require('mongoose'); -var BaseModel = require("./base_model"); +var BaseModel = require('./base_model'); var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId; diff --git a/models/reply.js b/models/reply.js index a79a17e6fe..2f64e27343 100644 --- a/models/reply.js +++ b/models/reply.js @@ -1,5 +1,7 @@ +'use strict'; + var mongoose = require('mongoose'); -var BaseModel = require("./base_model"); +var BaseModel = require('./base_model'); var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId; diff --git a/models/topic.js b/models/topic.js index baecc34840..62ddd965cc 100644 --- a/models/topic.js +++ b/models/topic.js @@ -1,5 +1,7 @@ +'use strict'; + var mongoose = require('mongoose'); -var BaseModel = require("./base_model"); +var BaseModel = require('./base_model'); var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId; var config = require('../config'); @@ -37,9 +39,9 @@ TopicSchema.virtual('tabName').get(function () { if (pair) { return pair[1]; - } else { - return ''; } + return ''; + }); mongoose.model('Topic', TopicSchema); diff --git a/models/topic_collect.js b/models/topic_collect.js index 0850dc050c..401d158bba 100644 --- a/models/topic_collect.js +++ b/models/topic_collect.js @@ -1,5 +1,7 @@ +'use strict'; + var mongoose = require('mongoose'); -var BaseModel = require("./base_model"); +var BaseModel = require('./base_model'); var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId; diff --git a/models/user.js b/models/user.js index c5c66db372..99bf0c4062 100644 --- a/models/user.js +++ b/models/user.js @@ -1,9 +1,9 @@ +'use strict'; + var mongoose = require('mongoose'); -var BaseModel = require("./base_model"); -var renderHelper = require('../common/render_helper'); +var BaseModel = require('./base_model'); var Schema = mongoose.Schema; var utility = require('utility'); -var _ = require('lodash'); var UserSchema = new Schema({ name: { type: String}, diff --git a/oneapm.js b/oneapm.js index 7471c3e1c7..8b43c49651 100644 --- a/oneapm.js +++ b/oneapm.js @@ -5,6 +5,8 @@ * description of configuration variables and their potential values. */ +'use strict'; + var config = require('./config'); exports.config = { @@ -25,6 +27,6 @@ exports.config = { level : 'info' }, transaction_events: { - enabled: true + enabled: true } }; diff --git a/package.json b/package.json index 7e1d458f33..2cdb01ebe2 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,11 @@ "express-session": "1.12.1", "helmet": "1.3.0", "ioredis": "1.15.1", - "jpush-sdk": "3.3.2", "loader-builder": "2.4.1", "loader": "2.1.1", "lodash": "4.16.2", "log4js": "^0.6.29", "markdown-it": "6.0.0", - "memory-cache": "0.1.4", "method-override": "2.3.5", "moment": "2.15.2", "mongoose": "4.4.9", @@ -46,7 +44,6 @@ "ready": "0.1.1", "request": "2.74.0", "response-time": "2.3.1", - "superagent": "1.8.2", "utility": "1.6.0", "validator": "5.1.0", "xmlbuilder": "7.0.0", @@ -54,6 +51,7 @@ }, "devDependencies": { "errorhandler": "1.4.3", + "eslint": "^3.19.0", "istanbul": "0.4.2", "loader-connect": "1.0.1", "mm": "1.3.5", diff --git a/proxy/index.js b/proxy/index.js index fffc4c4feb..410034e455 100644 --- a/proxy/index.js +++ b/proxy/index.js @@ -1,3 +1,5 @@ +'use strict'; + exports.User = require('./user'); exports.Message = require('./message'); exports.Topic = require('./topic'); diff --git a/proxy/message.js b/proxy/message.js index 3af3468e91..62e82263ae 100644 --- a/proxy/message.js +++ b/proxy/message.js @@ -1,3 +1,5 @@ +'use strict'; + var EventProxy = require('eventproxy'); var _ = require('lodash'); @@ -20,24 +22,6 @@ exports.getMessagesCount = function (id, callback) { Message.count({master_id: id, has_read: false}, callback); }; - -/** - * 根据消息Id获取消息 - * Callback: - * - err, 数据库错误 - * - message, 消息对象 - * @param {String} id 消息ID - * @param {Function} callback 回调函数 - */ -exports.getMessageById = function (id, callback) { - Message.findOne({_id: id}, function (err, message) { - if (err) { - return callback(err); - } - getMessageRelations(message, callback); - }); -}; - var getMessageRelations = exports.getMessageRelations = function (message, callback) { if (message.type === 'reply' || message.type === 'reply2' || message.type === 'at') { var proxy = new EventProxy(); @@ -59,6 +43,23 @@ var getMessageRelations = exports.getMessageRelations = function (message, callb } }; +/** + * 根据消息Id获取消息 + * Callback: + * - err, 数据库错误 + * - message, 消息对象 + * @param {String} id 消息ID + * @param {Function} callback 回调函数 + */ +exports.getMessageById = function (id, callback) { + Message.findOne({_id: id}, function (err, message) { + if (err) { + return callback(err); + } + getMessageRelations(message, callback); + }); +}; + /** * 根据用户ID,获取已读消息列表 * Callback: diff --git a/proxy/reply.js b/proxy/reply.js index 5e95d45411..74a8e39a9b 100644 --- a/proxy/reply.js +++ b/proxy/reply.js @@ -1,7 +1,8 @@ +'use strict'; + var models = require('../models'); var Reply = models.Reply; var EventProxy = require('eventproxy'); -var tools = require('../common/tools'); var User = require('./user'); var at = require('../common/at'); diff --git a/proxy/topic.js b/proxy/topic.js index bdcad967d1..b858382b4e 100644 --- a/proxy/topic.js +++ b/proxy/topic.js @@ -1,13 +1,13 @@ +'use strict'; + var EventProxy = require('eventproxy'); var models = require('../models'); var Topic = models.Topic; var User = require('./user'); var Reply = require('./reply'); -var tools = require('../common/tools'); var at = require('../common/at'); var _ = require('lodash'); - /** * 根据主题ID获取主题 * Callback: diff --git a/proxy/topic_collect.js b/proxy/topic_collect.js index bb3e14fb12..96786cf8b3 100644 --- a/proxy/topic_collect.js +++ b/proxy/topic_collect.js @@ -1,5 +1,7 @@ +'use strict'; + var TopicCollect = require('../models').TopicCollect; -var _ = require('lodash') +var _ = require('lodash'); exports.getTopicCollect = function (userId, topicId, callback) { TopicCollect.findOne({user_id: userId, topic_id: topicId}, callback); @@ -7,7 +9,7 @@ exports.getTopicCollect = function (userId, topicId, callback) { exports.getTopicCollectsByUserId = function (userId, opt, callback) { var defaultOpt = {sort: '-create_at'}; - opt = _.assign(defaultOpt, opt) + opt = _.assign(defaultOpt, opt); TopicCollect.find({user_id: userId}, '', opt, callback); }; diff --git a/proxy/user.js b/proxy/user.js index 58b8a0a132..a03548845a 100644 --- a/proxy/user.js +++ b/proxy/user.js @@ -1,3 +1,5 @@ +'use strict'; + var models = require('../models'); var User = models.User; var utility = require('utility'); @@ -27,7 +29,7 @@ exports.getUsersByNames = function (names, callback) { * @param {Function} callback 回调函数 */ exports.getUserByLoginName = function (loginName, callback) { - User.findOne({'loginname': new RegExp('^'+loginName+'$', "i")}, callback); + User.findOne({'loginname': new RegExp('^'+loginName+'$', 'i')}, callback); }; /** diff --git a/test/api/v1/message.test.js b/test/api/v1/message.test.js index 441d739769..1f3631d104 100644 --- a/test/api/v1/message.test.js +++ b/test/api/v1/message.test.js @@ -1,3 +1,5 @@ +'use strict'; + var support = require('../../support/support'); var message = require('../../../common/message'); var MessageProxy = require('../../../proxy').Message; @@ -74,5 +76,5 @@ describe('test/api/v1/message.test.js', function () { }); }); }); - + }); diff --git a/test/api/v1/reply.test.js b/test/api/v1/reply.test.js index a6942f5674..5bd3ba46f9 100644 --- a/test/api/v1/reply.test.js +++ b/test/api/v1/reply.test.js @@ -1,3 +1,5 @@ +'use strict'; + var app = require('../../../app'); var request = require('supertest')(app); var pedding = require('pedding'); @@ -5,9 +7,9 @@ var support = require('../../support/support'); var should = require('should'); describe('test/api/v1/reply.test.js', function () { - + var mockTopic, mockReplyId; - + before(function (done) { support.ready(function () { support.createTopic(support.normalUser.id, function (err, topic) { @@ -89,7 +91,7 @@ describe('test/api/v1/reply.test.js', function () { }); it('should fail when topic not found', function (done) { - var notFoundTopicId = mockTopic.id.split("").reverse().join(""); + var notFoundTopicId = mockTopic.id.split('').reverse().join(''); request.post('/api/v1/topic/' + notFoundTopicId + '/replies') .send({ content: 'reply a topic from api', @@ -130,7 +132,7 @@ describe('test/api/v1/reply.test.js', function () { }); }); - + describe('create ups', function () { it('should up', function (done) { @@ -141,7 +143,7 @@ describe('test/api/v1/reply.test.js', function () { .end(function (err, res) { should.not.exists(err); res.body.success.should.true(); - res.body.action.should.equal("up"); + res.body.action.should.equal('up'); done(); }); }); @@ -154,7 +156,7 @@ describe('test/api/v1/reply.test.js', function () { .end(function (err, res) { should.not.exists(err); res.body.success.should.true(); - res.body.action.should.equal("down"); + res.body.action.should.equal('down'); done(); }); }); @@ -183,7 +185,7 @@ describe('test/api/v1/reply.test.js', function () { }); it('should fail when reply_id is not found', function (done) { - var notFoundReplyId = mockReplyId.split("").reverse().join(""); + var notFoundReplyId = mockReplyId.split('').reverse().join(''); request.post('/api/v1/reply/' + notFoundReplyId + '/ups') .send({ accesstoken: support.normalUser.accessToken @@ -201,5 +203,5 @@ describe('test/api/v1/reply.test.js', function () { }); }); - + }); diff --git a/test/api/v1/tools.test.js b/test/api/v1/tools.test.js index f5368e208d..212d1c5780 100644 --- a/test/api/v1/tools.test.js +++ b/test/api/v1/tools.test.js @@ -1,3 +1,5 @@ +'use strict'; + var app = require('../../../app'); var request = require('supertest')(app); var support = require('../../support/support'); diff --git a/test/api/v1/topic.test.js b/test/api/v1/topic.test.js index ef3b136d00..f72a1f9c3a 100644 --- a/test/api/v1/topic.test.js +++ b/test/api/v1/topic.test.js @@ -1,10 +1,12 @@ +'use strict'; + var app = require('../../../app'); var request = require('supertest')(app); var should = require('should'); var support = require('../../support/support'); describe('test/api/v1/topic.test.js', function () { - + var mockUser, mockTopic; var createdTopicId = null; @@ -73,7 +75,7 @@ describe('test/api/v1/topic.test.js', function () { }); it('should fail when topic not found', function (done) { - var notFoundTopicId = mockTopic.id.split("").reverse().join(""); + var notFoundTopicId = mockTopic.id.split('').reverse().join(''); request.get('/api/v1/topic/' + notFoundTopicId) .end(function (err, res) { should.not.exists(err); @@ -137,7 +139,7 @@ describe('test/api/v1/topic.test.js', function () { should.not.exists(err); res.body.success.should.true(); res.body.topic_id.should.be.String(); - createdTopicId = res.body.topic_id + createdTopicId = res.body.topic_id; done(); }); }); @@ -223,7 +225,7 @@ describe('test/api/v1/topic.test.js', function () { res.body.topic_id.should.eql(createdTopicId); done(); }); - }) - }) - + }); + }); + }); diff --git a/test/api/v1/topic_collect.test.js b/test/api/v1/topic_collect.test.js index 4b7e3bd5f9..0df5ccb25b 100644 --- a/test/api/v1/topic_collect.test.js +++ b/test/api/v1/topic_collect.test.js @@ -1,3 +1,5 @@ +'use strict'; + var app = require('../../../app'); var request = require('supertest')(app); var should = require('should'); @@ -99,7 +101,7 @@ describe('test/api/v1/topic_collect.test.js', function () { request.post('/api/v1/topic_collect/collect') .send({ accesstoken: mockUser.accessToken, - topic_id: mockTopic.id + "not_valid" + topic_id: mockTopic.id + 'not_valid' }) .end(function (err, res) { should.not.exists(err); @@ -110,7 +112,7 @@ describe('test/api/v1/topic_collect.test.js', function () { }); it('should fail when topic not found', function (done) { - var notFoundTopicId = mockTopic.id.split("").reverse().join(""); + var notFoundTopicId = mockTopic.id.split('').reverse().join(''); request.post('/api/v1/topic_collect/collect') .send({ accesstoken: mockUser.accessToken, @@ -223,7 +225,7 @@ describe('test/api/v1/topic_collect.test.js', function () { request.post('/api/v1/topic_collect/de_collect') .send({ accesstoken: mockUser.accessToken, - topic_id: mockTopic.id + "not_valid" + topic_id: mockTopic.id + 'not_valid' }) .end(function (err, res) { should.not.exists(err); @@ -234,7 +236,7 @@ describe('test/api/v1/topic_collect.test.js', function () { }); it('should fail when topic not found', function (done) { - var notFoundTopicId = mockTopic.id.split("").reverse().join(""); + var notFoundTopicId = mockTopic.id.split('').reverse().join(''); request.post('/api/v1/topic_collect/de_collect') .send({ accesstoken: mockUser.accessToken, diff --git a/test/api/v1/user.test.js b/test/api/v1/user.test.js index e32b6748bd..21dfcc498e 100644 --- a/test/api/v1/user.test.js +++ b/test/api/v1/user.test.js @@ -1,3 +1,5 @@ +'use strict'; + var app = require('../../../app'); var request = require('supertest')(app); var support = require('../../support/support'); @@ -13,7 +15,7 @@ describe('test/api/v1/user.test.js', function () { done(); }); }); - + describe('get /api/v1/user/:loginname', function () { it('should return user info', function (done) { @@ -37,5 +39,5 @@ describe('test/api/v1/user.test.js', function () { }); }); - + }); diff --git a/test/app.test.js b/test/app.test.js index 003b665568..bf2b15823f 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1,3 +1,5 @@ +'use strict'; + var request = require('supertest'); var app = require('../app'); var config = require('../config'); diff --git a/test/common/at.test.js b/test/common/at.test.js index 14f639764d..cc045b64e8 100644 --- a/test/common/at.test.js +++ b/test/common/at.test.js @@ -1,9 +1,9 @@ +'use strict'; var should = require('should'); var mm = require('mm'); var support = require('../support/support'); var eventproxy = require('eventproxy'); -var _ = require('lodash'); var at = require('../../common/at'); var message = require('../../common/message'); diff --git a/test/common/cache.test.js b/test/common/cache.test.js index 7235be5155..6d4f0238f6 100644 --- a/test/common/cache.test.js +++ b/test/common/cache.test.js @@ -1,3 +1,5 @@ +'use strict'; + var cache = require('../../common/cache'); var should = require('should'); diff --git a/test/common/mail.test.js b/test/common/mail.test.js index c900b2c367..9bfd532a2a 100644 --- a/test/common/mail.test.js +++ b/test/common/mail.test.js @@ -1,3 +1,5 @@ +'use strict'; + var mail = require('../../common/mail'); describe('test/common/mail.test.js', function () { diff --git a/test/common/message.test.js b/test/common/message.test.js index 1d522d8742..02251e6661 100644 --- a/test/common/message.test.js +++ b/test/common/message.test.js @@ -1,11 +1,10 @@ +'use strict'; + var should = require('should'); var app = require('../../app'); var request = require('supertest')(app); var mm = require('mm'); var support = require('../support/support'); -var _ = require('lodash'); -var pedding = require('pedding'); -var multiline = require('multiline'); var MessageService = require('../../common/message'); var eventproxy = require('eventproxy'); var ReplyProxy = require('../../proxy').Reply; @@ -50,8 +49,8 @@ describe('test/common/message.test.js', function () { topic.title, ]; texts.forEach(function (text) { - res.text.should.containEql(text) - }) + res.text.should.containEql(text); + }); done(err); }); }); @@ -75,11 +74,11 @@ describe('test/common/message.test.js', function () { '中@了你', ]; texts.forEach(function (text) { - res.text.should.containEql(text) - }) + res.text.should.containEql(text); + }); done(err); }); }); }); }); -}) +}); diff --git a/test/common/render_helper.test.js b/test/common/render_helper.test.js index 1b67846012..678c38020f 100644 --- a/test/common/render_helper.test.js +++ b/test/common/render_helper.test.js @@ -1,45 +1,31 @@ +'use strict'; + var should = require('should'); -var app = require('../../app'); -var request = require('supertest')(app); -var mm = require('mm'); -var support = require('../support/support'); -var _ = require('lodash'); -var pedding = require('pedding'); -var multiline = require('multiline'); var renderHelper = require('../../common/render_helper'); describe('test/common/render_helper.test.js', function () { describe('#markdown', function () { it('should render code inline', function () { - var text = multiline(function () {; - /* -`var a = 1;` - */ - }); + var text = '`var a = 1;`'; var rendered = renderHelper.markdown(text); rendered.should.equal('
var a = 1;
var a = 1;\n
var a = 1;