diff --git a/.eslintrc.json b/.eslintrc.json index 9ed7dba4..efa7ef14 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,11 +4,14 @@ "es2021": true, "jquery": true }, - "extends": ["standard"], + "extends": [ + "standard", + "prettier" + ], "parserOptions": { "ecmaVersion": 12 }, "rules": { - "no-var": 0 + "no-var": "off" } } diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ab6ec0bd..e8c6dc49 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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' diff --git a/.prettierrc.yaml b/.prettierrc.yaml index 6a1d121c..33f7c6d9 100644 --- a/.prettierrc.yaml +++ b/.prettierrc.yaml @@ -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 @@ -10,3 +15,6 @@ overrides: - files: '*.css' options: singleQuote: false +- files: '*.js' + options: + singleQuote: true diff --git a/assets/static/js/custom_scripts.js b/assets/static/js/custom_scripts.js index b8b144e1..d651d79c 100644 --- a/assets/static/js/custom_scripts.js +++ b/assets/static/js/custom_scripts.js @@ -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 */ @@ -73,6 +76,6 @@ var downloadButton = document.getElementById('download-button-button') if (downloadButton) { setupDownloadButton(downloadButton) - }; + } }) -}()) +})()