build: strip trailing whitespace in docs (#17488)

This commit is contained in:
Milan Burda 2019-03-20 21:12:47 +01:00 committed by Samuel Attard
parent 1c7b3026a6
commit a82bbd010e
12 changed files with 86 additions and 32 deletions

View file

@ -86,6 +86,7 @@ auto_filenames = {
"docs/api/structures/notification-action.md", "docs/api/structures/notification-action.md",
"docs/api/structures/point.md", "docs/api/structures/point.md",
"docs/api/structures/printer-info.md", "docs/api/structures/printer-info.md",
"docs/api/structures/process-memory-info.md",
"docs/api/structures/process-metric.md", "docs/api/structures/process-metric.md",
"docs/api/structures/product.md", "docs/api/structures/product.md",
"docs/api/structures/rectangle.md", "docs/api/structures/rectangle.md",

View file

@ -63,8 +63,9 @@
"lint:cpp": "node ./script/lint.js --cc", "lint:cpp": "node ./script/lint.js --cc",
"lint:py": "node ./script/lint.js --py", "lint:py": "node ./script/lint.js --py",
"lint:gn": "node ./script/lint.js --gn", "lint:gn": "node ./script/lint.js --gn",
"lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run create-typescript-definitions && npm run lint:docs-relative-links", "lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run create-typescript-definitions && npm run lint:docs-relative-links && npm run lint:check-trailing-whitespace",
"lint:docs-relative-links": "python ./script/check-relative-doc-links.py", "lint:docs-relative-links": "python ./script/check-relative-doc-links.py",
"lint:check-trailing-whitespace": "python ./script/check-trailing-whitespace.py",
"lint:js-in-markdown": "standard-markdown docs", "lint:js-in-markdown": "standard-markdown docs",
"create-api-json": "electron-docs-linter docs --outfile=electron-api.json", "create-api-json": "electron-docs-linter docs --outfile=electron-api.json",
"create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --in=electron-api.json --out=electron.d.ts && node spec/ts-smoke/runner.js", "create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --in=electron-api.json --out=electron.d.ts && node spec/ts-smoke/runner.js",

View file

@ -0,0 +1,52 @@
#!/usr/bin/env python
import os
import sys
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
DOCS_DIR = os.path.join(SOURCE_ROOT, 'docs')
def main():
os.chdir(SOURCE_ROOT)
filepaths = []
totalDirs = 0
try:
for root, dirs, files in os.walk(DOCS_DIR):
totalDirs += len(dirs)
for f in files:
if f.endswith('.md'):
filepaths.append(os.path.join(root, f))
except KeyboardInterrupt:
print('Keyboard interruption. Please try again.')
return
trailingWhiteSpaceFiles = 0
for path in filepaths:
trailingWhiteSpaceFiles += hasTrailingWhiteSpace(path)
print('Parsed through ' + str(len(filepaths)) +
' files within docs directory and its ' +
str(totalDirs) + ' subdirectories.')
print('Found ' + str(trailingWhiteSpaceFiles) +
' files with trailing whitespace.')
return trailingWhiteSpaceFiles
def hasTrailingWhiteSpace(filepath):
try:
f = open(filepath, 'r')
lines = f.read().splitlines()
except KeyboardInterrupt:
print('Keyboard interruption whle parsing. Please try again.')
finally:
f.close()
for line in lines:
if line != line.rstrip():
print "Trailing whitespace in: " + filepath
return True
return False
if __name__ == '__main__':
sys.exit(main())