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 b137e0590e..cb183d04ce 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,14 +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; - let result = ''; + 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 7d9754e80d..cf586a0221 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 4e73b1b7e3..c955747c80 100644 --- a/lib/plugins/helper/paginator.js +++ b/lib/plugins/helper/paginator.js @@ -3,17 +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 space = options.hasOwnProperty('space') ? options.space : '…'; + 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 transform = options.transform; - let result = ''; - let i; + 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 3a44dc22eb..7c08130faf 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) {