Skip to content

Commit

Permalink
feat: finalize no broken links rule and dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
prototypicalpro committed Dec 8, 2020
1 parent a2329fc commit c1b1f72
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 72 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
6 changes: 5 additions & 1 deletion lib/github_markup_check_and_render
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
113 changes: 51 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
"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",
"matched": "^5.0.1",
"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"
},
Expand All @@ -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",
Expand Down
10 changes: 4 additions & 6 deletions rules/file-no-broken-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
})`
)
Expand Down Expand Up @@ -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

0 comments on commit c1b1f72

Please sign in to comment.