Skip to content

Commit

Permalink
Code style update (#732)
Browse files Browse the repository at this point in the history
* unify naming element of forEach

* omit curly braces of simple return statement
  • Loading branch information
1v9 authored Oct 20, 2019
1 parent d5149a3 commit d2f619a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<br>
<a href="https://bestpractices.coreinfrastructure.org/projects/2625"><img src="https://img.shields.io/cii/level/2625?style=flat-square" title="Core Infrastructure Initiative Best Practices"></a>
<a href="https://travis-ci.org/theme-next/hexo-theme-next?branch=master"><img src="https://img.shields.io/travis/theme-next/hexo-theme-next/master?style=flat-square&logo=travis%20ci" title="Travis CI [Linux]"></a>
<a href="https://app.codacy.com/manual/theme-next/hexo-theme-next/dashboard"><img src="https://img.shields.io/codacy/grade/72f7fe7609c2438a92069f448e5a341a/master?style=flat-square&logo=codacy" title="Project Grade"></a>
<a href="https://app.codacy.com/manual/theme-next/hexo-theme-next/dashboard"><img src="https://img.shields.io/codacy/grade/3f91d806eb204fc2b597543151fff87d/master?style=flat-square&logo=codacy" title="Project Grade"></a>
<img src="https://img.shields.io/snyk/vulnerabilities/github/theme-next/hexo-theme-next?style=flat-square" title="Vulnerabilities">
<br>
<img src="https://user-images.githubusercontent.com/16272760/63487983-da41b080-c4df-11e9-951c-64883a8a5e9b.png">
Expand Down
2 changes: 1 addition & 1 deletion docs/ru/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<br>
<a href="https://bestpractices.coreinfrastructure.org/projects/2625"><img src="https://img.shields.io/cii/level/2625?style=flat-square" title="Инициатива базовой инфраструктуры: передовой опыт"></a>
<a href="https://travis-ci.org/theme-next/hexo-theme-next?branch=master"><img src="https://img.shields.io/travis/theme-next/hexo-theme-next/master?style=flat-square&logo=travis%20ci" title="Travis CI [Linux]"></a>
<a href="https://app.codacy.com/manual/theme-next/hexo-theme-next/dashboard"><img src="https://img.shields.io/codacy/grade/72f7fe7609c2438a92069f448e5a341a/master?style=flat-square&logo=codacy" title="Оценка проекта"></a>
<a href="https://app.codacy.com/manual/theme-next/hexo-theme-next/dashboard"><img src="https://img.shields.io/codacy/grade/3f91d806eb204fc2b597543151fff87d/master?style=flat-square&logo=codacy" title="Оценка проекта"></a>
<img src="https://img.shields.io/snyk/vulnerabilities/github/theme-next/hexo-theme-next?style=flat-square" title="Vulnerabilities">
<br>
<img src="https://user-images.githubusercontent.com/16272760/63487983-da41b080-c4df-11e9-951c-64883a8a5e9b.png">
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<br>
<a href="https://bestpractices.coreinfrastructure.org/projects/2625"><img src="https://img.shields.io/cii/level/2625?style=flat-square" title="Core Infrastructure Initiative Best Practices"></a>
<a href="https://travis-ci.org/theme-next/hexo-theme-next?branch=master"><img src="https://img.shields.io/travis/theme-next/hexo-theme-next/master?style=flat-square&logo=travis%20ci" title="Travis CI [Linux]"></a>
<a href="https://app.codacy.com/manual/theme-next/hexo-theme-next/dashboard"><img src="https://img.shields.io/codacy/grade/72f7fe7609c2438a92069f448e5a341a/master?style=flat-square&logo=codacy" title="Project Grade"></a>
<a href="https://app.codacy.com/manual/theme-next/hexo-theme-next/dashboard"><img src="https://img.shields.io/codacy/grade/3f91d806eb204fc2b597543151fff87d/master?style=flat-square&logo=codacy" title="Project Grade"></a>
<img src="https://img.shields.io/snyk/vulnerabilities/github/theme-next/hexo-theme-next?style=flat-square" title="Vulnerabilities">
<br>
<img src="https://user-images.githubusercontent.com/16272760/63487983-da41b080-c4df-11e9-951c-64883a8a5e9b.png">
Expand Down
6 changes: 1 addition & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ gulp.task('validate:languages', cb => {
}
});

if (errors.length === 0) {
return cb();
} else {
return cb(errors);
}
return errors.length === 0 ? cb() : cb(errors);
});

gulp.task('default', gulp.series('lint', 'validate:config', 'validate:languages'));
6 changes: 3 additions & 3 deletions layout/_partials/comments.swig
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<script{{ pjax }}>
(function() {
let commentButton = document.querySelectorAll('.comment-button');
commentButton.forEach(item => {
commentButton.forEach(element => {
let commentClass = item.classList[2];
item.addEventListener('click', () => {
element.addEventListener('click', () => {
commentButton.forEach(rmActive => rmActive.classList.remove('active'));
item.classList.add('active');
element.classList.add('active');
document.querySelectorAll('.comment-position').forEach(rmActive => rmActive.classList.remove('active'));
document.querySelector(`.comment-position.${commentClass}`).classList.add('active');
{%- if theme.comments.storage %}
Expand Down
4 changes: 1 addition & 3 deletions scripts/filters/default-injects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const points = require('../events/lib/injects-point');
hexo.extend.filter.register('theme_inject', injects => {
let filePath = hexo.theme.config.custom_file_path;

if (!filePath) {
return;
}
if (!filePath) return;

points.views.forEach(key => {
if (filePath[key]) {
Expand Down
8 changes: 2 additions & 6 deletions scripts/filters/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ hexo.extend.filter.register('after_post_render', data => {
exturl : theme.exturl,
lazyload: theme.lazyload
};
if (!filters.excerpt && !filters.exturl && !filters.lazyload) {
return;
}
if (!filters.excerpt && !filters.exturl && !filters.lazyload) return;
const cheerio = require('cheerio');
const $ = cheerio.load(data.content, {
decodeEntities: false
Expand Down Expand Up @@ -54,9 +52,7 @@ hexo.extend.filter.register('after_post_render', data => {
});
var length = 0;
elements.each((i, o) => {
if (length > theme.auto_excerpt.length) {
return;
}
if (length > theme.auto_excerpt.length) return;
length += $(o).text().length;
_$.root().append($(o).remove());
});
Expand Down
4 changes: 1 addition & 3 deletions scripts/helpers/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
hexo.extend.helper.register('next_font', () => {
var config = hexo.theme.config.font;

if (!config || !config.enable) {
return '';
}
if (!config || !config.enable) return '';

var fontDisplay = '&display=swap';
var fontSubset = '&subset=latin,latin-ext';
Expand Down
16 changes: 6 additions & 10 deletions source/js/local-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ window.addEventListener('DOMContentLoaded', () => {

const getIndexByWord = (word, text, caseSensitive) => {
let wordLen = word.length;
if (wordLen === 0) {
return [];
}
if (wordLen === 0) return [];
let startPosition = 0;
let position = [];
let index = [];
Expand Down Expand Up @@ -116,9 +114,7 @@ window.addEventListener('DOMContentLoaded', () => {
// Perform local searching
datas.forEach(data => {
// Only match articles with not empty titles
if (!data.title) {
return;
}
if (!data.title) return;
let searchTextCount = 0;
let title = data.title.trim();
let titleInLowerCase = title.toLowerCase();
Expand Down Expand Up @@ -244,11 +240,11 @@ window.addEventListener('DOMContentLoaded', () => {
.then(res => {
// Get the contents from search data
isfetched = true;
datas = isXml ? [...new DOMParser().parseFromString(res, 'text/xml').querySelectorAll('entry')].map(item => {
datas = isXml ? [...new DOMParser().parseFromString(res, 'text/xml').querySelectorAll('entry')].map(element => {
return {
title : item.querySelector('title').innerHTML,
content: item.querySelector('content').innerHTML,
url : item.querySelector('url').innerHTML
title : element.querySelector('title').innerHTML,
content: element.querySelector('content').innerHTML,
url : element.querySelector('url').innerHTML
};
}) : JSON.parse(res);

Expand Down
46 changes: 23 additions & 23 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ NexT.utils = {
* One-click copy code support.
*/
registerCopyCode: function() {
document.querySelectorAll('figure.highlight').forEach(e => {
document.querySelectorAll('figure.highlight').forEach(element => {
const initButton = button => {
if (CONFIG.copycode.style === 'mac') {
button.innerHTML = '<i class="fa fa-clipboard"></i>';
Expand All @@ -69,13 +69,13 @@ NexT.utils = {
};
const box = document.createElement('div');
box.classList.add('highlight-wrap');
e.wrap(box);
e.parentNode.insertAdjacentHTML('beforeend', '<div class="copy-btn"></div>');
var button = e.parentNode.querySelector('.copy-btn');
element.wrap(box);
element.parentNode.insertAdjacentHTML('beforeend', '<div class="copy-btn"></div>');
var button = element.parentNode.querySelector('.copy-btn');
button.addEventListener('click', event => {
var target = event.currentTarget;
var code = [...target.parentNode.querySelectorAll('.code .line')].map(element => {
return element.innerText;
var code = [...target.parentNode.querySelectorAll('.code .line')].map(line => {
return line.innerText;
}).join('\n');
var ta = document.createElement('textarea');
var yPosition = window.scrollY;
Expand Down Expand Up @@ -112,28 +112,28 @@ NexT.utils = {
},

wrapTableWithBox: function() {
document.querySelectorAll('table').forEach(table => {
document.querySelectorAll('table').forEach(element => {
const box = document.createElement('div');
box.className = 'table-container';
table.wrap(box);
element.wrap(box);
});
},

registerVideoIframe: function() {
document.querySelectorAll('iframe').forEach(element => {
const SUPPORTED_PLAYERS = [
const supported = [
'www.youtube.com',
'player.vimeo.com',
'player.youku.com',
'player.bilibili.com',
'www.tudou.com'
];
const pattern = new RegExp(SUPPORTED_PLAYERS.join('|'));
if (!element.parentNode.matches('.video-container') && element.src.search(pattern) > 0) {
].some(host => element.src.includes(host));
if (supported && !element.parentNode.matches('.video-container')) {
const box = document.createElement('div');
box.className = 'video-container';
element.wrap(box);
let width = Number(element.width); let height = Number(element.height);
let width = Number(element.width);
let height = Number(element.height);
if (width && height) {
element.parentNode.style.paddingTop = (height / width * 100) + '%';
}
Expand Down Expand Up @@ -179,20 +179,20 @@ NexT.utils = {
*/
registerTabsTag: function() {
// Binding `nav-tabs` & `tab-content` by real time permalink changing.
document.querySelectorAll('.tabs ul.nav-tabs .tab').forEach(tab => {
tab.addEventListener('click', event => {
document.querySelectorAll('.tabs ul.nav-tabs .tab').forEach(element => {
element.addEventListener('click', event => {
event.preventDefault();
var target = event.currentTarget;
// Prevent selected tab to select again.
if (!target.classList.contains('active')) {
// Add & Remove active class on `nav-tabs` & `tab-content`.
[...target.parentNode.children].forEach(item => {
item.classList.remove('active');
[...target.parentNode.children].forEach(element => {
element.classList.remove('active');
});
target.classList.add('active');
var tActive = document.getElementById(target.querySelector('a').getAttribute('href').replace('#', ''));
[...tActive.parentNode.children].forEach(item => {
item.classList.remove('active');
[...tActive.parentNode.children].forEach(element => {
element.classList.remove('active');
});
tActive.classList.add('active');
// Trigger event
Expand All @@ -208,8 +208,8 @@ NexT.utils = {

registerCanIUseTag: function() {
// Get responsive height passed from iframe.
window.addEventListener('message', e => {
var data = e.data;
window.addEventListener('message', event => {
var data = event.data;
if ((typeof data === 'string') && (data.indexOf('ciu_embed') > -1)) {
var featureID = data.split(':')[1];
var height = data.split(':')[2];
Expand Down Expand Up @@ -301,8 +301,8 @@ NexT.utils = {
rootMargin: marginTop + 'px 0px -100% 0px',
threshold : 0
});
sections.forEach(item => {
item && intersectionObserver.observe(item);
sections.forEach(element => {
element && intersectionObserver.observe(element);
});
}
createIntersectionObserver(document.documentElement.scrollHeight);
Expand Down

0 comments on commit d2f619a

Please sign in to comment.