build: auto-fix whitespace in docs in pre-commit hook (#17490)

This commit is contained in:
Samuel Attard 2019-03-21 12:15:55 -07:00 committed by GitHub
parent 6555be2636
commit 784f9742bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 11 deletions

View file

@ -7,4 +7,4 @@
* `bypassCSP` Boolean (optional) - Default false.
* `allowServiceWorkers` Boolean (optional) - Default false.
* `supportFetchAPI` Boolean (optional) - Default false.
* `corsEnabled` Boolean (optional) - Default false.
* `corsEnabled` Boolean (optional) - Default false.

View file

@ -5,4 +5,4 @@
* `sender` WebContents - Returns the `webContents` that sent the message
* `reply` Function - A function that will send an IPC message to the renderer frame that sent the original message that you are currently handling. You should use this method to "reply" to the sent message in order to guaruntee the reply will go to the correct process and frame.
* `...args` any[]
IpcRenderer
IpcRenderer

View file

@ -7,4 +7,4 @@
* `contentLengths` Number[] - The total size of the content, in bytes.
* `price` Number - The cost of the product in the local currency.
* `formattedPrice` String - The locale formatted price of the product.
* `downloadable` Boolean - A Boolean value that indicates whether the App Store has downloadable content for this product.
* `downloadable` Boolean - A Boolean value that indicates whether the App Store has downloadable content for this product.

View file

@ -2,4 +2,4 @@
* `code` String
* `url` String (optional)
* `startLine` Integer (optional) - Default is 1.
* `startLine` Integer (optional) - Default is 1.

View file

@ -118,4 +118,4 @@ inAppPurchase.getProducts(PRODUCT_IDS).then(products => {
console.log('The payment has been added to the payment queue.')
})
})
```
```

View file

@ -38,4 +38,4 @@ parameters. You can find these in your app in the global variable
[unity-launcher]: https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles#Adding_shortcuts_to_a_launcher
[audacious-launcher]: https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles?action=AttachFile&do=get&target=shortcuts.png
[spec]: https://specifications.freedesktop.org/desktop-entry-spec/1.1/ar01s11.html
[spec]: https://specifications.freedesktop.org/desktop-entry-spec/1.1/ar01s11.html

View file

@ -149,4 +149,4 @@ autoUpdater.on('error', message => {
[electron-release-server]: https://github.com/ArekSredzki/electron-release-server
[nucleus]: https://github.com/atlassian/nucleus
[update.electronjs.org]: https://github.com/electron/update.electronjs.org
[update-electron-app]: https://github.com/electron/update-electron-app
[update-electron-app]: https://github.com/electron/update-electron-app

View file

@ -116,8 +116,9 @@
"node script/lint.js --py --fix --only --",
"git add"
],
"docs/api/*.md": [
"docs/api/**/*.md": [
"node script/gen-filenames.js",
"python script/check-trailing-whitespace.py --fix",
"git add filenames.auto.gni"
]
}

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python
import argparse
import os
import sys
@ -9,6 +10,8 @@ DOCS_DIR = os.path.join(SOURCE_ROOT, 'docs')
def main():
os.chdir(SOURCE_ROOT)
args = parse_args()
filepaths = []
totalDirs = 0
try:
@ -23,7 +26,7 @@ def main():
trailingWhiteSpaceFiles = 0
for path in filepaths:
trailingWhiteSpaceFiles += hasTrailingWhiteSpace(path)
trailingWhiteSpaceFiles += hasTrailingWhiteSpace(path, args.fix)
print('Parsed through ' + str(len(filepaths)) +
' files within docs directory and its ' +
@ -32,7 +35,7 @@ def main():
' files with trailing whitespace.')
return trailingWhiteSpaceFiles
def hasTrailingWhiteSpace(filepath):
def hasTrailingWhiteSpace(filepath, fix):
try:
f = open(filepath, 'r')
lines = f.read().splitlines()
@ -41,12 +44,26 @@ def hasTrailingWhiteSpace(filepath):
finally:
f.close()
fixed_lines = []
for line in lines:
if line != line.rstrip():
fixed_lines.append(line.rstrip() + '\n')
if not fix and line != line.rstrip():
print "Trailing whitespace in: " + filepath
return True
if fix:
with open(filepath, 'w') as f:
print(fixed_lines)
f.writelines(fixed_lines)
return False
def parse_args():
parser = argparse.ArgumentParser(
description='Check for trailing whitespace in md files')
parser.add_argument('-f', '--fix',
help='Automatically fix trailing whitespace issues',
action='store_true')
return parser.parse_known_args()[0]
if __name__ == '__main__':
sys.exit(main())