From d0fb6254ffb17d9d93df09109a8bf92d6c0a2b8e Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 20 Sep 2019 15:26:58 +0800 Subject: [PATCH] chore: enable no-console eslint rule --- .eslintrc | 2 +- lib/routes/eastday/sh.js | 3 ++- lib/routes/gov/city/index.js | 6 ++++-- lib/routes/gov/city/nanjing/getContent.js | 3 ++- lib/routes/gov/city/nanjing/index.js | 3 ++- lib/routes/gov/news/index.js | 3 ++- lib/routes/gov/province/index.js | 6 ++++-- lib/routes/gov/province/jiangsu/getContent.js | 3 ++- lib/routes/gov/province/jiangsu/index.js | 4 +++- lib/routes/gov/shanxi/rst.js | 3 ++- lib/routes/gov/suzhou/news.js | 3 ++- lib/routes/mail/imap.js | 3 ++- lib/routes/namoc/announcement.js | 3 ++- lib/routes/namoc/exhibition.js | 3 ++- lib/routes/namoc/media.js | 3 ++- lib/routes/namoc/news.js | 3 ++- lib/routes/nogizaka46/news.js | 6 ------ lib/routes/people/env.js | 1 - lib/routes/universities/sysu/sdcs.js | 1 - lib/routes/zhilian/index.js | 4 +--- 20 files changed, 37 insertions(+), 29 deletions(-) diff --git a/.eslintrc b/.eslintrc index a85401527e86eb..c726440dac604f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,7 +10,7 @@ "es6": true }, "rules": { - "no-console": 0, + "no-console": 1, "block-scoped-var": 1, "curly": 1, "eqeqeq": 1, diff --git a/lib/routes/eastday/sh.js b/lib/routes/eastday/sh.js index 117556d0d31562..c7ab57b7dd01fd 100644 --- a/lib/routes/eastday/sh.js +++ b/lib/routes/eastday/sh.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const logger = require('@/utils/logger'); module.exports = async (ctx) => { const domain = 'http://wap.eastday.com'; @@ -42,7 +43,7 @@ module.exports = async (ctx) => { entity.description += content; } } catch (error) { - console.log(error); + logger.error(error); } return entity; diff --git a/lib/routes/gov/city/index.js b/lib/routes/gov/city/index.js index 577e95ae82649e..ca25fcf7c5284d 100644 --- a/lib/routes/gov/city/index.js +++ b/lib/routes/gov/city/index.js @@ -1,3 +1,5 @@ +const logger = require('@/utils/logger'); + module.exports = async (ctx) => { const { name, category } = ctx.params; let url = ''; @@ -7,7 +9,7 @@ module.exports = async (ctx) => { url = 'http://www.nanjing.gov.cn'; break; default: - console.log('URL pattern not matched'); + logger.error('URL pattern not matched'); } if (url === '') { @@ -20,7 +22,7 @@ module.exports = async (ctx) => { const responseData = await getRSS(url, category); ctx.state.data = responseData; } catch (error) { - console.error(error); + logger.error(error); ctx.throw(404, 'Cannot find page'); } }; diff --git a/lib/routes/gov/city/nanjing/getContent.js b/lib/routes/gov/city/nanjing/getContent.js index 899e33cd963bd5..955eabb417ef8d 100644 --- a/lib/routes/gov/city/nanjing/getContent.js +++ b/lib/routes/gov/city/nanjing/getContent.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const logger = require('@/utils/logger'); module.exports = async (link, totalPage = 1) => { let title = ''; @@ -22,7 +23,7 @@ module.exports = async (link, totalPage = 1) => { } } } catch (err) { - console.error('Cannot load page content'); + logger.error('Cannot load page content'); } return { title, link, description, item }; diff --git a/lib/routes/gov/city/nanjing/index.js b/lib/routes/gov/city/nanjing/index.js index a8c7eb50d4426c..54ca0522718be1 100644 --- a/lib/routes/gov/city/nanjing/index.js +++ b/lib/routes/gov/city/nanjing/index.js @@ -1,4 +1,5 @@ const getContent = require('./getContent'); +const logger = require('@/utils/logger'); const TOTAL_PAGE = 3; @@ -19,7 +20,7 @@ module.exports = async (homePage, category) => { url = `${homePage}/mszx/`; break; default: - console.log('URL pattern not matched'); + logger.error('URL pattern not matched'); } if (url === '') { diff --git a/lib/routes/gov/news/index.js b/lib/routes/gov/news/index.js index 5e85eb3c536ed5..d601a9e39249fb 100644 --- a/lib/routes/gov/news/index.js +++ b/lib/routes/gov/news/index.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const logger = require('@/utils/logger'); module.exports = async (ctx) => { const uid = ctx.params.uid; @@ -23,7 +24,7 @@ module.exports = async (ctx) => { title = '中国政府网 - 国务院信息'; break; default: - console.log('pattern not matched'); + logger.error('pattern not matched'); } const listData = await got.get(url); const $ = cheerio.load(listData.data); diff --git a/lib/routes/gov/province/index.js b/lib/routes/gov/province/index.js index a35bba13549122..40eeb07c76751b 100644 --- a/lib/routes/gov/province/index.js +++ b/lib/routes/gov/province/index.js @@ -1,3 +1,5 @@ +const logger = require('@/utils/logger'); + module.exports = async (ctx) => { const { name, category } = ctx.params; let url = ''; @@ -7,7 +9,7 @@ module.exports = async (ctx) => { url = 'http://www.jiangsu.gov.cn'; break; default: - console.log('URL pattern not matched'); + logger.error('URL pattern not matched'); } if (url === '') { @@ -20,7 +22,7 @@ module.exports = async (ctx) => { const responseData = await getRSS(url, category); ctx.state.data = responseData; } catch (error) { - console.error(error); + logger.error(error); ctx.throw(404, 'Cannot find page'); } }; diff --git a/lib/routes/gov/province/jiangsu/getContent.js b/lib/routes/gov/province/jiangsu/getContent.js index f116da3eeac2a9..f4455f91ae4d34 100644 --- a/lib/routes/gov/province/jiangsu/getContent.js +++ b/lib/routes/gov/province/jiangsu/getContent.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const logger = require('@/utils/logger'); const urlTemplate = (homePage, cid, uid) => { let template = `${homePage}/col/col${cid}/index.html`; @@ -30,7 +31,7 @@ module.exports = async (homePage, cid, uid, totalPage = 1) => { } } } catch (err) { - console.error('Cannot load page content'); + logger.error('Cannot load page content'); } const link = urlTemplate(homePage, cid); diff --git a/lib/routes/gov/province/jiangsu/index.js b/lib/routes/gov/province/jiangsu/index.js index 2c3d4cf04d5349..10c562b24c064b 100644 --- a/lib/routes/gov/province/jiangsu/index.js +++ b/lib/routes/gov/province/jiangsu/index.js @@ -1,3 +1,5 @@ +const logger = require('@/utils/logger'); + const getContent = require('./getContent'); const TOTAL_PAGE = 1; @@ -52,7 +54,7 @@ module.exports = async (homePage, category) => { uid = 158542; break; default: - console.log('URL pattern not matched'); + logger.error('URL pattern not matched'); } if (cid === '') { diff --git a/lib/routes/gov/shanxi/rst.js b/lib/routes/gov/shanxi/rst.js index 32e6e02a58d720..ad73fccd403125 100644 --- a/lib/routes/gov/shanxi/rst.js +++ b/lib/routes/gov/shanxi/rst.js @@ -1,6 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const resolve_url = require('url').resolve; +const logger = require('@/utils/logger'); module.exports = async (ctx) => { const category = ctx.params.category; @@ -28,7 +29,7 @@ module.exports = async (ctx) => { title = '山西人事考试专栏 - 其他考试'; break; default: - console.log('pattern not matched'); + logger.error('pattern not matched'); } const response = await got({ method: 'get', diff --git a/lib/routes/gov/suzhou/news.js b/lib/routes/gov/suzhou/news.js index 4538a0afc5c409..c59ff6bf9a0f75 100644 --- a/lib/routes/gov/suzhou/news.js +++ b/lib/routes/gov/suzhou/news.js @@ -1,6 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const iconv = require('iconv-lite'); +const logger = require('@/utils/logger'); module.exports = async (ctx) => { const uid = ctx.params.uid; @@ -16,7 +17,7 @@ module.exports = async (ctx) => { title = '苏州市政府 - 政务要闻'; break; default: - console.log('pattern not matched'); + logger.error('pattern not matched'); } const response = await got({ method: 'get', diff --git a/lib/routes/mail/imap.js b/lib/routes/mail/imap.js index ebeb3c7d9692c3..8b28eaede20263 100644 --- a/lib/routes/mail/imap.js +++ b/lib/routes/mail/imap.js @@ -2,6 +2,7 @@ const ImapClient = require('emailjs-imap-client').default; const queryString = require('query-string'); const config = require('@/config').value; const parser = require('mailparser').simpleParser; +const logger = require('@/utils/logger'); module.exports = async (ctx) => { const email = ctx.params.email; @@ -32,7 +33,7 @@ module.exports = async (ctx) => { .then(() => imap.selectMailbox('INBOX')) .then((mailbox) => imap.listMessages('INBOX', `${Math.max(mailbox.exists - 9, 1)}:*`, ['uid', 'flags', 'envelope', 'body[]'])) .then((messages) => messages) - .catch((error) => console.log(error)) + .catch((error) => logger.error(error)) .finally(() => { imap.close(); }); diff --git a/lib/routes/namoc/announcement.js b/lib/routes/namoc/announcement.js index a16a75fcf4d405..d23a625010f6a6 100644 --- a/lib/routes/namoc/announcement.js +++ b/lib/routes/namoc/announcement.js @@ -1,6 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); +const logger = require('@/utils/logger'); const host = 'http://www.namoc.org/xwzx/tzgg/2017gonggao/'; @@ -35,7 +36,7 @@ module.exports = async (ctx) => { proList.push(es); return Promise.resolve(single); } catch (err) { - console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); + logger.error(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); } }) ); diff --git a/lib/routes/namoc/exhibition.js b/lib/routes/namoc/exhibition.js index bc20786da70a24..12640d7e0ab403 100644 --- a/lib/routes/namoc/exhibition.js +++ b/lib/routes/namoc/exhibition.js @@ -1,6 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); +const logger = require('@/utils/logger'); const host = 'http://www.namoc.org/zsjs/zlzx/'; @@ -34,7 +35,7 @@ module.exports = async (ctx) => { proList.push(es); return Promise.resolve(single); } catch (err) { - console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); + logger.error(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); } }) ); diff --git a/lib/routes/namoc/media.js b/lib/routes/namoc/media.js index ae1c52aa67838d..195ae300bf834c 100644 --- a/lib/routes/namoc/media.js +++ b/lib/routes/namoc/media.js @@ -1,6 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); +const logger = require('@/utils/logger'); const host = 'http://www.namoc.org/xwzx/mtry/2018/'; @@ -36,7 +37,7 @@ module.exports = async (ctx) => { proList.push(es); return Promise.resolve(single); } catch (err) { - console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); + logger.error(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); } }) ); diff --git a/lib/routes/namoc/news.js b/lib/routes/namoc/news.js index b9c0469bb3aec8..2be05e8af1286a 100644 --- a/lib/routes/namoc/news.js +++ b/lib/routes/namoc/news.js @@ -1,6 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); +const logger = require('@/utils/logger'); const host = 'http://www.namoc.org/xwzx/xw/xinwen/'; @@ -36,7 +37,7 @@ module.exports = async (ctx) => { proList.push(es); return Promise.resolve(single); } catch (err) { - console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); + logger.error(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); } }) ); diff --git a/lib/routes/nogizaka46/news.js b/lib/routes/nogizaka46/news.js index b4d9011ab189e6..c71682063c3ea4 100644 --- a/lib/routes/nogizaka46/news.js +++ b/lib/routes/nogizaka46/news.js @@ -23,12 +23,6 @@ module.exports = async (ctx) => { list .map((index, item) => { item = $(item); - console.log( - item - .find('.title strong a') - .first() - .text() - ); return { title: item .find('.title strong a') diff --git a/lib/routes/people/env.js b/lib/routes/people/env.js index 1ae4ee97ba3edf..c1b9bdc577e2d3 100644 --- a/lib/routes/people/env.js +++ b/lib/routes/people/env.js @@ -55,7 +55,6 @@ module.exports = async (ctx) => { .split(/\s+/); if (date.length > 0) { date = date[0].replace(/(年|月)/g, '/').replace('日', ' ') + ':00'; - console.log(date); } else { date = new Date(); } diff --git a/lib/routes/universities/sysu/sdcs.js b/lib/routes/universities/sysu/sdcs.js index 117351ecc50e95..a1c0e2504e9ef3 100644 --- a/lib/routes/universities/sysu/sdcs.js +++ b/lib/routes/universities/sysu/sdcs.js @@ -76,7 +76,6 @@ module.exports = async (ctx) => { for (let i = 0; i < block_index.length; i++) { const block_news = $('#block-views-homepage-block-' + block_index[i].index + '> div > div.view-content > div > ul > li > a'); for (let j = 0; j < block_news.length; j++) { - console.log(block_news[j]); item_data.push(getDetail(block_news[j], block_index[i].description_header)); } } diff --git a/lib/routes/zhilian/index.js b/lib/routes/zhilian/index.js index 4509a63df1e6a3..9e20ddcad99e5b 100644 --- a/lib/routes/zhilian/index.js +++ b/lib/routes/zhilian/index.js @@ -11,9 +11,7 @@ module.exports = async (ctx) => { url: city_api_url, }); const city_response_data = city_response.data.data; - if (city_response_data.name === undefined) { - console.log('No This City'); - } else { + if (city_response_data.name) { const job_api_url = `https://fe-api.zhaopin.com/c/i/sou?pageSize=20&cityId=${city_response_data.code}&workExperience=-1&education=5&companyType=-1&employmentType=-1&jobWelfareTag=-1&kw=${encodeURI(keyword)}&kt=3`; const job_response = await got({ method: 'get',