Skip to content

Commit 703282f

Browse files
committed
improve: require semicolon on .js files
1 parent 6f26f32 commit 703282f

File tree

5 files changed

+210
-205
lines changed

5 files changed

+210
-205
lines changed

.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"browser": true,
1111
"jquery": true
1212
},
13+
"rules": {
14+
"semi": ["error", "always"]
15+
},
1316
"overrides": [
1417
{
1518
"files": "**/*.md",
@@ -18,6 +21,7 @@
1821
{
1922
"files": "**/*.md/*.js",
2023
"rules": {
24+
"semi": ["error", "never"],
2125
"array-callback-return": "off",
2226
"no-var": "error",
2327
"n/handle-callback-err": "off",
@@ -33,6 +37,7 @@
3337
"**/guide/migrating-4.md/*.js"
3438
],
3539
"rules": {
40+
"semi": ["error", "never"],
3641
"no-var": "off",
3742
"object-shorthand": "off",
3843
"prefer-arrow-callback": "off",

js/app.js

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,115 @@
11
$(function () {
2-
const doc = $(document)
2+
const doc = $(document);
33

44
// top link
55
$('#top').click(function (e) {
6-
$('html, body').animate({ scrollTop: 0 }, 500)
7-
return false
8-
})
6+
$('html, body').animate({ scrollTop: 0 }, 500);
7+
return false;
8+
});
99

1010
// scrolling links
11-
let added
11+
let added;
1212
doc.scroll(function (e) {
1313
if (doc.scrollTop() > 5) {
14-
if (added) return
15-
added = true
16-
$('body').addClass('scroll')
14+
if (added) return;
15+
added = true;
16+
$('body').addClass('scroll');
1717
} else {
18-
$('body').removeClass('scroll')
19-
added = false
18+
$('body').removeClass('scroll');
19+
added = false;
2020
}
21-
})
21+
});
2222

2323
// menu bar
2424

2525
const headings = $('h2, h3').map(function (i, el) {
2626
return {
2727
top: $(el).offset().top - 200,
2828
id: el.id
29-
}
30-
})
29+
};
30+
});
3131

3232
function closest () {
33-
let h
34-
const top = $(window).scrollTop()
35-
let i = headings.length
33+
let h;
34+
const top = $(window).scrollTop();
35+
let i = headings.length;
3636
while (i--) {
37-
h = headings[i]
38-
if (top >= h.top) return h
37+
h = headings[i];
38+
if (top >= h.top) return h;
3939
}
4040
}
4141

42-
let currentApiPrefix
43-
let parentMenuSelector
44-
let lastApiPrefix
42+
let currentApiPrefix;
43+
let parentMenuSelector;
44+
let lastApiPrefix;
4545

4646
if (document.readyState !== 'loading') {
47-
const languageElement = document.getElementById('languageData')
48-
const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : []
47+
const languageElement = document.getElementById('languageData');
48+
const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : [];
4949

50-
const langDisplay = document.getElementById('current-lang')
50+
const langDisplay = document.getElementById('current-lang');
5151

5252
if (langDisplay) {
53-
const currentLanguage = window.location.pathname.split('/')[1]
54-
const matchedLang = languagesData.find(lang => lang.code === currentLanguage)
55-
langDisplay.textContent = matchedLang ? matchedLang.name : 'English'
53+
const currentLanguage = window.location.pathname.split('/')[1];
54+
const matchedLang = languagesData.find(lang => lang.code === currentLanguage);
55+
langDisplay.textContent = matchedLang ? matchedLang.name : 'English';
5656
}
5757
}
5858

5959
$(document).scroll(function () {
60-
const h = closest()
61-
if (!h) return
60+
const h = closest();
61+
if (!h) return;
6262

63-
currentApiPrefix = h.id.split('.')[0]
64-
parentMenuSelector = '#' + currentApiPrefix + '-menu'
63+
currentApiPrefix = h.id.split('.')[0];
64+
parentMenuSelector = '#' + currentApiPrefix + '-menu';
6565

66-
$(parentMenuSelector).addClass('active')
66+
$(parentMenuSelector).addClass('active');
6767

6868
if (lastApiPrefix && (lastApiPrefix !== currentApiPrefix)) {
69-
$('#' + lastApiPrefix + '-menu').removeClass('active')
69+
$('#' + lastApiPrefix + '-menu').removeClass('active');
7070
}
7171

72-
$('#menu li a').removeClass('active')
72+
$('#menu li a').removeClass('active');
7373

74-
const a = $('a[href="#' + h.id + '"]')
75-
a.addClass('active')
74+
const a = $('a[href="#' + h.id + '"]');
75+
a.addClass('active');
7676

77-
lastApiPrefix = currentApiPrefix.split('.')[0]
78-
})
77+
lastApiPrefix = currentApiPrefix.split('.')[0];
78+
});
7979

8080
// i18n notice
8181
if (readCookie('i18nClose')) {
82-
$('#i18n-notice-box').hide()
83-
$('#i18n-notice-box').addClass('hidden')
82+
$('#i18n-notice-box').hide();
83+
$('#i18n-notice-box').addClass('hidden');
8484
} else {
8585
$('#close-i18n-notice-box').on('click', function () {
86-
$('#i18n-notice-box').hide()
87-
$('#i18n-notice-box').addClass('hidden')
88-
createCookie('i18nClose', 1)
89-
})
86+
$('#i18n-notice-box').hide();
87+
$('#i18n-notice-box').addClass('hidden');
88+
createCookie('i18nClose', 1);
89+
});
9090
}
91-
})
91+
});
9292

9393
function createCookie (name, value, days) {
94-
let expires
94+
let expires;
9595

9696
if (days) {
97-
const date = new Date()
98-
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
99-
expires = '; expires=' + date.toGMTString()
97+
const date = new Date();
98+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
99+
expires = '; expires=' + date.toGMTString();
100100
} else {
101-
expires = ''
101+
expires = '';
102102
}
103-
document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + expires + '; path=/'
103+
document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + expires + '; path=/';
104104
}
105105

106106
function readCookie (name) {
107-
const nameEQ = encodeURIComponent(name) + '='
108-
const ca = document.cookie.split(';')
107+
const nameEQ = encodeURIComponent(name) + '=';
108+
const ca = document.cookie.split(';');
109109
for (let i = 0; i < ca.length; i++) {
110-
let c = ca[i]
111-
while (c.charAt(0) === ' ') c = c.substring(1, c.length)
112-
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length))
110+
let c = ca[i];
111+
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
112+
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
113113
}
114-
return null
114+
return null;
115115
}

js/copycode.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
const codeBlocks = document.querySelectorAll('pre:has(code)')
1+
const codeBlocks = document.querySelectorAll('pre:has(code)');
22

33
codeBlocks.forEach((block) => {
44
// Only add button if browser supports Clipboard API
5-
if (!navigator.clipboard) return
5+
if (!navigator.clipboard) return;
66

7-
const button = createCopyButton()
8-
block.appendChild(button)
9-
block.setAttribute('tabindex', 0) // Add keyboard a11y for <pre></pre>
7+
const button = createCopyButton();
8+
block.appendChild(button);
9+
block.setAttribute('tabindex', 0); // Add keyboard a11y for <pre></pre>
1010

1111
button.addEventListener('click', async () => {
12-
await copyCode(block, button)
13-
})
14-
})
12+
await copyCode(block, button);
13+
});
14+
});
1515

1616
function createCopyButton () {
17-
const button = document.createElement('button')
17+
const button = document.createElement('button');
1818
setButtonAttributes(button, {
1919
type: 'button', // button doesn't act as a submit button
2020
title: 'copy code',
2121
'aria-label': 'click to copy code'
22-
})
23-
return button
22+
});
23+
return button;
2424
}
2525

2626
function setButtonAttributes (button, attributes) {
2727
for (const [key, value] of Object.entries(attributes)) {
28-
button.setAttribute(key, value)
28+
button.setAttribute(key, value);
2929
}
3030
}
3131

3232
async function copyCode (block, button) {
33-
const code = block.querySelector('code')
34-
let text = code.innerText
33+
const code = block.querySelector('code');
34+
let text = code.innerText;
3535
// remove "$" and space if exists at the beginning of the code
36-
text = text.replace(/^\$\s?/, '')
36+
text = text.replace(/^\$\s?/, '');
3737

3838
try {
39-
await navigator.clipboard.writeText(text)
40-
updateButtonState(button, 'copied', 'code is copied!')
39+
await navigator.clipboard.writeText(text);
40+
updateButtonState(button, 'copied', 'code is copied!');
4141
} catch {
42-
updateButtonState(button, 'failed', 'failed!')
42+
updateButtonState(button, 'failed', 'failed!');
4343
}
4444
}
4545

4646
function updateButtonState (button, statusClass, ariaLabel) {
47-
button.setAttribute('aria-live', 'polite')
48-
button.setAttribute('aria-label', ariaLabel)
49-
button.classList.add(statusClass)
47+
button.setAttribute('aria-live', 'polite');
48+
button.setAttribute('aria-label', ariaLabel);
49+
button.classList.add(statusClass);
5050

5151
// Clear any existing timer
52-
if (button.dataset.timerId) clearTimeout(Number(button.dataset.timerId))
52+
if (button.dataset.timerId) clearTimeout(Number(button.dataset.timerId));
5353
const timer = setTimeout(() => {
54-
button.classList.remove(statusClass)
55-
button.setAttribute('aria-label', 'click to copy code')
56-
}, 1000)
54+
button.classList.remove(statusClass);
55+
button.setAttribute('aria-label', 'click to copy code');
56+
}, 1000);
5757

58-
button.dataset.timerId = timer
58+
button.dataset.timerId = timer;
5959
}

0 commit comments

Comments
 (0)