Skip to content

Commit

Permalink
chore: enable no-console eslint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Sep 20, 2019
1 parent f7d9688 commit d0fb625
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"es6": true
},
"rules": {
"no-console": 0,
"no-console": 1,
"block-scoped-var": 1,
"curly": 1,
"eqeqeq": 1,
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/eastday/sh.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = async (ctx) => {
entity.description += content;
}
} catch (error) {
console.log(error);
logger.error(error);
}

return entity;
Expand Down
6 changes: 4 additions & 2 deletions lib/routes/gov/city/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const logger = require('@/utils/logger');

module.exports = async (ctx) => {
const { name, category } = ctx.params;
let url = '';
Expand All @@ -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 === '') {
Expand All @@ -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');
}
};
3 changes: 2 additions & 1 deletion lib/routes/gov/city/nanjing/getContent.js
Original file line number Diff line number Diff line change
@@ -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 = '';
Expand All @@ -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 };
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/gov/city/nanjing/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const getContent = require('./getContent');
const logger = require('@/utils/logger');

const TOTAL_PAGE = 3;

Expand All @@ -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 === '') {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/gov/news/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions lib/routes/gov/province/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const logger = require('@/utils/logger');

module.exports = async (ctx) => {
const { name, category } = ctx.params;
let url = '';
Expand All @@ -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 === '') {
Expand All @@ -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');
}
};
3 changes: 2 additions & 1 deletion lib/routes/gov/province/jiangsu/getContent.js
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion lib/routes/gov/province/jiangsu/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const logger = require('@/utils/logger');

const getContent = require('./getContent');

const TOTAL_PAGE = 1;
Expand Down Expand Up @@ -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 === '') {
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/gov/shanxi/rst.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/gov/suzhou/news.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/mail/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/namoc/announcement.js
Original file line number Diff line number Diff line change
@@ -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/';

Expand Down Expand Up @@ -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}`);
}
})
);
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/namoc/exhibition.js
Original file line number Diff line number Diff line change
@@ -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/';

Expand Down Expand Up @@ -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}`);
}
})
);
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/namoc/media.js
Original file line number Diff line number Diff line change
@@ -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/';

Expand Down Expand Up @@ -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}`);
}
})
);
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/namoc/news.js
Original file line number Diff line number Diff line change
@@ -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/';

Expand Down Expand Up @@ -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}`);
}
})
);
Expand Down
6 changes: 0 additions & 6 deletions lib/routes/nogizaka46/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 0 additions & 1 deletion lib/routes/people/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion lib/routes/universities/sysu/sdcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/routes/zhilian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d0fb625

Please sign in to comment.