Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use eslint instead of jslint #942

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.debug.js
*.min.js
node_modules/*
65 changes: 65 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
44 changes: 0 additions & 44 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:

node_js:
- 4
- 5
- 6
- stable

addons:
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -45,7 +48,6 @@ test-cov cov: install pretest
--timeout $(TEST_TIMEOUT) \
$(TESTS)


build:
@./node_modules/loader-builder/bin/builder views .

Expand Down
2 changes: 2 additions & 0 deletions api/v1/message.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var eventproxy = require('eventproxy');
var Message = require('../../proxy').Message;
var at = require('../../common/at');
Expand Down
4 changes: 3 additions & 1 deletion api/v1/middleware.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var UserModel = require('../../models').User;
var eventproxy = require('eventproxy');
var validator = require('validator');
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 20 additions & 18 deletions api/v1/reply.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var eventproxy = require('eventproxy');
var validator = require('validator');
var Topic = require('../../proxy').Topic;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
});
});

});
};

Expand Down
2 changes: 2 additions & 0 deletions api/v1/tools.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var eventproxy = require('eventproxy');

var accesstoken = function (req, res, next) {
Expand Down
14 changes: 8 additions & 6 deletions api/v1/topic.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var models = require('../../models');
var TopicModel = models.Topic;
var TopicProxy = require('../../proxy').Topic;
Expand Down Expand Up @@ -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;
Expand All @@ -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});
})
});

};

Expand Down Expand Up @@ -230,7 +232,7 @@ exports.update = function (req, res, next) {
});
});
} else {
res.status(403)
res.status(403);
return res.send({success: false, error_msg: '对不起,你不能编辑此话题。'});
}
});
Expand Down
18 changes: 10 additions & 8 deletions api/v1/topic_collect.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var eventproxy = require('eventproxy');
var TopicProxy = require('../../proxy').Topic;
var TopicCollectProxy = require('../../proxy').TopicCollect;
Expand All @@ -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;
}));

});
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions api/v1/user.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,15 +24,15 @@ 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条

var query = {_id: {'$in': topic_ids}};
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;
}));
Expand Down
2 changes: 2 additions & 0 deletions api_router_v1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var express = require('express');
var topicController = require('./api/v1/topic');
var topicCollectController = require('./api/v1/topic_collect');
Expand Down
Loading