diff --git a/Dockerfile b/Dockerfile index 23995221..13075cf7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,9 @@ FROM ruby:2.6-slim as ruby-deps ARG RUNTIME_DEPS ARG BUILD_DEPS +# set to always UTF8 +ENV LANG=C.UTF-8 + # Install build deps RUN apt-get update && \ apt-get install --no-install-recommends -y $RUNTIME_DEPS $BUILD_DEPS && \ diff --git a/lib/github_markup_check_and_render b/lib/github_markup_check_and_render index 4249bd91..cc7d3ac9 100755 --- a/lib/github_markup_check_and_render +++ b/lib/github_markup_check_and_render @@ -1,8 +1,10 @@ #!/usr/bin/env ruby +# encoding: UTF-8 # Modified github_markup utility which checks first that the file can be rendered before rendering $LOAD_PATH.unshift File.dirname(File.realpath(__FILE__)) + "/../lib" require 'github/markup' +require 'charlock_holmes' if ARGV.size < 1 print "usage: #{File.basename($0)} FILE\n" @@ -14,8 +16,10 @@ file_contents = nil begin file = File.open( name, "r" ) - file_contents = file.read + encoded_contents = file.read file.close + detection = CharlockHolmes::EncodingDetector.detect(encoded_contents) + file_contents = encoded_contents.encode("UTF-8", detection[:encoding], invalid: :replace, replace: "") rescue Exception => e $stderr.print "error: #{e.message}\n" exit 1 diff --git a/package-lock.json b/package-lock.json index 55513b5c..f5afb1c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2145,9 +2145,9 @@ } }, "@eslint/eslintrc": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.1.tgz", - "integrity": "sha512-XRUeBZ5zBWLYgSANMpThFddrZZkEbGHgUdt5UJjZfnlN9BGCiUBrf+nvbRupSjMvqzwnQN0qwCmOxITt1cfywA==", + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.2.tgz", + "integrity": "sha512-EfB5OHNYp1F4px/LI/FEnGylop7nOqkQ1LRzCM0KccA2U8tvV8w01KBv37LbO7nW4H+YhKyo2LcJhRwjjV17QQ==", "dev": true, "requires": { "ajv": "^6.12.4", @@ -2752,9 +2752,9 @@ } }, "@types/babel__traverse": { - "version": "7.0.16", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.16.tgz", - "integrity": "sha512-S63Dt4CZOkuTmpLGGWtT/mQdVORJOpx6SZWGVaP56dda/0Nx5nEe82K7/LAm8zYr6SfMq+1N2OreIOrHAx656w==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.11.0.tgz", + "integrity": "sha512-kSjgDMZONiIfSH1Nxcr5JIRMwUetDki63FSQfpTCz8ogF3Ulqm8+mr5f78dUYs6vMiB6gBusQqfQmBvHZj/lwg==", "requires": { "@babel/types": "^7.3.0" } @@ -3656,7 +3656,7 @@ } }, "broken-link-checker": { - "version": "github:prototypicalpro/broken-link-checker#9cdd806d578ef0aae1c5ab9d927fac14ea1e1bb0", + "version": "github:prototypicalpro/broken-link-checker#7032781fe8768da4943f8757de6825cab83432c4", "from": "github:prototypicalpro/broken-link-checker#master", "requires": { "auto-tunnel": "github:stevenvachon/auto-tunnel", @@ -4983,9 +4983,9 @@ "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=" }, "core-js": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.8.0.tgz", - "integrity": "sha512-W2VYNB0nwQQE7tKS7HzXd7r2y/y2SVJl4ga6oH/dnaLFzM0o2lB2P3zCkWj5Wc/zyMYjtgd5Hmhk0ObkQFZOIA==" + "version": "3.8.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.8.1.tgz", + "integrity": "sha512-9Id2xHY1W7m8hCl8NkhQn5CufmF/WuR30BTRewvCXc1aZd3kMECwNZ69ndLbekKfakw9Rf2Xyc+QR6E7Gg+obg==" }, "core-js-compat": { "version": "3.8.0", @@ -5957,13 +5957,13 @@ } }, "eslint": { - "version": "7.14.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.14.0.tgz", - "integrity": "sha512-5YubdnPXrlrYAFCKybPuHIAH++PINe1pmKNc5wQRB9HSbqIK1ywAnntE3Wwua4giKu0bjligf1gLF6qxMGOYRA==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.15.0.tgz", + "integrity": "sha512-Vr64xFDT8w30wFll643e7cGrIkPEU50yIiI36OdSIDoSGguIeaLzBo0vpGvzo9RECUqq7htURfwEtKqwytkqzA==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@eslint/eslintrc": "^0.2.1", + "@eslint/eslintrc": "^0.2.2", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -5973,10 +5973,10 @@ "eslint-scope": "^5.1.1", "eslint-utils": "^2.1.0", "eslint-visitor-keys": "^2.0.0", - "espree": "^7.3.0", + "espree": "^7.3.1", "esquery": "^1.2.0", "esutils": "^2.0.2", - "file-entry-cache": "^5.0.1", + "file-entry-cache": "^6.0.0", "functional-red-black-tree": "^1.0.1", "glob-parent": "^5.0.0", "globals": "^12.1.0", @@ -6361,13 +6361,13 @@ "dev": true }, "espree": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.0.tgz", - "integrity": "sha512-dksIWsvKCixn1yrEXO8UosNSxaDoSYpq9reEjZSbHLpT5hpaCAKTLBwq0RHtLrIr+c0ByiYzWT8KTMRzoRCNlw==", + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.1.tgz", + "integrity": "sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g==", "dev": true, "requires": { "acorn": "^7.4.0", - "acorn-jsx": "^5.2.0", + "acorn-jsx": "^5.3.1", "eslint-visitor-keys": "^1.3.0" }, "dependencies": { @@ -6730,12 +6730,12 @@ } }, "file-entry-cache": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", - "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.0.tgz", + "integrity": "sha512-fqoO76jZ3ZnYrXLDRxBR1YvOvc0k844kcOg40bgsPrE25LAb/PDqTY+ho64Xh2c8ZXgIKldchCFHczG2UVRcWA==", "dev": true, "requires": { - "flat-cache": "^2.0.1" + "flat-cache": "^3.0.4" } }, "file-uri-to-path": { @@ -6849,31 +6849,19 @@ "dev": true }, "flat-cache": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", - "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", + "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", "dev": true, "requires": { - "flatted": "^2.0.0", - "rimraf": "2.6.3", - "write": "1.0.3" - }, - "dependencies": { - "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", - "dev": true, - "requires": { - "glob": "^7.1.3" - } - } + "flatted": "^3.1.0", + "rimraf": "^3.0.2" } }, "flatted": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz", - "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.1.0.tgz", + "integrity": "sha512-tW+UkmtNg/jv9CSofAKvgVcO7c2URjhTdW1ZTkcAritblu8tajiYy7YisnIflEwtKssCtOxpnBRoCB7iap0/TA==", "dev": true }, "flush-write-stream": { @@ -7981,9 +7969,9 @@ } }, "humanize-duration": { - "version": "3.24.0", - "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.24.0.tgz", - "integrity": "sha512-B3udnqisaDeRsvUSb+5n2hjxhABI9jotB+i1IEhgHhguTeM5LxIUKoVIu7UpeyaPOygr/Fnv7UhOi45kYYG+tg==" + "version": "3.25.0", + "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.25.0.tgz", + "integrity": "sha512-QXth17C/8J2QVO0urby5sANmgvwdOF4YZW3mO13ZTkJli4ltVphzMJVG+HkVuTN/bIq1W/O0jRYSyQACus/GVQ==" }, "humanize-url": { "version": "1.0.1", @@ -9788,9 +9776,9 @@ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, "js-yaml": { - "version": "3.14.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz", - "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==", + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -10843,6 +10831,16 @@ "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, + "js-yaml": { + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz", + "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, "locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -13250,9 +13248,9 @@ "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==" }, "simple-git": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-2.24.0.tgz", - "integrity": "sha512-nF31Xai5lTYgRCiSJ1lHzK0Vk9jWOvAFW12bdBaWy2bhodio04eOWYurvyM/nTBYsPIiQl3PFvdod5TRcPvzww==", + "version": "2.25.0", + "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-2.25.0.tgz", + "integrity": "sha512-RMBFWKiPDl3rAoFbEaCVsjQ0v6sgR0q7cyUF9e/4lR81Mf2/5xwop0aCQatUDXKMIXnkuOG6aTEadQmGtOw4mg==", "requires": { "@kwsites/file-exists": "^1.1.1", "@kwsites/promise-deferred": "^1.1.1", @@ -15245,15 +15243,6 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, - "write": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", - "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", - "dev": true, - "requires": { - "mkdirp": "^0.5.1" - } - }, "write-file-atomic": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", diff --git a/package.json b/package.json index f68bb268..e84aff58 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "gitlog": "^4.0.3", "is-windows": "^1.0.2", "isbinaryfile": "^4.0.6", - "js-yaml": "^3.14.0", + "js-yaml": "^3.14.1", "jsonfile": "^6.1.0", "lodash": "^4.17.20", "log-symbols": "^4.0.0", @@ -52,7 +52,7 @@ "nock": "^13.0.5", "node-fetch": "^2.6.0", "rimraf": "^3.0.2", - "simple-git": "^2.24.0", + "simple-git": "^2.25.0", "standardjs": "^1.0.0-alpha", "yargs": "^15.4.1" }, @@ -62,7 +62,7 @@ "chai-each": "0.0.1", "chai-string": "^1.5.0", "documentation": "^13.1.0", - "eslint": "^7.14.0", + "eslint": "^7.15.0", "eslint-config-prettier": "^6.15.0", "eslint-config-prettier-standard": "^3.0.1", "eslint-config-standard": "^14.1.1", diff --git a/rules/file-no-broken-links.js b/rules/file-no-broken-links.js index b4a42bd4..9dbe5eb6 100644 --- a/rules/file-no-broken-links.js +++ b/rules/file-no-broken-links.js @@ -77,12 +77,10 @@ async function fileNoBrokenLinks(fs, options) { ) // make the messages for the failing URLs const failingMessages = failing.map( - ({ brokenReason, originalURL, http }) => + ({ brokenReason, originalURL, httpResponse }) => `${originalURL} (${ brokenReason.includes('HTTP') - ? `status code ${ - http && http.response && http.response.statusCode - }` + ? `status code ${httpResponse && httpResponse.status}` : `unknown error ${brokenReason}` })` ) @@ -130,13 +128,13 @@ async function fileNoBrokenLinks(fs, options) { message: allMessages.length === 0 ? 'All links are valid' - : allMessages.concat(', ') + : allMessages.join(', ') } }) ) // return the final result const passed = results.every(({ passed }) => passed) - return new Result('', results, passed) + return new Result(passed ? '' : 'Found broken links', results, passed) } module.exports = fileNoBrokenLinks