You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ha...@apache.org on 2018/03/21 12:14:41 UTC
[3/7] incubator-weex-site git commit: Add line and column of file in
url validator
Add line and column of file in url validator
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex-site/commit/84e5b7c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex-site/tree/84e5b7c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex-site/diff/84e5b7c6
Branch: refs/heads/master
Commit: 84e5b7c6fc656d853692b36783f09c631dc7693a
Parents: 3cefc51
Author: Zhenfei You <he...@imyzf.com>
Authored: Wed Mar 21 15:01:09 2018 +0800
Committer: Zhenfei You <he...@imyzf.com>
Committed: Wed Mar 21 15:01:09 2018 +0800
----------------------------------------------------------------------
package-lock.json | 6 ++++++
package.json | 1 +
test/url-validator.js | 17 +++++++++++++++--
3 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex-site/blob/84e5b7c6/package-lock.json
----------------------------------------------------------------------
diff --git a/package-lock.json b/package-lock.json
index 7ff0f25..c9344bd 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1555,6 +1555,12 @@
"unpipe": "1.0.0"
}
},
+ "find-line-column": {
+ "version": "0.5.2",
+ "resolved": "https://registry.npmjs.org/find-line-column/-/find-line-column-0.5.2.tgz",
+ "integrity": "sha1-2wAjj/hoVRoYLnShA0FtKVqYyMo=",
+ "dev": true
+ },
"find-up": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
http://git-wip-us.apache.org/repos/asf/incubator-weex-site/blob/84e5b7c6/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index fc83e0a..e2ba441 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
},
"devDependencies": {
"chalk": "^2.3.2",
+ "find-line-column": "^0.5.2",
"glob": "^7.1.2",
"node-fetch": "^2.1.1",
"url-extractor": "^2.0.2"
http://git-wip-us.apache.org/repos/asf/incubator-weex-site/blob/84e5b7c6/test/url-validator.js
----------------------------------------------------------------------
diff --git a/test/url-validator.js b/test/url-validator.js
index 1fb2fee..f020d52 100644
--- a/test/url-validator.js
+++ b/test/url-validator.js
@@ -3,6 +3,7 @@ const fs = require('fs')
const fetch = require('node-fetch')
const urlExtractor = require('url-extractor')
const chalk = require('chalk')
+const findLineColumn = require('find-line-column')
const extractUrls = urlExtractor.extractUrls
const SOURCE_TYPE_MARKDOWN = urlExtractor.SOURCE_TYPE_MARKDOWN
@@ -11,11 +12,23 @@ const whiteList = [
'localhost'
]
+function log(errorCode, url, file, position) {
+ console.log(chalk.bgRed(errorCode), chalk.yellow(url),
+ `${file}:${position.line}:${position.col}`);
+}
+
glob('source/**/*.md', (err, files) => {
files.forEach((file, fileIndex) => {
fs.readFile(file, { encoding: 'utf-8' }, (err, text) => {
+ if (err) {
+ console.error(err)
+ return
+ }
+
const urls = extractUrls(text, SOURCE_TYPE_MARKDOWN)
urls.forEach(url => {
+ const position = findLineColumn(text, text.indexOf(url))
+
// '//xxx.com' -> 'http://xxx.com'
if (url.match(/^\/\//)) url = 'http:' + url
@@ -30,12 +43,12 @@ glob('source/**/*.md', (err, files) => {
fetch(url)
.then(res => {
if (res.status >= 400) {
- console.log(chalk.bgRed(res.status), chalk.yellow(url), file)
+ log(res.status, url, file, position);
}
})
.catch(err => {
if (err.code !== 'ECONNREFUSED' && err.code !== 'ECONNRESET') {
- console.log(chalk.bgRed(err.code), chalk.yellow(url), file)
+ log(err.code, url, file, position)
}
})
})