From dbb3d68d8de934e39b06bc8c53dae7c3868c2706 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 31 Jul 2021 23:06:59 -0700 Subject: [PATCH 01/11] Use formatting task to check docs and config formatting in CI The `config:check-formatting` and `docs:check-formatting` tasks have no value to the developer, since they will be better off to just run the formatting task. This means that the only use for this task is the CI. I think this can be better achieved by configuring the CI to format the code and then check for a diff. This ensures that there is no possibility for a mismatch between the formatting check and the formatting task. --- .github/workflows/check-formatting.yml | 10 ++++++++-- Taskfile.yml | 15 --------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 05008504..1a7c97b1 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -34,8 +34,14 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} version: 3.x + - name: Format documentation + run: task docs:format + - name: Check documentation formatting - run: task docs:check-formatting + run: git diff --color --exit-code + + - name: Format configuration files + run: task config:format - name: Check configuration file formatting - run: task config:check-formatting + run: git diff --color --exit-code diff --git a/Taskfile.yml b/Taskfile.yml index 61abb84a..5dd42dff 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -60,8 +60,6 @@ tasks: check-formatting: desc: Check formatting of all files cmds: - - task: docs:check-formatting - - task: config:check-formatting - task: general:check-formatting format: @@ -223,7 +221,6 @@ tasks: docs:check: desc: Lint and check formatting of documentation files cmds: - - task: docs:check-formatting - task: markdown:lint - task: markdown:fix - task: markdown:check-links @@ -257,11 +254,6 @@ tasks: exit 1 fi - docs:check-formatting: - desc: Check formatting of documentation files - cmds: - - npx {{ .PRETTIER }} --check "**/*.md" - docs:format: desc: Format documentation files cmds: @@ -338,7 +330,6 @@ tasks: config:check: desc: Lint and check formatting of configuration files cmds: - - task: config:check-formatting - task: config:lint config:lint: @@ -352,12 +343,6 @@ tasks: - wget --output-document={{ .WORKFLOW_SCHEMA_PATH }} https://json.schemastore.org/github-workflow - npx ajv-cli validate --strict=false -s {{ .WORKFLOW_SCHEMA_PATH }} -d "./.github/workflows/*.{yml,yaml}" - config:check-formatting: - desc: Check formatting of configuration files - cmds: - - npx {{ .PRETTIER }} --check "**/*.{yml,yaml}" - - npx {{ .PRETTIER }} --check "**/*.json" - config:format: desc: Format configuration files cmds: From e13a5587e7f1d369112e59831b70c2ca5a16b301 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 31 Jul 2021 23:14:09 -0700 Subject: [PATCH 02/11] Use Prettier to format all supported files The Prettier formatting tool supports a long list of languages. Previously, it was being arbitrarily limited to JSON, YAML, and Markdown files. It will be more useful to allow it to format files of any language it supports. --- .github/workflows/check-formatting.yml | 198 +++++++++++++++++++++++-- Taskfile.yml | 22 +-- 2 files changed, 190 insertions(+), 30 deletions(-) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 1a7c97b1..02b5f31d 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -1,4 +1,4 @@ -name: Check formatting +name: Check Prettier Formatting on: push: @@ -6,19 +6,191 @@ on: - ".github/workflows/check-formatting.yml" - "Taskfile.yml" - ".prettierrc" + # CSS + - "**.css" + - "**.wxss" + # PostCSS + - "**.pcss" + - "**.postcss" + # Less + - "**.less" + # SCSS + - "**.scss" + # GraphQL + - "**.graphqls?" + - "**.gql" + # handlebars + - "**.handlebars" + - "**.hbs" + # HTML + - "**.mjml" + - "**.html?" + - "**.html.hl" + - "**.st" + - "**.xht" + - "**.xhtml" + # Vue + - "**.vue" + # JavaScript + - "**.flow" + - "**._?jsb?" + - "**.bones" + - "**.cjs" + - "**.es6?" + - "**.frag" + - "**.gs" + - "**.jake" + - "**.jscad" + - "**.jsfl" + - "**.js[ms]" + - "**.[mn]js" + - "**.pac" + - "**.wxs" + - "**.[xs]s?js" + - "**.xsjslib" + # JSX + - "**.jsx" + # TypeScript + - "**.ts" + # TSX + - "**.tsx" + # JSON + - "**/.eslintrc" - "**.json" - - "**.md" - - "**.yaml" - - "**.yml" + - "**.avsc" + - "**.geojson" + - "**.gltf" + - "**.har" + - "**.ice" + - "**.JSON-tmLanguage" + - "**.mcmeta" + - "**.tfstate" + - "**.topojson" + - "**.webapp" + - "**.webmanifest" + - "**.yyp?" + # JSONC + - "**/.babelrc" + - "**/.jscsrc" + - "**/.js[hl]intrc" + - "**.jsonc" + - "**.sublime-*" + # JSON5 + - "**.json5" + # Markdown + - "**.mdx?" + - "**.markdown" + - "**.mk?down" + - "**.mdwn" + - "**.mkdn?" + - "**.ronn" + - "**.workbook" + # YAML + - "**/.clang-format" + - "**/.clang-tidy" + - "**/.gemrc" + - "**/glide.lock" + - "**.ya?ml*" + - "**.mir" + - "**.reek" + - "**.rviz" + - "**.sublime-syntax" + - "**.syntax" pull_request: paths: - ".github/workflows/check-formatting.yml" - "Taskfile.yml" - ".prettierrc" + # CSS + - "**.css" + - "**.wxss" + # PostCSS + - "**.pcss" + - "**.postcss" + # Less + - "**.less" + # SCSS + - "**.scss" + # GraphQL + - "**.graphqls?" + - "**.gql" + # handlebars + - "**.handlebars" + - "**.hbs" + # HTML + - "**.mjml" + - "**.html?" + - "**.html.hl" + - "**.st" + - "**.xht" + - "**.xhtml" + # Vue + - "**.vue" + # JavaScript + - "**.flow" + - "**._?jsb?" + - "**.bones" + - "**.cjs" + - "**.es6?" + - "**.frag" + - "**.gs" + - "**.jake" + - "**.jscad" + - "**.jsfl" + - "**.js[ms]" + - "**.[mn]js" + - "**.pac" + - "**.wxs" + - "**.[xs]s?js" + - "**.xsjslib" + # JSX + - "**.jsx" + # TypeScript + - "**.ts" + # TSX + - "**.tsx" + # JSON + - "**/.eslintrc" - "**.json" - - "**.md" - - "**.yaml" - - "**.yml" + - "**.avsc" + - "**.geojson" + - "**.gltf" + - "**.har" + - "**.ice" + - "**.JSON-tmLanguage" + - "**.mcmeta" + - "**.tfstate" + - "**.topojson" + - "**.webapp" + - "**.webmanifest" + - "**.yyp?" + # JSONC + - "**/.babelrc" + - "**/.jscsrc" + - "**/.js[hl]intrc" + - "**.jsonc" + - "**.sublime-*" + # JSON5 + - "**.json5" + # Markdown + - "**.mdx?" + - "**.markdown" + - "**.mk?down" + - "**.mdwn" + - "**.mkdn?" + - "**.ronn" + - "**.workbook" + # YAML + - "**/.clang-format" + - "**/.clang-tidy" + - "**/.gemrc" + - "**/glide.lock" + - "**.ya?ml*" + - "**.mir" + - "**.reek" + - "**.rviz" + - "**.sublime-syntax" + - "**.syntax" jobs: check-formatting: @@ -34,14 +206,8 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} version: 3.x - - name: Format documentation - run: task docs:format + - name: Format with Prettier + run: task general:format-prettier - - name: Check documentation formatting - run: git diff --color --exit-code - - - name: Format configuration files - run: task config:format - - - name: Check configuration file formatting + - name: Check formatting run: git diff --color --exit-code diff --git a/Taskfile.yml b/Taskfile.yml index 5dd42dff..0efdcbe2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -67,8 +67,7 @@ tasks: cmds: - task: go:format - task: python:format - - task: docs:format - - task: config:format + - task: general:format-prettier # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:check: @@ -197,7 +196,7 @@ tasks: # we invoke `arduino-lint` like this instead of `./arduino-lint` to remove # the `./` chars from the examples - PATH=. arduino-lint ../docs/commands - - task: docs:format + - task: general:format-prettier docs:build: desc: Build documentation website contents @@ -254,11 +253,6 @@ tasks: exit 1 fi - docs:format: - desc: Format documentation files - cmds: - - npx {{ .PRETTIER }} --write "**/*.md" - # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-shell-task/Taskfile.yml shell:check: desc: Check for problems with shell scripts @@ -343,12 +337,6 @@ tasks: - wget --output-document={{ .WORKFLOW_SCHEMA_PATH }} https://json.schemastore.org/github-workflow - npx ajv-cli validate --strict=false -s {{ .WORKFLOW_SCHEMA_PATH }} -d "./.github/workflows/*.{yml,yaml}" - config:format: - desc: Format configuration files - cmds: - - npx {{ .PRETTIER }} --write "**/*.{yml,yaml}" - - npx {{ .PRETTIER }} --write "**/*.json" - # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml general:check-formatting: desc: Check basic formatting style of all files @@ -360,6 +348,12 @@ tasks: fi - ec + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml + general:format-prettier: + desc: Format all supported files with Prettier + cmds: + - npx prettier --write . + check-spelling: desc: Check for commonly misspelled words cmds: From ee499113e3cc7891e70f1a319850927cdc5b0265 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:10:43 -0700 Subject: [PATCH 03/11] Add `.prettierignore` to "Check Prettier Formatting" workflow's path filter The workflow should run whenever this file is modified. --- .github/workflows/check-formatting.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 02b5f31d..2cbe7a0a 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -6,6 +6,7 @@ on: - ".github/workflows/check-formatting.yml" - "Taskfile.yml" - ".prettierrc" + - "**/.prettierignore" # CSS - "**.css" - "**.wxss" @@ -101,6 +102,7 @@ on: - ".github/workflows/check-formatting.yml" - "Taskfile.yml" - ".prettierrc" + - "**/.prettierignore" # CSS - "**.css" - "**.wxss" From 83315add394bb150c1603f276c91307d78f64bd3 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:11:48 -0700 Subject: [PATCH 04/11] Make `.prettierrc` path filter of "Check Prettier Formatting" workflow recursive `.prettierrc` is the Prettier formatting tool's configuration file. Prettier uses the configuration file closes to the file being formatted, meaning a project can have multiple configuration files. The workflow should run whenever any configuration file is edited. --- .github/workflows/check-formatting.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 2cbe7a0a..374265b5 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -5,8 +5,8 @@ on: paths: - ".github/workflows/check-formatting.yml" - "Taskfile.yml" - - ".prettierrc" - "**/.prettierignore" + - "**/.prettierrc*" # CSS - "**.css" - "**.wxss" @@ -101,8 +101,8 @@ on: paths: - ".github/workflows/check-formatting.yml" - "Taskfile.yml" - - ".prettierrc" - "**/.prettierignore" + - "**/.prettierrc*" # CSS - "**.css" - "**.wxss" From 4a9c2349ed3c5f9e536d309e22f66ce16de6367c Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:14:27 -0700 Subject: [PATCH 05/11] Add manual events as "Check Prettier Formatting" workflow triggers The `workflow_dispatch` event allows triggering the workflow via the GitHub web interface. This makes it easy to trigger an immediate workflow run after some relevant external change. The `repository_dispatch` event allows triggering workflows via the GitHub API. This might be useful for triggering an immediate check in multiple relevant repositories after an external change, or some automated process. Although we don't have any specific need for this event at the moment, the event has no impact on the workflow, so there is no reason against having it. It is the sort of thing that can end up being useful if it is already in consistently in place, but not worth setting up on demand, since the effort to set it up is greater than the effort to trigger all the workflows manually. --- .github/workflows/check-formatting.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 374265b5..82a3c019 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -193,6 +193,8 @@ on: - "**.rviz" - "**.sublime-syntax" - "**.syntax" + workflow_dispatch: + repository_dispatch: jobs: check-formatting: From 00653db8d305853002e6b7a9bf82cebfe67592fa Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:20:24 -0700 Subject: [PATCH 06/11] Use standardized job/step names in "Check Prettier Formatting" workflow These are the naming conventions established in the standardized template workflow. --- .github/workflows/check-formatting.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 82a3c019..5f35788f 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -197,14 +197,14 @@ on: repository_dispatch: jobs: - check-formatting: + check: runs-on: ubuntu-latest steps: - - name: Checkout local repository + - name: Checkout repository uses: actions/checkout@v2 - - name: Install Taskfile + - name: Install Task uses: arduino/setup-task@v1 with: repo-token: ${{ secrets.GITHUB_TOKEN }} From 9fdd765c7aaab95351fcb2fbdd59baf4c08f79b8 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:22:26 -0700 Subject: [PATCH 07/11] Add general comment to "Check Prettier Formatting" workflow providing trigger event reference The workings of the `workflow_dispatch` and `repository_dispatch` events is not obvious from the name. For this reason, a comment was added to explain their working. But this information is explained well enough in GitHub's documentation, so the workflow will be less cluttered by simply providing a reference link interested parties can easily follow to get all the information on the events used by the workflow. --- .github/workflows/check-formatting.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 5f35788f..ebf76508 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -1,5 +1,6 @@ name: Check Prettier Formatting +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows on: push: paths: From f16537e533d233f5560e374880daef84488ded95 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:23:17 -0700 Subject: [PATCH 08/11] Make "Check Prettier Formatting" workflow support taskfiles using either YAML file extension There are two file extensions in common use for YAML files: `.yaml` and `.yml`. Although this project uses `.yml` exclusively for YAML files, this is a standardized workflow which might be applied to projects that have established the use of the other extension. It will be most flexible if it supports both. --- .github/workflows/check-formatting.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index ebf76508..0420fadf 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -5,7 +5,7 @@ on: push: paths: - ".github/workflows/check-formatting.yml" - - "Taskfile.yml" + - "Taskfile.ya?ml" - "**/.prettierignore" - "**/.prettierrc*" # CSS @@ -101,7 +101,7 @@ on: pull_request: paths: - ".github/workflows/check-formatting.yml" - - "Taskfile.yml" + - "Taskfile.ya?ml" - "**/.prettierignore" - "**/.prettierrc*" # CSS From b93dd744e997810626a4c9ade900d6a91575684c Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:26:09 -0700 Subject: [PATCH 09/11] Use standardized filename for "Check Prettier Formatting" workflow This is the template workflow filename, which is intended to serve as a unique identifier, and thus must be a bit more verbose. --- ...eck-formatting.yml => check-prettier-formatting-task.yml} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename .github/workflows/{check-formatting.yml => check-prettier-formatting-task.yml} (94%) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-prettier-formatting-task.yml similarity index 94% rename from .github/workflows/check-formatting.yml rename to .github/workflows/check-prettier-formatting-task.yml index 0420fadf..caccbcf9 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-prettier-formatting-task.yml @@ -1,10 +1,11 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md name: Check Prettier Formatting # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows on: push: paths: - - ".github/workflows/check-formatting.yml" + - ".github/workflows/check-prettier-formatting-task.ya?ml" - "Taskfile.ya?ml" - "**/.prettierignore" - "**/.prettierrc*" @@ -100,7 +101,7 @@ on: - "**.syntax" pull_request: paths: - - ".github/workflows/check-formatting.yml" + - ".github/workflows/check-prettier-formatting-task.ya?ml" - "Taskfile.ya?ml" - "**/.prettierignore" - "**/.prettierrc*" From 49cbbd5760074b2902f190f8d333b0d14ce6ae43 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:28:15 -0700 Subject: [PATCH 10/11] Add badge for "Check Prettier Formatting" workflow to readme The badges provide a prominent indication of the repository's CI status at a glance. This may help to bring potential issues to the attention of the maintainers. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b2767463..7e8f6e46 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![Check Markdown status](https://github.com/arduino/arduino-lint/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-markdown-task.yml) [![Docs Status](https://github.com/arduino/arduino-lint/workflows/Publish%20documentation/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Publish+documentation) [![Codecov](https://codecov.io/gh/arduino/arduino-lint/branch/main/graph/badge.svg?token=nprqPQMbdh)](https://codecov.io/gh/arduino/arduino-lint) +[![Check Prettier Formatting status](https://github.com/arduino/arduino-lint/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-prettier-formatting-task.yml) [![Check General Formatting status](https://github.com/arduino/arduino-lint/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-general-formatting-task.yml) [![Check Shell Scripts status](https://github.com/arduino/arduino-lint/actions/workflows/check-shell-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-shell-task.yml) [![Check Certificates status](https://github.com/arduino/arduino-lint/actions/workflows/check-certificates.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-certificates.yml) From db8fc9e4b52c1e2e3620d875dd90d1285794fa52 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 00:31:19 -0700 Subject: [PATCH 11/11] Bring all files into Prettier formatting compliance Prettier formatting is now being applied to all supported files rather than only Markdown and YAML files as previously. Some files were not compliant. --- Taskfile.yml | 1 - docs/css/version-select.css | 4 +-- docs/js/version-select.js | 71 +++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 0efdcbe2..05a34530 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -390,7 +390,6 @@ vars: -X {{ .CONFIGURATION_PACKAGE }}.buildTimestamp={{.TIMESTAMP}} ' GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic" - DOCS_VERSION: dev DOCS_ALIAS: "" DOCS_REMOTE: "origin" diff --git a/docs/css/version-select.css b/docs/css/version-select.css index 49079bf4..e5bd98b8 100644 --- a/docs/css/version-select.css +++ b/docs/css/version-select.css @@ -1,5 +1,5 @@ -@media only screen and (max-width:76.1875em) { +@media only screen and (max-width: 76.1875em) { #version-selector { - padding: .6rem .8rem; + padding: 0.6rem 0.8rem; } } diff --git a/docs/js/version-select.js b/docs/js/version-select.js index 6c316b81..61d8307e 100644 --- a/docs/js/version-select.js +++ b/docs/js/version-select.js @@ -1,50 +1,51 @@ window.addEventListener("DOMContentLoaded", function () { // This is a bit hacky. Figure out the base URL from a known CSS file the // template refers to... - var ex = new RegExp("/?assets/fonts/material-icons.css$"); - var sheet = document.querySelector('link[href$="material-icons.css"]'); + var ex = new RegExp("/?assets/fonts/material-icons.css$") + var sheet = document.querySelector('link[href$="material-icons.css"]') - var REL_BASE_URL = sheet.getAttribute("href").replace(ex, ""); - var ABS_BASE_URL = sheet.href.replace(ex, ""); - var CURRENT_VERSION = ABS_BASE_URL.split("/").pop(); + var REL_BASE_URL = sheet.getAttribute("href").replace(ex, "") + var ABS_BASE_URL = sheet.href.replace(ex, "") + var CURRENT_VERSION = ABS_BASE_URL.split("/").pop() function makeSelect(options, selected) { - var select = document.createElement("select"); - select.classList.add("form-control"); + var select = document.createElement("select") + select.classList.add("form-control") options.forEach(function (i) { - var option = new Option(i.text, i.value, undefined, - i.value === selected); - select.add(option); - }); + var option = new Option(i.text, i.value, undefined, i.value === selected) + select.add(option) + }) - return select; + return select } - var xhr = new XMLHttpRequest(); - xhr.open("GET", ABS_BASE_URL + "/../versions.json"); + var xhr = new XMLHttpRequest() + xhr.open("GET", ABS_BASE_URL + "/../versions.json") xhr.onload = function () { - var versions = JSON.parse(this.responseText); + var versions = JSON.parse(this.responseText) var realVersion = versions.find(function (i) { - return i.version === CURRENT_VERSION || - i.aliases.includes(CURRENT_VERSION); - }).version; - - var select = makeSelect(versions.map(function (i) { - return { text: i.title, value: i.version }; - }), realVersion); + return i.version === CURRENT_VERSION || i.aliases.includes(CURRENT_VERSION) + }).version + + var select = makeSelect( + versions.map(function (i) { + return { text: i.title, value: i.version } + }), + realVersion + ) select.addEventListener("change", function (event) { - window.location.href = ABS_BASE_URL + "/../" + this.value; - }); - - var container = document.createElement("div"); - container.id = "version-selector"; - container.className = "md-nav__item"; - container.appendChild(select); - - var sidebar = document.querySelector(".md-nav--primary > .md-nav__list"); - sidebar.parentNode.insertBefore(container, sidebar); - }; - xhr.send(); -}); + window.location.href = ABS_BASE_URL + "/../" + this.value + }) + + var container = document.createElement("div") + container.id = "version-selector" + container.className = "md-nav__item" + container.appendChild(select) + + var sidebar = document.querySelector(".md-nav--primary > .md-nav__list") + sidebar.parentNode.insertBefore(container, sidebar) + } + xhr.send() +})