From c2e4672e86a573d528a24b96fab63977172c0d64 Mon Sep 17 00:00:00 2001 From: weyusi <43627182+weyusi@users.noreply.github.com> Date: Sat, 6 Jul 2019 12:50:06 +0930 Subject: [PATCH] chore(deps-dev): update eslint requirement from ^5.9.0 to ^6.0.1 (#3606) * chore(deps-dev): update eslint requirement from ^5.9.0 to ^6.0.1 * refactor: call hasOwnProperty from Object.prototype https://eslint.org/docs/6.0.0/rules/no-prototype-builtins --- lib/hexo/render.js | 2 +- lib/plugins/filter/post_permalink.js | 2 +- lib/plugins/helper/list_archives.js | 2 +- lib/plugins/helper/list_categories.js | 6 +++--- lib/plugins/helper/list_posts.js | 2 +- lib/plugins/helper/list_tags.js | 4 ++-- lib/plugins/helper/paginator.js | 6 +++--- lib/plugins/helper/tagcloud.js | 4 ++-- lib/plugins/helper/toc.js | 4 ++-- lib/plugins/processor/post.js | 2 +- package.json | 2 +- test/scripts/helpers/paginator.js | 2 +- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/hexo/render.js b/lib/hexo/render.js index 0c467d884e..40029d46e0 100644 --- a/lib/hexo/render.js +++ b/lib/hexo/render.js @@ -112,7 +112,7 @@ Render.prototype.renderSync = function(data, options) { }; function toString(result, options) { - if (!options.hasOwnProperty('toString') || typeof result === 'string') return result; + if (!Object.prototype.hasOwnProperty.call(options, 'toString') || typeof result === 'string') return result; if (typeof options.toString === 'function') { return options.toString(result); diff --git a/lib/plugins/filter/post_permalink.js b/lib/plugins/filter/post_permalink.js index 7a958f9a3c..9fc519c933 100644 --- a/lib/plugins/filter/post_permalink.js +++ b/lib/plugins/filter/post_permalink.js @@ -35,7 +35,7 @@ function postPermalinkFilter(data) { for (let i = 0, len = keys.length; i < len; i++) { const key = keys[i]; - if (meta.hasOwnProperty(key)) continue; + if (Object.prototype.hasOwnProperty.call(meta, key)) continue; // Use Object.getOwnPropertyDescriptor to copy getters to avoid "Maximum call // stack size exceeded" error diff --git a/lib/plugins/helper/list_archives.js b/lib/plugins/helper/list_archives.js index a4cd54a9ba..861e92fa15 100644 --- a/lib/plugins/helper/list_archives.js +++ b/lib/plugins/helper/list_archives.js @@ -8,7 +8,7 @@ function listArchivesHelper(options = {}) { let { format } = options; const type = options.type || 'monthly'; const { style = 'list', transform, separator = ', ' } = options; - const showCount = options.hasOwnProperty('show_count') ? options.show_count : true; + const showCount = Object.prototype.hasOwnProperty.call(options, 'show_count') ? options.show_count : true; const className = options.class || 'archive'; const order = options.order || -1; let result = ''; diff --git a/lib/plugins/helper/list_categories.js b/lib/plugins/helper/list_categories.js index b6575adf00..f867ed6903 100644 --- a/lib/plugins/helper/list_categories.js +++ b/lib/plugins/helper/list_categories.js @@ -1,7 +1,7 @@ 'use strict'; function listCategoriesHelper(categories, options) { - if (!options && (!categories || !categories.hasOwnProperty('length'))) { + if (!options && (!categories || !Object.prototype.hasOwnProperty.call(categories, 'length'))) { options = categories; categories = this.site.categories; } @@ -10,13 +10,13 @@ function listCategoriesHelper(categories, options) { options = options || {}; const { style = 'list', transform, separator = ', ', suffix = '' } = options; - const showCount = options.hasOwnProperty('show_count') ? options.show_count : true; + const showCount = Object.prototype.hasOwnProperty.call(options, 'show_count') ? options.show_count : true; const className = options.class || 'category'; const depth = options.depth ? parseInt(options.depth, 10) : 0; const orderby = options.orderby || 'name'; const order = options.order || 1; const showCurrent = options.show_current || false; - const childrenIndicator = options.hasOwnProperty('children_indicator') ? options.children_indicator : false; + const childrenIndicator = Object.prototype.hasOwnProperty.call(options, 'children_indicator') ? options.children_indicator : false; const prepareQuery = parent => { const query = {}; diff --git a/lib/plugins/helper/list_posts.js b/lib/plugins/helper/list_posts.js index b809f1ea25..3161edd71b 100644 --- a/lib/plugins/helper/list_posts.js +++ b/lib/plugins/helper/list_posts.js @@ -1,7 +1,7 @@ 'use strict'; function listPostsHelper(posts, options) { - if (!options && (!posts || !posts.hasOwnProperty('length'))) { + if (!options && (!posts || !Object.prototype.hasOwnProperty.call(posts, 'length'))) { options = posts; posts = this.site.posts; } diff --git a/lib/plugins/helper/list_tags.js b/lib/plugins/helper/list_tags.js index 25b80e6313..a972563c58 100644 --- a/lib/plugins/helper/list_tags.js +++ b/lib/plugins/helper/list_tags.js @@ -1,7 +1,7 @@ 'use strict'; function listTagsHelper(tags, options) { - if (!options && (!tags || !tags.hasOwnProperty('length'))) { + if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) { options = tags; tags = this.site.tags; } @@ -10,7 +10,7 @@ function listTagsHelper(tags, options) { options = options || {}; const { style = 'list', transform, separator = ', ', suffix = '' } = options; - const showCount = options.hasOwnProperty('show_count') ? options.show_count : true; + const showCount = Object.prototype.hasOwnProperty.call(options, 'show_count') ? options.show_count : true; const className = options.class || 'tag'; const orderby = options.orderby || 'name'; const order = options.order || 1; diff --git a/lib/plugins/helper/paginator.js b/lib/plugins/helper/paginator.js index cbd248b20b..78850bf8b8 100644 --- a/lib/plugins/helper/paginator.js +++ b/lib/plugins/helper/paginator.js @@ -3,14 +3,14 @@ function paginatorHelper(options = {}) { const current = options.current || this.page.current || 0; const total = options.total || this.page.total || 1; - const endSize = options.hasOwnProperty('end_size') ? +options.end_size : 1; - const midSize = options.hasOwnProperty('mid_size') ? +options.mid_size : 2; + const endSize = Object.prototype.hasOwnProperty.call(options, 'end_size') ? +options.end_size : 1; + const midSize = Object.prototype.hasOwnProperty.call(options, 'mid_size') ? +options.mid_size : 2; const { space = '…', transform } = options; const base = options.base || this.page.base || ''; const format = options.format || `${this.config.pagination_dir}/%d/`; const prevText = options.prev_text || 'Prev'; const nextText = options.next_text || 'Next'; - const prevNext = options.hasOwnProperty('prev_next') ? options.prev_next : true; + const prevNext = Object.prototype.hasOwnProperty.call(options, 'prev_next') ? options.prev_next : true; if (!current) return ''; diff --git a/lib/plugins/helper/tagcloud.js b/lib/plugins/helper/tagcloud.js index 7c107bf837..58c953d9ac 100644 --- a/lib/plugins/helper/tagcloud.js +++ b/lib/plugins/helper/tagcloud.js @@ -158,7 +158,7 @@ const colorNames = { }; function tagcloudHelper(tags, options) { - if (!options && (!tags || !tags.hasOwnProperty('length'))) { + if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) { options = tags; tags = this.site.tags; } @@ -251,7 +251,7 @@ function Color(color) { Color.prototype.parse = function(color) { color = color.toLowerCase(); - if (colorNames.hasOwnProperty(color)) { + if (Object.prototype.hasOwnProperty.call(colorNames, color)) { const obj = colorNames[color]; this.r = obj.r; diff --git a/lib/plugins/helper/toc.js b/lib/plugins/helper/toc.js index 9decb86e76..ddf4023816 100644 --- a/lib/plugins/helper/toc.js +++ b/lib/plugins/helper/toc.js @@ -7,14 +7,14 @@ function tocHelper(str, options = {}) { if (!cheerio) cheerio = require('cheerio'); const $ = cheerio.load(str); - const headingsMaxDepth = options.hasOwnProperty('max_depth') ? options.max_depth : 6; + const headingsMaxDepth = Object.prototype.hasOwnProperty.call(options, 'max_depth') ? options.max_depth : 6; const headingsSelector = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].slice(0, headingsMaxDepth).join(','); const headings = $(headingsSelector); if (!headings.length) return ''; const className = options.class || 'toc'; - const listNumber = options.hasOwnProperty('list_number') ? options.list_number : true; + const listNumber = Object.prototype.hasOwnProperty.call(options, 'list_number') ? options.list_number : true; let result = `
    `; const lastNumber = [0, 0, 0, 0, 0, 0]; let firstLevel = 0; diff --git a/lib/plugins/processor/post.js b/lib/plugins/processor/post.js index cf422d9099..56da936086 100644 --- a/lib/plugins/processor/post.js +++ b/lib/plugins/processor/post.js @@ -54,7 +54,7 @@ module.exports = ctx => { data.slug = info.title; if (file.params.published) { - if (!data.hasOwnProperty('published')) data.published = true; + if (!Object.prototype.hasOwnProperty.call(data, 'published')) data.published = true; } else { data.published = false; } diff --git a/package.json b/package.json index cb5cc57da8..03563fbeff 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "@easyops/git-exec-and-restage": "^1.0.4", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", - "eslint": "^5.9.0", + "eslint": "^6.0.1", "eslint-ci": "^1.0.0", "eslint-config-hexo": "^3.0.0", "hexo-renderer-marked": "^1.0.1", diff --git a/test/scripts/helpers/paginator.js b/test/scripts/helpers/paginator.js index 6bdd23ca79..d02ea0d75c 100644 --- a/test/scripts/helpers/paginator.js +++ b/test/scripts/helpers/paginator.js @@ -27,7 +27,7 @@ describe('paginator', () => { const total = data.total; const pages = data.pages; const space = data.space || '…'; - const prevNext = data.hasOwnProperty('prev_next') ? data.prev_next : true; + const prevNext = Object.prototype.hasOwnProperty.call(data, 'prev_next') ? data.prev_next : true; let num; if (prevNext && current > 1) {