diff --git a/docs/api/structures/custom-scheme.md b/docs/api/structures/custom-scheme.md index 1b766125262b..1a720a76686e 100644 --- a/docs/api/structures/custom-scheme.md +++ b/docs/api/structures/custom-scheme.md @@ -7,4 +7,4 @@ * `bypassCSP` Boolean (optional) - Default false. * `allowServiceWorkers` Boolean (optional) - Default false. * `supportFetchAPI` Boolean (optional) - Default false. - * `corsEnabled` Boolean (optional) - Default false. \ No newline at end of file + * `corsEnabled` Boolean (optional) - Default false. diff --git a/docs/api/structures/ipc-main-event.md b/docs/api/structures/ipc-main-event.md index 83558d5174d6..4a072c94f9d8 100644 --- a/docs/api/structures/ipc-main-event.md +++ b/docs/api/structures/ipc-main-event.md @@ -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 \ No newline at end of file +IpcRenderer diff --git a/docs/api/structures/product.md b/docs/api/structures/product.md index 911ccc2b5e68..a3d2e9c6d749 100644 --- a/docs/api/structures/product.md +++ b/docs/api/structures/product.md @@ -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. \ No newline at end of file +* `downloadable` Boolean - A Boolean value that indicates whether the App Store has downloadable content for this product. diff --git a/docs/api/structures/web-source.md b/docs/api/structures/web-source.md index 240cb265acd3..74c34f372d31 100644 --- a/docs/api/structures/web-source.md +++ b/docs/api/structures/web-source.md @@ -2,4 +2,4 @@ * `code` String * `url` String (optional) -* `startLine` Integer (optional) - Default is 1. \ No newline at end of file +* `startLine` Integer (optional) - Default is 1. diff --git a/docs/tutorial/in-app-purchases.md b/docs/tutorial/in-app-purchases.md index fbd2acb9f3bb..c689ed127834 100644 --- a/docs/tutorial/in-app-purchases.md +++ b/docs/tutorial/in-app-purchases.md @@ -118,4 +118,4 @@ inAppPurchase.getProducts(PRODUCT_IDS).then(products => { console.log('The payment has been added to the payment queue.') }) }) -``` \ No newline at end of file +``` diff --git a/docs/tutorial/linux-desktop-actions.md b/docs/tutorial/linux-desktop-actions.md index 3713ac69ba01..f4e5695ccf44 100644 --- a/docs/tutorial/linux-desktop-actions.md +++ b/docs/tutorial/linux-desktop-actions.md @@ -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 \ No newline at end of file +[spec]: https://specifications.freedesktop.org/desktop-entry-spec/1.1/ar01s11.html diff --git a/docs/tutorial/updates.md b/docs/tutorial/updates.md index e0245b2f6866..26256afe9feb 100644 --- a/docs/tutorial/updates.md +++ b/docs/tutorial/updates.md @@ -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 \ No newline at end of file +[update-electron-app]: https://github.com/electron/update-electron-app diff --git a/package.json b/package.json index a618a5d34d43..7abf5b23243f 100644 --- a/package.json +++ b/package.json @@ -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" ] } diff --git a/script/check-trailing-whitespace.py b/script/check-trailing-whitespace.py index 3951ba40d3b3..5b100956aaa1 100755 --- a/script/check-trailing-whitespace.py +++ b/script/check-trailing-whitespace.py @@ -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())