diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..cb72458 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,11 @@ +{ + "curly" : true, + "eqeqeq" : true, + "indent" : 2, + "latedef" : true, + "newcap" : true, + "quotmark": "single", + "strict" : true, + "undef" : true, + "node" : true +} diff --git a/package.json b/package.json index cf0efb7..2641859 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "scripts": { "test": "./node_modules/.bin/mocha test/index.js", "test-cov": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", - "gen-doc": "./node_modules/.bin/jsdoc2md --src src/telegram.js -t README.hbs > README.md" + "gen-doc": "./node_modules/.bin/jsdoc2md --src src/telegram.js -t README.hbs > README.md", + "jshint": "./node_modules/.bin/jshint src test" }, "author": "Yago Pérez ", "license": "MIT", @@ -32,6 +33,7 @@ "del": "^2.0.2", "istanbul": "^0.3.17", "jsdoc-to-markdown": "^1.2.0", + "jshint": "^2.8.0", "mocha": "^2.2.5", "mocha-lcov-reporter": "0.0.2", "should": "^7.0.1" diff --git a/src/telegram.js b/src/telegram.js index a1d94b6..19b1e60 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1,9 +1,11 @@ +'use strict'; + var TelegramBotWebHook = require('./telegramWebHook'); var TelegramBotPolling = require('./telegramPolling'); var debug = require('debug')('node-telegram-bot-api'); var EventEmitter = require('events').EventEmitter; -var Promise = require("bluebird"); -var request = require("request"); +var Promise = require('bluebird'); +var request = require('request'); var stream = require('stream'); var util = require('util'); var mime = require('mime'); @@ -56,7 +58,7 @@ util.inherits(TelegramBot, EventEmitter); TelegramBot.prototype.initPolling = function() { if (this._polling) { this._polling.abort = true; - this._polling.lastRequest.cancel("Polling restart"); + this._polling.lastRequest.cancel('Polling restart'); } this._polling = new TelegramBotPolling(this.token, this.options.polling, this.processUpdate); }; @@ -111,7 +113,7 @@ TelegramBot.prototype._buildURL = function(path) { host: 'api.telegram.org', pathname: '/bot' + this.token + '/' + path }); -} +}; /** * Returns basic information about the bot in form of a `User` object. @@ -462,6 +464,6 @@ TelegramBot.prototype.downloadFile = function(fileId, downloadDir) { }); }); -} +}; module.exports = TelegramBot; diff --git a/src/telegramPolling.js b/src/telegramPolling.js index abd5708..97d3ec9 100644 --- a/src/telegramPolling.js +++ b/src/telegramPolling.js @@ -1,5 +1,7 @@ +'use strict'; + var debug = require('debug')('node-telegram-bot-api'); -var Promise = require("bluebird"); +var Promise = require('bluebird'); var request = require('request'); var URL = require('url'); @@ -7,7 +9,7 @@ var requestPromise = Promise.promisify(request); var TelegramBotPolling = function (token, options, callback) { options = options || {}; - if (typeof options === "function") { + if (typeof options === 'function') { callback = options; options = {}; } diff --git a/src/telegramWebHook.js b/src/telegramWebHook.js index 97119b5..cd03940 100644 --- a/src/telegramWebHook.js +++ b/src/telegramWebHook.js @@ -1,7 +1,8 @@ +'use strict'; + var debug = require('debug')('node-telegram-bot-api'); var https = require('https'); var http = require('http'); -var util = require('util'); var fs = require('fs'); var TelegramBotWebHook = function (token, options, callback) { @@ -26,7 +27,7 @@ var TelegramBotWebHook = function (token, options, callback) { } this._webServer.listen(options.port, options.host, function () { - debug("WebHook listening on port %s", options.port); + debug('WebHook listening on port %s', options.port); }); }; diff --git a/test/.jshintrc b/test/.jshintrc new file mode 100644 index 0000000..a0d4f0e --- /dev/null +++ b/test/.jshintrc @@ -0,0 +1,12 @@ +{ + "mocha" : true, + "curly" : true, + "eqeqeq" : true, + "indent" : 2, + "latedef" : true, + "newcap" : true, + "quotmark": "single", + "strict" : true, + "undef" : true, + "node" : true +} diff --git a/test/index.js b/test/index.js index fa92cef..cef66f7 100644 --- a/test/index.js +++ b/test/index.js @@ -1,10 +1,12 @@ +'use strict'; + var TelegramPolling = require('../src/telegramPolling'); var Telegram = require('../index'); var request = require('request'); var should = require('should'); var fs = require('fs'); -process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; +process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; var TOKEN = process.env.TEST_TELEGRAM_TOKEN; if (!TOKEN) { throw new Error('Bot token not provided'); @@ -69,7 +71,7 @@ describe('Telegram', function () { method: 'POST', json: true, headers: { - "content-type": "application/json", + 'content-type': 'application/json', }, body: {update_id: 0, message: {text: 'test'}} }); @@ -94,7 +96,7 @@ describe('Telegram', function () { method: 'POST', json: true, headers: { - "content-type": "application/json", + 'content-type': 'application/json', }, rejectUnhauthorized: false, body: {update_id: 0, message: {text: 'test'}} @@ -190,7 +192,7 @@ describe('Telegram', function () { describe('#sendChatAction', function () { it('should send a chat action', function (done) { var bot = new Telegram(TOKEN); - var action = "typing"; + var action = 'typing'; bot.sendChatAction(USERID, action).then(function (resp) { resp.should.be.exactly(true); done();