Skip to content

Commit

Permalink
Add Pretter formatter JS with loosened config matching current
Browse files Browse the repository at this point in the history
  • Loading branch information
CAM-Gerlach committed Oct 27, 2023
1 parent a67d6bb commit d80d78d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
"es2021": true,
"jquery": true
},
"extends": ["standard"],
"extends": [
"standard",
"prettier"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"no-var": 0
"no-var": "off"
}
}
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ repos:
exclude: 'configs/disqus-comments\.ini'
args: [--autofix]

# Format JavaScript with Prettier
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
- id: prettier
name: Format JavaScript (Prettier)
types: [javascript]

# Lint and fix JavaScript
- repo: https://github.com/eslint/eslint
rev: v8.52.0
Expand All @@ -98,6 +106,7 @@ repos:
args: [--fix, --max-warnings, '0', --color --report-unused-disable-directives]
additional_dependencies:
- 'eslint-config-standard@17.1.0'
- 'eslint-config-prettier@v9.0.0'
- 'eslint-plugin-import@2.29.0'
- 'eslint-plugin-n@16.2.0'
- 'eslint-plugin-promise@6.1.1'
Expand Down
8 changes: 8 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Configuration file for Prettier

printWidth: 120
tabWidth: 2
useTabs: false
semi: false
trailingComma: 'none'
bracketSpacing: false
arrowParens: 'always'
proseWrap: 'preserve'
endOfLine: 'lf'
singleAttributePerLine: false
Expand All @@ -10,3 +15,6 @@ overrides:
- files: '*.css'
options:
singleQuote: false
- files: '*.js'
options:
singleQuote: true
33 changes: 18 additions & 15 deletions assets/static/js/custom_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,44 @@
/* Helper functions */

// Get the key corresponding to the current desktop operating system
function getOSName () {
function getOSName() {
var platform = navigator.platform
if (!platform) {
return 'other'
};
}
if (platform.indexOf('Win') === 0) {
return 'win'
};
}
if (platform.indexOf('Mac') === 0) {
return 'mac'
};
if ((platform.indexOf('Linux') === 0 || platform.indexOf('X11') === 0) &&
!platform.match(/android/i) && !navigator.userAgent.match(/android/i)) {
}
if (
(platform.indexOf('Linux') === 0 || platform.indexOf('X11') === 0) &&
!platform.match(/android/i) &&
!navigator.userAgent.match(/android/i)
) {
return 'linux'
};
}
return 'other'
};
}

// Get the button data corresponding to the current OS
function getButtonData () {
function getButtonData() {
var osName = getOSName()
return buttonData[osName]
};
}

/* Main functions */

// Setup download button based on current OS
function setupDownloadButton (downloadButton) {
function setupDownloadButton(downloadButton) {
var buttonData = getButtonData()
downloadButton.href = buttonData.url
downloadButton.getElementsByClassName('download-text')[0].textContent = buttonData.text
for (var i = 0; i < buttonData.icon.length; i++) {
downloadButton.getElementsByClassName('download-os-icon')[0].classList.add(buttonData.icon[i])
};
};
}
}

/* Fire events */

Expand All @@ -73,6 +76,6 @@
var downloadButton = document.getElementById('download-button-button')
if (downloadButton) {
setupDownloadButton(downloadButton)
};
}
})
}())
})()

0 comments on commit d80d78d

Please sign in to comment.