This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New test infrastructure * Enable push to Git * fix reporting * links to errors * better visual on errors * Improved logging * Fixes to content * Fixed logging when everything passes * Moves to JS Script * logging fix * Don’t use test files * Adds checks for files changed * Don't write extra file * Remove checkIfUpdatedUpdated
- Loading branch information
Showing
80 changed files
with
2,182 additions
and
685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
|
||
const wfRegEx = require('../wfRegEx'); | ||
const visit = require('unist-util-visit'); | ||
var toString = require('mdast-util-to-string'); | ||
|
||
module.exports = { | ||
'wf-headings-tldr': wfTLDR, | ||
'wf-headings-blank': wfHeadingsBlank, | ||
'wf-headings-in-markdown': wfHeadingsInMarkdown, | ||
'wf-headings-no-markup-in-title': wfNoMarkupInTitle, | ||
}; | ||
|
||
const reEntity = /&\w*?;/; | ||
const reHTML = /</; | ||
const reMD = /`/; | ||
const reTLDR = /tl;dr/i; | ||
const reHeading = /^<h\d>.*?<\/h\d>$/i; | ||
const reHideFromTOC = /.hide-from-toc/; | ||
|
||
function wfHeadingsInMarkdown(ast, file, setting) { | ||
let msg = 'Headings must use markdown style, HTML is not permitted.'; | ||
visit(ast, 'html', function (node) { | ||
if (reHeading.test(node.value)) { | ||
file.message(msg, node); | ||
} | ||
}); | ||
} | ||
|
||
function wfHeadingsBlank(ast, file, setting) { | ||
visit(ast, 'heading', function(node) { | ||
let title = toString(node).trim(); | ||
if (title.length === 0) { | ||
file.message('Headings cannot be empty.', node); | ||
} | ||
}); | ||
} | ||
|
||
function wfNoMarkupInTitle(ast, file, setting) { | ||
visit(ast, 'heading', function(node) { | ||
if (node.depth !== 1) { | ||
return; | ||
} | ||
let title = toString(node); | ||
if (reHTML.test(title)) { | ||
file.message('Top level headings cannot contain HTML elements', node); | ||
} | ||
if (reMD.test(title)) { | ||
file.message('Top level headings cannot contain Markdown', node); | ||
} | ||
if (reEntity.test(title)) { | ||
file.message('Top level headings cannot contain encoded entities', node); | ||
} | ||
}); | ||
} | ||
|
||
function wfTLDR(ast, file, setting) { | ||
let msgLevel = 'TL;DR headings must be level 3 or greater.'; | ||
let msgHide = 'TL;DR headings must be hidden from the TOC with `{: .hide-from-toc }`'; | ||
visit(ast, 'heading', function(node) { | ||
let body = toString(node); | ||
if (reTLDR.test(body)) { | ||
if (node.depth < 3) { | ||
file.message(msgLevel, node); | ||
} | ||
if (!reHideFromTOC.test(body)) { | ||
file.message(msgHide, node); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
|
||
const url = require('url'); | ||
const wfRegEx = require('../wfRegEx'); | ||
const visit = require('unist-util-visit'); | ||
const toString = require('mdast-util-to-string'); | ||
|
||
module.exports = { | ||
'wf-html-you-tube': wfYouTube, | ||
'wf-html-dgc-links': wfHTMLDGCLinks, | ||
'wf-html-internal-links': wfInternalLinks, | ||
'wf-html-link-forced-lang': wfForcedLang, | ||
'wf-html-unsafe-short-links': wfUnsafeShortLinks | ||
}; | ||
|
||
const reYouTube = /^<iframe\s.*?src=['|"]https?:\/\/(www.)?youtube.com\/.*?['|"| ].*>[.\s\n\r]*?<\/iframe>$/i; | ||
const reDGCLink = /^<a\s.*?href=['|"]?(https?:)?\/\/developers.google.com/i; | ||
const reSandboxedLink = /^<a\s.*?href=['|"]?(https?:)?\/\/sandbox.google.com/i; | ||
const reGooGL = /^<a\s.*?href=['|"]?http:\/\/goo\.gl\//i; | ||
const reHref = /^<a\s.*href=['|"](.*)['|"]>/i; | ||
|
||
function wfYouTube(ast, file, setting) { | ||
let msg = 'YouTube videos must use DevSite embed.'; | ||
visit(ast, 'html', function (node) { | ||
if (reYouTube.test(node.value)) { | ||
file.message(msg, node); | ||
} | ||
}); | ||
} | ||
|
||
function wfHTMLDGCLinks(ast, file, setting) { | ||
let msg = 'Do not hard code `developers.google.com` in links.'; | ||
visit(ast, 'html', function (node) { | ||
if (reDGCLink.test(node.value)) { | ||
file.message(msg, node); | ||
} | ||
}); | ||
} | ||
|
||
function wfInternalLinks(ast, file, setting) { | ||
let msg = 'Do not use internal Google sandboxed links'; | ||
visit(ast, 'html', function (node) { | ||
if (reSandboxedLink.test(node.value)) { | ||
file.message(msg, node); | ||
} | ||
}); | ||
} | ||
|
||
function wfUnsafeShortLinks(ast, file, setting) { | ||
let msg = 'Do not use unsafe `HTTP://goo.gl/` links'; | ||
visit(ast, 'html', function (node) { | ||
if (reGooGL.test(node.value)) { | ||
file.message(msg, node); | ||
} | ||
}); | ||
} | ||
|
||
function wfForcedLang(ast, file, setting) { | ||
let msg = 'Hard coded language URL in link (`hl=xx`).'; | ||
visit(ast, 'html', function (node) { | ||
let match = reHref.exec(node.value); | ||
if (match && match[1]) { | ||
let parsedUrl = url.parse(match[1]); | ||
let queryString = parsedUrl.query; | ||
if (queryString && queryString.toLowerCase().indexOf('hl=') >= 0) { | ||
file.message(msg, node); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const visit = require('unist-util-visit'); | ||
|
||
module.exports = { | ||
'wf-images-md': wfImagesInMD, | ||
'wf-images-html': wfImagesInHTML, | ||
}; | ||
|
||
const reRemote = /(https?:)?\/\//i; | ||
const reImgTag = /<img /i; | ||
const reImgSrc = /src=['|"](.*?)['|"|>|\s]/i; | ||
|
||
|
||
function doesImageExist(file, imgPath, node) { | ||
let msgHardCoded = 'Do not hard code `developers.google.com` in paths.'; | ||
if (reRemote.test(imgPath)) { | ||
if (imgPath.indexOf('developers.google.com') > 0) { | ||
file.message(msgHardCoded, node); | ||
imgPath = imgPath.replace(/https?:\/\/developers\.google\.com/i, ''); | ||
} else { | ||
return; | ||
} | ||
} | ||
let filePath = file.cwd; | ||
if (imgPath.indexOf('/') === 0) { | ||
filePath = path.join(filePath, 'src/content/en', imgPath.replace('/web/', '')); | ||
} else { | ||
filePath = path.join(filePath, file.dirname, imgPath); | ||
} | ||
try { | ||
fs.accessSync(filePath, fs.R_OK); | ||
return true; | ||
} catch (ex) { | ||
let msg = `Unable to find image \`${imgPath}\``; | ||
file.message(msg, node); | ||
} | ||
} | ||
|
||
function wfImagesInMD(ast, file, setting) { | ||
visit(ast, 'image', function (node) { | ||
if (node.url && node.url.trim().length > 0) { | ||
doesImageExist(file, node.url, node); | ||
} | ||
}); | ||
} | ||
|
||
function wfImagesInHTML(ast, file, setting) { | ||
visit(ast, 'html', function (node) { | ||
let matched = reImgSrc.exec(node.value); | ||
if (matched && matched[1]) { | ||
doesImageExist(file, matched[1], node); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
const url = require('url'); | ||
const visit = require('unist-util-visit'); | ||
|
||
module.exports = { | ||
'wf-links-forced-lang': wfForcedLang, | ||
'wf-links-dgc': wfDGCLinks, | ||
'wf-links-unsafe-short': wfUnsafeShort, | ||
'wf-links-internal': wfInternalLinks | ||
}; | ||
|
||
// Check for links with hard coded languages | ||
function wfForcedLang(ast, file, setting) { | ||
let msg = 'Hard coded language URL in link (`hl=xx`)'; | ||
visit(ast, 'link', function (node) { | ||
let parsedUrl = url.parse(node.url); | ||
let queryString = parsedUrl.query; | ||
if (queryString && queryString.toLowerCase().indexOf('hl=') >= 0) { | ||
file.message(msg, node); | ||
} | ||
}); | ||
} | ||
|
||
// Check for links with FQDN to DevSite | ||
function wfDGCLinks(ast, file, setting) { | ||
let msg = 'Do not hard code `developers.google.com` in links.'; | ||
visit(ast, 'link', function (node) { | ||
let parsedUrl = url.parse(node.url); | ||
let hostname = parsedUrl.hostname; | ||
if (hostname && hostname.toLowerCase() === 'developers.google.com') { | ||
file.message(msg, node); | ||
} | ||
}); | ||
} | ||
|
||
// Check for unsecured shortlinks | ||
function wfUnsafeShort(ast, file, setting) { | ||
let msg = 'Do not use unsafe `HTTP://goo.gl/` links'; | ||
visit(ast, 'link', function (node) { | ||
let parsedUrl = url.parse(node.url); | ||
let protocol = parsedUrl.protocol; | ||
let hostname = parsedUrl.hostname; | ||
if (hostname && hostname.toLowerCase() === 'goo.gl') { | ||
if (protocol && protocol.toLowerCase() === 'http:') { | ||
file.message(msg, node); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// Check for internal & sandboxed links | ||
function wfInternalLinks(ast, file, setting) { | ||
let msg = 'Do not use internal Google sandboxed links.'; | ||
visit(ast, 'link', function (node) { | ||
let parsedUrl = url.parse(node.url); | ||
let hostname = parsedUrl.hostname; | ||
if (hostname && hostname.toLowerCase() === 'sandbox.google.com') { | ||
file.message(msg, node); | ||
} | ||
}); | ||
} |
Oops, something went wrong.