chore: add clang-format and limited linting for Objective-C sources (#18104)

This commit is contained in:
Milan Burda 2019-05-02 14:05:37 +02:00 committed by Cheng Zhao
parent 8785e9007c
commit 9585818a90
35 changed files with 142 additions and 36 deletions

View file

@ -1,3 +1,7 @@
// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
int main(int argc, char* argv[]) {

View file

@ -4,6 +4,8 @@
#include "atom/app/atom_main_delegate.h"
#include <string>
#include "atom/browser/mac/atom_application.h"
#include "atom/common/application_info.h"
#include "atom/common/mac/main_application_bundle.h"

View file

@ -33,6 +33,6 @@ void App::SetAppLogsPath(mate::Arguments* args) {
}
}
} // namespace atom
} // namespace api
} // namespace atom

View file

@ -4,6 +4,8 @@
#include "atom/browser/api/atom_api_app.h"
#include <string>
#import <Cocoa/Cocoa.h>
#include "base/strings/sys_string_conversions.h"
@ -59,6 +61,6 @@ base::RepeatingCallback<void()> App::StartAccessingSecurityScopedResource(
bookmarkUrl);
}
} // namespace atom
} // namespace api
} // namespace atom

View file

@ -4,6 +4,9 @@
#include "atom/browser/api/atom_api_browser_window.h"
#include <memory>
#include <vector>
#import <Cocoa/Cocoa.h>
#include "atom/browser/native_browser_view.h"

View file

@ -4,6 +4,9 @@
#import "atom/browser/api/atom_api_menu_mac.h"
#include <string>
#include <utility>
#include "atom/browser/native_window.h"
#include "atom/browser/unresponsive_suppressor.h"
#include "atom/common/node_includes.h"

View file

@ -4,7 +4,9 @@
#include "atom/browser/api/atom_api_power_monitor.h"
#include <ApplicationServices/ApplicationServices.h>
#include <vector>
#import <ApplicationServices/ApplicationServices.h>
#import <Cocoa/Cocoa.h>
@interface MacLockMonitor : NSObject {

View file

@ -5,6 +5,9 @@
#include "atom/browser/api/atom_api_system_preferences.h"
#include <map>
#include <memory>
#include <string>
#include <utility>
#import <AVFoundation/AVFoundation.h>
#import <Cocoa/Cocoa.h>

View file

@ -4,6 +4,8 @@
#include "atom/browser/auto_updater.h"
#include <string>
#import <ReactiveCocoa/NSObject+RACPropertySubscribing.h>
#import <ReactiveCocoa/RACCommand.h>
#import <ReactiveCocoa/RACSignal.h>
@ -29,7 +31,7 @@ SQRLUpdater* g_updater = nil;
namespace {
bool g_update_available = false;
std::string update_url_ = "";
std::string update_url_ = ""; // NOLINT(runtime/string)
} // namespace

View file

@ -4,6 +4,9 @@
#include "atom/browser/browser.h"
#include <string>
#include <utility>
#include "atom/browser/mac/atom_application.h"
#include "atom/browser/mac/atom_application_delegate.h"
#include "atom/browser/mac/dict_util.h"
@ -282,9 +285,9 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) {
LOG(ERROR) << "Unable to set login item enabled on sandboxed app.";
}
#else
if (settings.open_at_login)
if (settings.open_at_login) {
base::mac::AddToLoginItems(settings.open_as_hidden);
else {
} else {
RemoveFromLoginItems();
}
#endif

View file

@ -4,6 +4,10 @@
#import "atom/browser/mac/atom_application.h"
#include <memory>
#include <string>
#include <utility>
#include "atom/browser/browser.h"
#import "atom/browser/mac/atom_application_delegate.h"
#include "atom/browser/mac/dict_util.h"

View file

@ -4,6 +4,9 @@
#import "atom/browser/mac/atom_application_delegate.h"
#include <memory>
#include <string>
#include "atom/browser/browser.h"
#import "atom/browser/mac/atom_application.h"
#include "atom/browser/mac/dict_util.h"
@ -24,7 +27,7 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
@end
@implementation OOMDisabledIMKInputSession
- (void)_coreAttributesFromRange:(NSRange)range
whichAttributes:(long long)attributes
whichAttributes:(long long)attributes // NOLINT(runtime/int)
completionHandler:(void (^)(void))block {
// The allocator flag is per-process, so other threads may temporarily
// not have fatal OOM occur while this method executes, but it is better

View file

@ -4,6 +4,10 @@
#include "atom/browser/mac/dict_util.h"
#include <memory>
#include <string>
#include <utility>
#include "base/json/json_writer.h"
#include "base/strings/sys_string_conversions.h"
#include "base/values.h"

View file

@ -4,6 +4,9 @@
#include "atom/browser/mac/in_app_purchase.h"
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h"

View file

@ -4,6 +4,8 @@
#include "atom/browser/mac/in_app_purchase_observer.h"
#include <vector>
#include "base/bind.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h"

View file

@ -4,6 +4,10 @@
#include "atom/browser/mac/in_app_purchase_product.h"
#include <string>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h"

View file

@ -4,6 +4,8 @@
#include "atom/browser/native_browser_view_mac.h"
#include <vector>
#include "atom/browser/ui/inspectable_web_contents.h"
#include "atom/browser/ui/inspectable_web_contents_view.h"
#include "skia/ext/skia_utils_mac.h"

View file

@ -8,6 +8,7 @@
#include <objc/objc-runtime.h>
#include <string>
#include <vector>
#include "atom/browser/native_browser_view_mac.h"
#include "atom/browser/ui/cocoa/atom_native_widget_mac.h"

View file

@ -4,6 +4,9 @@
#include "atom/browser/notifications/mac/cocoa_notification.h"
#include <string>
#include <utility>
#include "atom/browser/notifications/notification_delegate.h"
#include "atom/browser/notifications/notification_presenter.h"
#include "base/mac/mac_util.h"

View file

@ -4,6 +4,8 @@
#include "atom/browser/notifications/mac/notification_center_delegate.h"
#include <string>
#include "atom/browser/notifications/mac/cocoa_notification.h"
#include "atom/browser/notifications/mac/notification_presenter_mac.h"

View file

@ -4,6 +4,10 @@
#include "atom/browser/ui/certificate_trust.h"
#include <memory>
#include <string>
#include <utility>
#import <Cocoa/Cocoa.h>
#import <SecurityInterface/SFCertificateTrustPanel.h>

View file

@ -4,6 +4,8 @@
#import "atom/browser/ui/cocoa/atom_bundle_mover.h"
#include <string>
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <Security/Security.h>
@ -389,19 +391,14 @@ bool AtomBundleMover::Trash(NSString* path) {
// This allows us to trash the app in macOS Sierra even when the app is
// running inside an app translocation image.
if (!result) {
auto* code = R"str(
set theFile to POSIX file "%@"
tell application "Finder"
move theFile to trash
end tell
)str";
NSAppleScript* appleScript = [[[NSAppleScript alloc]
initWithSource:
[NSString
stringWithFormat:
@"\
set theFile to POSIX file \"%@\" "
@"\n\
tell application \"Finder\" "
@"\n\
move theFile to trash \n\
"
@" end tell",
path]] autorelease];
initWithSource:[NSString stringWithFormat:@(code), path]] autorelease];
NSDictionary* errorDict = nil;
NSAppleEventDescriptor* scriptResult =
[appleScript executeAndReturnError:&errorDict];
@ -425,4 +422,4 @@ bool AtomBundleMover::DeleteOrTrash(NSString* path) {
} // namespace ui
} // namespace atom
} // namespace atom

View file

@ -182,8 +182,8 @@ static base::scoped_nsobject<NSMenu> recentDocumentsMenuSwap_;
// Empties the source menu items to the destination.
- (void)moveMenuItems:(NSMenu*)source to:(NSMenu*)destination {
const long count = [source numberOfItems];
for (long index = 0; index < count; index++) {
const NSInteger count = [source numberOfItems];
for (NSInteger index = 0; index < count; index++) {
NSMenuItem* removedItem = [[[source itemAtIndex:0] retain] autorelease];
[source removeItemAtIndex:0];
[destination addItem:removedItem];

View file

@ -4,6 +4,8 @@
#include "atom/browser/ui/cocoa/atom_ns_window_delegate.h"
#include <algorithm>
#include "atom/browser/browser.h"
#include "atom/browser/native_window_mac.h"
#include "atom/browser/ui/cocoa/atom_preview_item.h"

View file

@ -4,6 +4,9 @@
#import "atom/browser/ui/cocoa/atom_touch_bar.h"
#include <string>
#include <vector>
#include "atom/common/color_util.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "base/strings/sys_string_conversions.h"

View file

@ -4,6 +4,8 @@
#import <Cocoa/Cocoa.h>
#include <vector>
#include "atom/browser/ui/drag_util.h"
#include "base/files/file_path.h"
#include "base/strings/sys_string_conversions.h"

View file

@ -4,6 +4,10 @@
#include "atom/browser/ui/file_dialog.h"
#include <string>
#include <utility>
#include <vector>
#import <Cocoa/Cocoa.h>
#import <CoreServices/CoreServices.h>

View file

@ -4,6 +4,10 @@
#include "atom/browser/ui/message_box.h"
#include <string>
#include <utility>
#include <vector>
#import <Cocoa/Cocoa.h>
#include "atom/browser/native_window.h"

View file

@ -4,6 +4,9 @@
#include "atom/browser/ui/tray_icon_cocoa.h"
#include <string>
#include <vector>
#include "atom/browser/ui/cocoa/NSString+ANSI.h"
#include "atom/browser/ui/cocoa/atom_menu_controller.h"
#include "base/strings/sys_string_conversions.h"

View file

@ -4,6 +4,9 @@
#include "atom/common/api/atom_api_native_image.h"
#include <string>
#include <vector>
#import <Cocoa/Cocoa.h>
#include "base/strings/sys_string_conversions.h"

View file

@ -4,6 +4,8 @@
#import "atom/common/application_info.h"
#include <string>
#import "atom/common/mac/main_application_bundle.h"
#import "base/mac/foundation_util.h"
#import "base/strings/sys_string_conversions.h"

View file

@ -4,7 +4,11 @@
#include "atom/common/crash_reporter/crash_reporter_mac.h"
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_util.h"
#include "base/mac/bundle_locations.h"

View file

@ -4,6 +4,9 @@
#include "atom/common/platform_util.h"
#include <string>
#include <utility>
#import <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
#import <ServiceManagement/ServiceManagement.h>

View file

@ -67,6 +67,7 @@
"lint:js": "node ./script/lint.js --js",
"lint:clang-format": "python script/run-clang-format.py -r -c atom/ chromium_src/ || (echo \"\\nCode not formatted correctly.\" && exit 1)",
"lint:cpp": "node ./script/lint.js --cc",
"lint:objc": "node ./script/lint.js --objc",
"lint:py": "node ./script/lint.js --py",
"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 && npm run lint:check-trailing-whitespace",

View file

@ -41,6 +41,21 @@ function spawnAndCheckExitCode (cmd, args, opts) {
if (status) process.exit(status)
}
function cpplint (args) {
const result = childProcess.spawnSync('cpplint.py', args, { encoding: 'utf8' })
// cpplint.py writes EVERYTHING to stderr, including status messages
if (result.stderr) {
for (const line of result.stderr.split(/[\r\n]+/)) {
if (line.length && !line.startsWith('Done processing ') && line !== 'Total errors found: 0') {
console.warn(line)
}
}
}
if (result.status) {
process.exit(result.status)
}
}
const LINTERS = [ {
key: 'c++',
roots: ['atom', 'native_mate'],
@ -51,18 +66,25 @@ const LINTERS = [ {
} else {
spawnAndCheckExitCode('python', ['script/run-clang-format.py', ...filenames])
}
const result = childProcess.spawnSync('cpplint.py', filenames, { encoding: 'utf8' })
// cpplint.py writes EVERYTHING to stderr, including status messages
if (result.stderr) {
for (const line of result.stderr.split(/[\r\n]+/)) {
if (line.length && !line.startsWith('Done processing ') && line !== 'Total errors found: 0') {
console.warn(line)
}
}
}
if (result.status) {
process.exit(result.status)
cpplint(filenames)
}
}, {
key: 'objc',
roots: ['atom'],
test: filename => filename.endsWith('.mm'),
run: (opts, filenames) => {
if (opts.fix) {
spawnAndCheckExitCode('python', ['script/run-clang-format.py', '--fix', ...filenames])
} else {
spawnAndCheckExitCode('python', ['script/run-clang-format.py', ...filenames])
}
const filter = [
'-readability/casting',
'-whitespace/braces',
'-whitespace/indent',
'-whitespace/parens'
]
cpplint(['--extensions=mm', `--filter=${filter.join(',')}`, ...filenames])
}
}, {
key: 'python',
@ -119,7 +141,7 @@ const LINTERS = [ {
function parseCommandLine () {
let help
const opts = minimist(process.argv.slice(2), {
boolean: [ 'c++', 'javascript', 'python', 'gn', 'help', 'changed', 'fix', 'verbose', 'only' ],
boolean: [ 'c++', 'objc', 'javascript', 'python', 'gn', 'help', 'changed', 'fix', 'verbose', 'only' ],
alias: { 'c++': ['cc', 'cpp', 'cxx'], javascript: ['js', 'es'], python: 'py', changed: 'c', help: 'h', verbose: 'v' },
unknown: arg => { help = true }
})