build: auto-fix whitespace in docs in pre-commit hook (#17490)
This commit is contained in:
parent
6555be2636
commit
784f9742bc
9 changed files with 29 additions and 11 deletions
|
@ -7,4 +7,4 @@
|
||||||
* `bypassCSP` Boolean (optional) - Default false.
|
* `bypassCSP` Boolean (optional) - Default false.
|
||||||
* `allowServiceWorkers` Boolean (optional) - Default false.
|
* `allowServiceWorkers` Boolean (optional) - Default false.
|
||||||
* `supportFetchAPI` Boolean (optional) - Default false.
|
* `supportFetchAPI` Boolean (optional) - Default false.
|
||||||
* `corsEnabled` Boolean (optional) - Default false.
|
* `corsEnabled` Boolean (optional) - Default false.
|
||||||
|
|
|
@ -5,4 +5,4 @@
|
||||||
* `sender` WebContents - Returns the `webContents` that sent the message
|
* `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.
|
* `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[]
|
* `...args` any[]
|
||||||
IpcRenderer
|
IpcRenderer
|
||||||
|
|
|
@ -7,4 +7,4 @@
|
||||||
* `contentLengths` Number[] - The total size of the content, in bytes.
|
* `contentLengths` Number[] - The total size of the content, in bytes.
|
||||||
* `price` Number - The cost of the product in the local currency.
|
* `price` Number - The cost of the product in the local currency.
|
||||||
* `formattedPrice` String - The locale formatted price of the product.
|
* `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.
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
* `code` String
|
* `code` String
|
||||||
* `url` String (optional)
|
* `url` String (optional)
|
||||||
* `startLine` Integer (optional) - Default is 1.
|
* `startLine` Integer (optional) - Default is 1.
|
||||||
|
|
|
@ -118,4 +118,4 @@ inAppPurchase.getProducts(PRODUCT_IDS).then(products => {
|
||||||
console.log('The payment has been added to the payment queue.')
|
console.log('The payment has been added to the payment queue.')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
@ -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
|
[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
|
[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
|
||||||
|
|
|
@ -149,4 +149,4 @@ autoUpdater.on('error', message => {
|
||||||
[electron-release-server]: https://github.com/ArekSredzki/electron-release-server
|
[electron-release-server]: https://github.com/ArekSredzki/electron-release-server
|
||||||
[nucleus]: https://github.com/atlassian/nucleus
|
[nucleus]: https://github.com/atlassian/nucleus
|
||||||
[update.electronjs.org]: https://github.com/electron/update.electronjs.org
|
[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
|
||||||
|
|
|
@ -116,8 +116,9 @@
|
||||||
"node script/lint.js --py --fix --only --",
|
"node script/lint.js --py --fix --only --",
|
||||||
"git add"
|
"git add"
|
||||||
],
|
],
|
||||||
"docs/api/*.md": [
|
"docs/api/**/*.md": [
|
||||||
"node script/gen-filenames.js",
|
"node script/gen-filenames.js",
|
||||||
|
"python script/check-trailing-whitespace.py --fix",
|
||||||
"git add filenames.auto.gni"
|
"git add filenames.auto.gni"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -9,6 +10,8 @@ DOCS_DIR = os.path.join(SOURCE_ROOT, 'docs')
|
||||||
def main():
|
def main():
|
||||||
os.chdir(SOURCE_ROOT)
|
os.chdir(SOURCE_ROOT)
|
||||||
|
|
||||||
|
args = parse_args()
|
||||||
|
|
||||||
filepaths = []
|
filepaths = []
|
||||||
totalDirs = 0
|
totalDirs = 0
|
||||||
try:
|
try:
|
||||||
|
@ -23,7 +26,7 @@ def main():
|
||||||
|
|
||||||
trailingWhiteSpaceFiles = 0
|
trailingWhiteSpaceFiles = 0
|
||||||
for path in filepaths:
|
for path in filepaths:
|
||||||
trailingWhiteSpaceFiles += hasTrailingWhiteSpace(path)
|
trailingWhiteSpaceFiles += hasTrailingWhiteSpace(path, args.fix)
|
||||||
|
|
||||||
print('Parsed through ' + str(len(filepaths)) +
|
print('Parsed through ' + str(len(filepaths)) +
|
||||||
' files within docs directory and its ' +
|
' files within docs directory and its ' +
|
||||||
|
@ -32,7 +35,7 @@ def main():
|
||||||
' files with trailing whitespace.')
|
' files with trailing whitespace.')
|
||||||
return trailingWhiteSpaceFiles
|
return trailingWhiteSpaceFiles
|
||||||
|
|
||||||
def hasTrailingWhiteSpace(filepath):
|
def hasTrailingWhiteSpace(filepath, fix):
|
||||||
try:
|
try:
|
||||||
f = open(filepath, 'r')
|
f = open(filepath, 'r')
|
||||||
lines = f.read().splitlines()
|
lines = f.read().splitlines()
|
||||||
|
@ -41,12 +44,26 @@ def hasTrailingWhiteSpace(filepath):
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
fixed_lines = []
|
||||||
for line in 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
|
print "Trailing whitespace in: " + filepath
|
||||||
return True
|
return True
|
||||||
|
if fix:
|
||||||
|
with open(filepath, 'w') as f:
|
||||||
|
print(fixed_lines)
|
||||||
|
f.writelines(fixed_lines)
|
||||||
|
|
||||||
return False
|
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__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue