Added eslint. To lint, npm run lint.

Linted the entire project. Using different rules for the script files
as there are a lot of undefined variables just because of the way the
DOM's global scope works.

Mostly just code cleanup, however the linter did catch a minor bug with
a settings regex. That has been corrected.
This commit is contained in:
Daniel Scalzi
2018-07-22 13:31:15 -04:00
parent ededf85892
commit 810e81521c
18 changed files with 1205 additions and 261 deletions

View File

@@ -152,8 +152,8 @@ const refreshMojangStatuses = async function(){
console.log('Refreshing Mojang Statuses..')
let status = 'grey'
let tooltipEssentialHTML = ``
let tooltipNonEssentialHTML = ``
let tooltipEssentialHTML = ''
let tooltipNonEssentialHTML = ''
try {
const statuses = await Mojang.status()
@@ -358,7 +358,7 @@ function asyncSystemScan(launchAfter = true){
switch(m.data){
case 'download':
// Downloading..
// Downloading..
setDownloadPercentage(m.value, m.total, m.percent)
break
}
@@ -366,7 +366,7 @@ function asyncSystemScan(launchAfter = true){
} else if(m.context === 'complete'){
switch(m.data){
case 'download':
case 'download': {
// Show installing progress bar.
remote.getCurrentWindow().setProgressBar(2)
@@ -383,8 +383,9 @@ function asyncSystemScan(launchAfter = true){
setLaunchDetails(eLStr + dotStr)
}, 750)
break
}
case 'java':
// Download & extraction complete, remove the loading from the OS progress bar.
// Download & extraction complete, remove the loading from the OS progress bar.
remote.getCurrentWindow().setProgressBar(-1)
// Extraction completed successfully.
@@ -497,14 +498,15 @@ function dlAsync(login = true){
}
} else if(m.context === 'progress'){
switch(m.data){
case 'assets':
case 'assets': {
const perc = (m.value/m.total)*20
setLaunchPercentage(40+perc, 100, parseInt(40+perc))
break
}
case 'download':
setDownloadPercentage(m.value, m.total, m.percent)
break
case 'extract':
case 'extract': {
// Show installing progress bar.
remote.getCurrentWindow().setProgressBar(2)
@@ -521,6 +523,7 @@ function dlAsync(login = true){
setLaunchDetails(eLStr + dotStr)
}, 750)
break
}
}
} else if(m.context === 'complete'){
switch(m.data){
@@ -1001,54 +1004,54 @@ function loadNews(){
const newsFeed = distroData.getRSS()
const newsHost = new URL(newsFeed).origin + '/'
$.ajax(
{
url: newsFeed,
success: (data) => {
const items = $(data).find('item')
const articles = []
{
url: newsFeed,
success: (data) => {
const items = $(data).find('item')
const articles = []
for(let i=0; i<items.length; i++){
for(let i=0; i<items.length; i++){
// JQuery Element
const el = $(items[i])
const el = $(items[i])
// Resolve date.
const date = new Date(el.find('pubDate').text()).toLocaleDateString('en-US', {month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric'})
// Resolve date.
const date = new Date(el.find('pubDate').text()).toLocaleDateString('en-US', {month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric'})
// Resolve comments.
let comments = el.find('slash\\:comments').text() || '0'
comments = comments + ' Comment' + (comments === '1' ? '' : 's')
// Resolve comments.
let comments = el.find('slash\\:comments').text() || '0'
comments = comments + ' Comment' + (comments === '1' ? '' : 's')
// Fix relative links in content.
let content = el.find('content\\:encoded').text()
let regex = /src="(?!http:\/\/|https:\/\/)(.+)"/g
let matches
while(matches = regex.exec(content)){
content = content.replace(matches[1], newsHost + matches[1])
}
let link = el.find('link').text()
let title = el.find('title').text()
let author = el.find('dc\\:creator').text()
// Generate article.
articles.push(
{
link,
title,
date,
author,
content,
comments,
commentsLink: link + '#comments'
// Fix relative links in content.
let content = el.find('content\\:encoded').text()
let regex = /src="(?!http:\/\/|https:\/\/)(.+)"/g
let matches
while((matches = regex.exec(content))){
content = content.replace(matches[1], newsHost + matches[1])
}
)
}
resolve({
articles
})
},
timeout: 2500
}).catch(err => {
let link = el.find('link').text()
let title = el.find('title').text()
let author = el.find('dc\\:creator').text()
// Generate article.
articles.push(
{
link,
title,
date,
author,
content,
comments,
commentsLink: link + '#comments'
}
)
}
resolve({
articles
})
},
timeout: 2500
}).catch(err => {
resolve({
articles: null
})

View File

@@ -22,7 +22,7 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
if(toggleState){
document.getElementById('main').setAttribute('overlay', true)
// Make things untabbable.
$("#main *").attr('tabindex', '-1')
$('#main *').attr('tabindex', '-1')
$('#' + content).parent().children().hide()
$('#' + content).show()
if(dismissable){
@@ -41,7 +41,7 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
} else {
document.getElementById('main').removeAttribute('overlay')
// Make things tabbable.
$("#main *").removeAttr('tabindex')
$('#main *').removeAttr('tabindex')
$('#overlayContainer').fadeOut({
duration: 250,
start: () => {
@@ -232,9 +232,9 @@ function populateServerListings(){
const distro = DistroManager.getDistribution()
const giaSel = ConfigManager.getSelectedServer()
const servers = distro.getServers()
let htmlString = ``
let htmlString = ''
for(const serv of servers){
htmlString += `<button class="serverListing" servid="${serv.getID()}" ${serv.getID() === giaSel ? `selected` : ``}>
htmlString += `<button class="serverListing" servid="${serv.getID()}" ${serv.getID() === giaSel ? 'selected' : ''}>
<img class="serverListingImg" src="${serv.getIcon()}"/>
<div class="serverListingDetails">
<span class="serverListingName">${serv.getName()}</span>
@@ -251,7 +251,7 @@ function populateServerListings(){
<circle class="cls-2" cx="53.73" cy="53.9" r="38"/>
</svg>
<span class="serverListingStarTooltip">Main Server</span>
</div>` : ``}
</div>` : ''}
</div>
</div>
</button>`
@@ -262,8 +262,8 @@ function populateServerListings(){
function populateAccountListings(){
const accountsObj = ConfigManager.getAuthAccounts()
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v]);
let htmlString = ``
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v])
let htmlString = ''
for(let i=0; i<accounts.length; i++){
htmlString += `<button class="accountListing" uuid="${accounts[i].uuid}" ${i===0 ? 'selected' : ''}>
<img src="https://crafatar.com/renders/head/${accounts[i].uuid}?scale=2&default=MHF_Steve&overlay">

View File

@@ -12,7 +12,7 @@ const settingsState = {
* General Settings Functions
*/
/**
/**
* Bind value validators to the settings UI elements. These will
* validate against the criteria defined in the ConfigManager (if
* and). If the value is invalid, the UI will reflect this and saving
@@ -59,8 +59,8 @@ function initSettingsValues(){
if(typeof gFn === 'function'){
if(v.tagName === 'INPUT'){
if(v.type === 'number' || v.type === 'text'){
// Special Conditions
const cVal = v.getAttribute('cValue')
// Special Conditions
const cVal = v.getAttribute('cValue')
if(cVal === 'JavaExecutable'){
populateJavaExecDetails(v.value)
v.value = gFn()
@@ -363,7 +363,7 @@ function populateAuthAccounts(){
const authKeys = Object.keys(authAccounts)
const selectedUUID = ConfigManager.getSelectedAccount().uuid
let authAccountStr = ``
let authAccountStr = ''
authKeys.map((val) => {
const acc = authAccounts[val]
@@ -408,16 +408,16 @@ function prepareAccountsTab() {
* Minecraft Tab
*/
/**
/**
* Disable decimals, negative signs, and scientific notation.
*/
document.getElementById('settingsGameWidth').addEventListener('keydown', (e) => {
if(/[-\.eE]/.test(e.key)){
document.getElementById('settingsGameWidth').addEventListener('keydown', (e) => {
if(/^[-.eE]$/.test(e.key)){
e.preventDefault()
}
})
document.getElementById('settingsGameHeight').addEventListener('keydown', (e) => {
if(/[-\.eE]/.test(e.key)){
if(/^[-.eE]$/.test(e.key)){
e.preventDefault()
}
})
@@ -472,7 +472,7 @@ settingsMinRAMRange.onchange = (e) => {
if(sMaxV < sMinV){
const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
updateRangedSlider(settingsMaxRAMRange, sMinV,
((sMinV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
((sMinV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
settingsMaxRAMLabel.innerHTML = sMinV.toFixed(1) + 'G'
}
@@ -504,7 +504,7 @@ settingsMaxRAMRange.onchange = (e) => {
if(sMaxV < sMinV){
const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
updateRangedSlider(settingsMinRAMRange, sMaxV,
((sMaxV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
((sMaxV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
settingsMinRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G'
}
settingsMaxRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G'
@@ -730,7 +730,7 @@ function prepareAboutTab(){
* Settings preparation functions.
*/
/**
/**
* Prepare the entire settings UI.
*
* @param {boolean} first Whether or not it is the first load.

View File

@@ -104,7 +104,7 @@ function showMainUI(data){
}, 750)
// Disable tabbing to the news container.
initNews().then(() => {
$("#newsContainer *").attr('tabindex', '-1')
$('#newsContainer *').attr('tabindex', '-1')
})
}
@@ -275,12 +275,12 @@ function mergeModConfiguration(o, n){
function refreshDistributionIndex(remote, onSuccess, onError){
if(remote){
DistroManager.pullRemote()
.then(onSuccess)
.catch(onError)
.then(onSuccess)
.catch(onError)
} else {
DistroManager.pullLocal()
.then(onSuccess)
.catch(onError)
.then(onSuccess)
.catch(onError)
}
}
@@ -313,7 +313,7 @@ async function validateSelectedAccount(){
})
} else {
const accountsObj = ConfigManager.getAuthAccounts()
const accounts = Array.from(Object.keys(accountsObj), v => accountsObj[v]);
const accounts = Array.from(Object.keys(accountsObj), v => accountsObj[v])
// This function validates the account switch.
setSelectedAccount(accounts[0].uuid)
toggleOverlay(false)
@@ -375,7 +375,7 @@ ipcRenderer.on('distributionIndexDone', (event, res) => {
} else {
fatalStartupError = true
if(document.readyState === 'complete'){
showFatalStartupError()
showFatalStartupError()
} else {
rscShouldLoad = true
}

View File

@@ -5,7 +5,7 @@
* modules, excluding dependencies.
*/
// Requirements
const $ = require('jquery');
const $ = require('jquery')
const {ipcRenderer, remote, shell, webFrame} = require('electron')
const isDev = require('electron-is-dev')
@@ -50,6 +50,7 @@ if(!isDev){
ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
}, 1800000)
ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
break
case 'realerror':
if(info != null && info.code != null){
if(info.code === 'ERR_UPDATER_INVALID_RELEASE_FEED'){
@@ -108,7 +109,7 @@ $(function(){
document.addEventListener('readystatechange', function () {
if (document.readyState === 'interactive'){
console.log('UICore Initializing..');
console.log('UICore Initializing..')
// Bind close button.
Array.from(document.getElementsByClassName('fCb')).map((val) => {
@@ -157,10 +158,10 @@ document.addEventListener('readystatechange', function () {
//const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width
//const targetWidth3 = document.getElementById("launch_button").getBoundingClientRect().width
document.getElementById("launch_details").style.maxWidth = 266.01
document.getElementById("launch_progress").style.width = 170.8
document.getElementById("launch_details_right").style.maxWidth = 170.8
document.getElementById("launch_progress_label").style.width = 53.21
document.getElementById('launch_details').style.maxWidth = 266.01
document.getElementById('launch_progress').style.width = 170.8
document.getElementById('launch_details_right').style.maxWidth = 170.8
document.getElementById('launch_progress_label').style.width = 53.21
}
@@ -170,7 +171,7 @@ document.addEventListener('readystatechange', function () {
* Open web links in the user's default browser.
*/
$(document).on('click', 'a[href^="http"]', function(event) {
event.preventDefault();
event.preventDefault()
//console.log(os.homedir())
shell.openExternal(this.href)
})