From 4acb332f39e6c12d2cab4e94614e082af220c510 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Wed, 11 Sep 2019 05:19:50 +0100 Subject: [PATCH 1/3] style: no-useless-concat & one-var (uninitialized) --- .eslintrc.json | 13 ------------- lib/plugins/tag/img.js | 4 +--- test/scripts/filters/external_link.js | 4 +--- test/scripts/filters/meta_generator.js | 18 ++++++------------ test/scripts/hexo/multi_config_path.js | 10 ++++------ 5 files changed, 12 insertions(+), 37 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 258cc463d4..a0cae2f875 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,19 +1,6 @@ { "extends": "hexo", "root": true, - "rules": { - "one-var": 0, - "operator-linebreak": [ - 2, - "after" - ], - "comma-spacing": [ - 2, - { - "after": true - } - ] - }, "parserOptions": { "ecmaVersion": 2018 } diff --git a/lib/plugins/tag/img.js b/lib/plugins/tag/img.js index 99aeccf7b9..43c05343a9 100644 --- a/lib/plugins/tag/img.js +++ b/lib/plugins/tag/img.js @@ -33,7 +33,7 @@ module.exports = ctx => { return function imgTag(args, content) { const classes = []; - let src; + let src, width, height, title, alt; // Find image URL and class name while (args.length > 0) { @@ -46,8 +46,6 @@ module.exports = ctx => { } } - let width, height, title, alt; - // Find image width and height if (args && args.length) { if (!/\D+/.test(args[0])) { diff --git a/test/scripts/filters/external_link.js b/test/scripts/filters/external_link.js index 5eec7074fe..655874bde5 100644 --- a/test/scripts/filters/external_link.js +++ b/test/scripts/filters/external_link.js @@ -178,9 +178,7 @@ describe('External link - post', () => { }; it('disabled', () => { - const content = 'foo' - + 'Hexo' - + 'bar'; + const content = 'fooHexobar'; const data = {content}; hexo.config.external_link.enable = false; diff --git a/test/scripts/filters/meta_generator.js b/test/scripts/filters/meta_generator.js index dcb4cbfa88..1acc426420 100644 --- a/test/scripts/filters/meta_generator.js +++ b/test/scripts/filters/meta_generator.js @@ -35,34 +35,28 @@ describe('Meta Generator', () => { }); it('ignore empty head tag', () => { - const content = '' - + '' - + ''; + const content = ''; hexo.config.meta_generator = true; const result = metaGenerator(content); const $ = cheerio.load(result); $('meta[name="generator"]').length.should.eql(1); - const expected = '' - + '' - + ''; + const expected = ''; result.should.eql(expected); }); it('apply to first non-empty head tag only', () => { - const content = '' - + '' - + ''; + const content = ''; hexo.config.meta_generator = true; const result = metaGenerator(content); const $ = cheerio.load(result); $('meta[name="generator"]').length.should.eql(1); - const expected = '' - + '' - + ''; + const expected = ''; result.should.eql(expected); }); diff --git a/test/scripts/hexo/multi_config_path.js b/test/scripts/hexo/multi_config_path.js index 32ee1bcc46..ce05ff8b03 100644 --- a/test/scripts/hexo/multi_config_path.js +++ b/test/scripts/hexo/multi_config_path.js @@ -163,7 +163,7 @@ describe('config flag handling', () => { mcp(base, notFile).should.eql(pathFn.join(base, '_config.yml')); hexo.log.reader[0].type.should.eql('warning'); hexo.log.reader[0].msg.should.eql('Config file ' + notFile - + ' not found, using default.'); + + ' not found, using default.'); }); it('1 not found file warning absolute', () => { @@ -172,7 +172,7 @@ describe('config flag handling', () => { mcp(base, notFile).should.eql(pathFn.join(base, '_config.yml')); hexo.log.reader[0].type.should.eql('warning'); hexo.log.reader[0].msg.should.eql('Config file ' + notFile - + ' not found, using default.'); + + ' not found, using default.'); }); it('combined config output', () => { @@ -194,8 +194,7 @@ describe('config flag handling', () => { mcp(base, 'notafile.yml,alsonotafile.json').should.not.eql(combinedPath); hexo.log.reader[11].type.should.eql('error'); - hexo.log.reader[11].msg.should.eql('No config files found.' - + ' Using _config.yml.'); + hexo.log.reader[11].msg.should.eql('No config files found. Using _config.yml.'); }); it('combine config output with absolute paths', () => { @@ -278,7 +277,6 @@ describe('config flag handling', () => { hexo.log.reader[7].type.should.eql('info'); hexo.log.reader[7].msg.should.eql('Config based on 1 files'); hexo.log.reader[11].type.should.eql('error'); - hexo.log.reader[11].msg.should.eql('No config files found.' - + ' Using _config.yml.'); + hexo.log.reader[11].msg.should.eql('No config files found. Using _config.yml.'); }); }); From 4b901657113b45cbf904f4391c82fe22db1d7c22 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Wed, 11 Sep 2019 05:39:50 +0100 Subject: [PATCH 2/3] style: operator-linebreak --- lib/hexo/index.js | 4 ++-- lib/plugins/filter/after_render/meta_generator.js | 4 ++-- lib/plugins/helper/toc.js | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/hexo/index.js b/lib/hexo/index.js index 755f72bd11..de179e09a7 100644 --- a/lib/hexo/index.js +++ b/lib/hexo/index.js @@ -138,8 +138,8 @@ class Hexo { const mcp = multiConfigPath(this); - this.config_path = args.config ? mcp(base, args.config, args.output) : - join(base, '_config.yml'); + this.config_path = args.config ? mcp(base, args.config, args.output) + : join(base, '_config.yml'); registerModels(this); diff --git a/lib/plugins/filter/after_render/meta_generator.js b/lib/plugins/filter/after_render/meta_generator.js index 2673ea4876..ac36b33cfd 100644 --- a/lib/plugins/filter/after_render/meta_generator.js +++ b/lib/plugins/filter/after_render/meta_generator.js @@ -2,8 +2,8 @@ function hexoMetaGeneratorInject(data) { const { config } = this; - if (!config.meta_generator || - data.match(/`; diff --git a/lib/plugins/helper/toc.js b/lib/plugins/helper/toc.js index 3601588284..51d0ef33e0 100644 --- a/lib/plugins/helper/toc.js +++ b/lib/plugins/helper/toc.js @@ -23,9 +23,7 @@ function tocHelper(str, options = {}) { function getId(ele) { const id = $(ele).attr('id'); const $parent = $(ele).parent(); - return id || - ($parent.length < 1 ? null : - getId($parent)); + return id || ($parent.length < 1 ? null : getId($parent)); } headings.each(function() { From e690ecab6612a2e53134e93878eaacdd82d8ec30 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Thu, 17 Oct 2019 07:50:17 +0100 Subject: [PATCH 3/3] style(external_link): operator-linebreak --- .../filter/after_post_render/external_link.js | 12 ++++++------ lib/plugins/filter/after_render/external_link.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/plugins/filter/after_post_render/external_link.js b/lib/plugins/filter/after_post_render/external_link.js index 43c8dd348e..10a0c0a3b2 100644 --- a/lib/plugins/filter/after_post_render/external_link.js +++ b/lib/plugins/filter/after_post_render/external_link.js @@ -11,8 +11,8 @@ const urlObj = (str) => { }; const isExternal = (url, config) => { - const exclude = Array.isArray(config.external_link.exclude) ? config.external_link.exclude : - [config.external_link.exclude]; + const exclude = Array.isArray(config.external_link.exclude) ? config.external_link.exclude + : [config.external_link.exclude]; const data = urlObj(url); const host = data.hostname; const sitehost = typeof urlObj(config.url) === 'object' ? urlObj(config.url).hostname : config.url; @@ -34,16 +34,16 @@ const isExternal = (url, config) => { function externalLinkFilter(data) { const { config } = this; - if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' || - config.external_link === true) { + if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' + || config.external_link === true) { config.external_link = Object.assign({ enable: true, field: 'site', exclude: '' }, config.external_link); } - if (config.external_link === false || config.external_link.enable === false || - config.external_link.field !== 'post') return; + if (config.external_link === false || config.external_link.enable === false + || config.external_link.field !== 'post') return; data.content = data.content.replace(//gi, (str, hrefStr, href) => { if (/target=/gi.test(str) || !isExternal(href, config)) return str; diff --git a/lib/plugins/filter/after_render/external_link.js b/lib/plugins/filter/after_render/external_link.js index d064bf13d5..92ed1f57fa 100644 --- a/lib/plugins/filter/after_render/external_link.js +++ b/lib/plugins/filter/after_render/external_link.js @@ -17,8 +17,8 @@ const urlObj = (str) => { * @returns {Boolean} True if the link doesn't have protocol or link has same host with config.url */ const isExternal = (url, config) => { - const exclude = Array.isArray(config.external_link.exclude) ? config.external_link.exclude : - [config.external_link.exclude]; + const exclude = Array.isArray(config.external_link.exclude) ? config.external_link.exclude + : [config.external_link.exclude]; const data = urlObj(url); const host = data.hostname; const sitehost = typeof urlObj(config.url) === 'object' ? urlObj(config.url).hostname : config.url; @@ -40,16 +40,16 @@ const isExternal = (url, config) => { function externalLinkFilter(data) { const { config } = this; - if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' || - config.external_link === true) { + if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' + || config.external_link === true) { config.external_link = Object.assign({ enable: true, field: 'site', exclude: '' }, config.external_link); } - if (config.external_link === false || config.external_link.enable === false || - config.external_link.field !== 'site') return; + if (config.external_link === false || config.external_link.enable === false + || config.external_link.field !== 'site') return; data = data.replace(//gi, (str, hrefStr, href) => { if (/target=/gi.test(str) || !isExternal(href, config)) return str;