Browse Source

chore: fix clang-tidy warnings (#38079)

* chore: fix clang-tidy warnings

* refactor: avoid need for NOLINTNEXTLINE
David Sanders 2 years ago
parent
commit
08593fd2bd

+ 4 - 0
.clang-tidy

@@ -0,0 +1,4 @@
+---
+Checks: '-modernize-use-nullptr'
+InheritParentConfig: true
+...

+ 3 - 4
shell/browser/api/electron_api_desktop_capturer.cc

@@ -243,8 +243,8 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
     std::vector<DesktopCapturer::Source> window_sources;
     window_sources.reserve(list->GetSourceCount());
     for (int i = 0; i < list->GetSourceCount(); i++) {
-      window_sources.emplace_back(DesktopCapturer::Source{
-          list->GetSource(i), std::string(), fetch_window_icons_});
+      window_sources.emplace_back(list->GetSource(i), std::string(),
+                                  fetch_window_icons_);
     }
     std::move(window_sources.begin(), window_sources.end(),
               std::back_inserter(captured_sources_));
@@ -256,8 +256,7 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
     std::vector<DesktopCapturer::Source> screen_sources;
     screen_sources.reserve(list->GetSourceCount());
     for (int i = 0; i < list->GetSourceCount(); i++) {
-      screen_sources.emplace_back(
-          DesktopCapturer::Source{list->GetSource(i), std::string()});
+      screen_sources.emplace_back(list->GetSource(i), std::string());
     }
 #if BUILDFLAG(IS_WIN)
     // Gather the same unique screen IDs used by the electron.screen API in

+ 8 - 4
shell/browser/api/electron_api_system_preferences.cc

@@ -17,17 +17,21 @@ namespace electron::api {
 
 gin::WrapperInfo SystemPreferences::kWrapperInfo = {gin::kEmbedderNativeGin};
 
-SystemPreferences::SystemPreferences() {
 #if BUILDFLAG(IS_WIN)
+SystemPreferences::SystemPreferences() {
   InitializeWindow();
-#endif
 }
+#else
+SystemPreferences::SystemPreferences() = default;
+#endif
 
-SystemPreferences::~SystemPreferences() {
 #if BUILDFLAG(IS_WIN)
+SystemPreferences::~SystemPreferences() {
   Browser::Get()->RemoveObserver(this);
-#endif
 }
+#else
+SystemPreferences::~SystemPreferences() = default;
+#endif
 
 bool SystemPreferences::IsInvertedColorScheme() {
   return ui::NativeTheme::GetInstanceForNativeUi()

+ 2 - 0
shell/browser/api/electron_api_system_preferences_mac.mm

@@ -455,6 +455,7 @@ v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
                   operation:LAAccessControlOperationUseKeySign
             localizedReason:[NSString stringWithUTF8String:reason.c_str()]
                       reply:^(BOOL success, NSError* error) {
+                        // NOLINTBEGIN(bugprone-use-after-move)
                         if (!success) {
                           std::string err_msg = std::string(
                               [error.localizedDescription UTF8String]);
@@ -470,6 +471,7 @@ v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
                                   gin_helper::Promise<void>::ResolvePromise,
                                   std::move(p)));
                         }
+                        // NOLINTEND(bugprone-use-after-move)
                       }];
 
   return handle;

+ 1 - 1
shell/browser/api/electron_api_utility_process.cc

@@ -279,7 +279,7 @@ void UtilityProcessWrapper::PostMessage(gin::Arguments* args) {
 
 bool UtilityProcessWrapper::Kill() const {
   if (pid_ == base::kNullProcessId)
-    return 0;
+    return false;
   base::Process process = base::Process::Open(pid_);
   bool result = process.Terminate(content::RESULT_CODE_NORMAL_EXIT, false);
   // Refs https://bugs.chromium.org/p/chromium/issues/detail?id=818244

+ 1 - 1
shell/browser/api/gpu_info_enumerator.cc

@@ -8,7 +8,7 @@
 
 namespace electron {
 
-GPUInfoEnumerator::GPUInfoEnumerator() : value_stack_(), current_{} {}
+GPUInfoEnumerator::GPUInfoEnumerator() = default;
 
 GPUInfoEnumerator::~GPUInfoEnumerator() = default;
 

+ 1 - 1
shell/browser/bluetooth/electron_bluetooth_delegate.cc

@@ -84,7 +84,7 @@ std::string ElectronBluetoothDelegate::GetDeviceAddress(
     RenderFrameHost* frame,
     const WebBluetoothDeviceId& device_id) {
   NOTIMPLEMENTED();
-  return nullptr;
+  return "";
 }
 
 WebBluetoothDeviceId ElectronBluetoothDelegate::AddScannedDevice(

+ 5 - 5
shell/browser/electron_permission_manager.cc

@@ -203,16 +203,16 @@ void ElectronPermissionManager::RequestPermissionsWithDetails(
   int request_id = pending_requests_.Add(std::make_unique<PendingRequest>(
       render_frame_host, permissions, std::move(response_callback)));
 
+  details.Set("requestingUrl", render_frame_host->GetLastCommittedURL().spec());
+  details.Set("isMainFrame", render_frame_host->GetParent() == nullptr);
+  base::Value dict_value(std::move(details));
+
   for (size_t i = 0; i < permissions.size(); ++i) {
     auto permission = permissions[i];
     const auto callback =
         base::BindRepeating(&ElectronPermissionManager::OnPermissionResponse,
                             base::Unretained(this), request_id, i);
-    details.Set("requestingUrl",
-                render_frame_host->GetLastCommittedURL().spec());
-    details.Set("isMainFrame", render_frame_host->GetParent() == nullptr);
-    request_handler_.Run(web_contents, permission, callback,
-                         base::Value(std::move(details)));
+    request_handler_.Run(web_contents, permission, callback, dict_value);
   }
 }
 

+ 0 - 2
shell/browser/file_select_helper.cc

@@ -71,8 +71,6 @@ struct FileSelectHelper::ActiveDirectoryEnumeration {
 FileSelectHelper::FileSelectHelper()
     : render_frame_host_(nullptr),
       web_contents_(nullptr),
-      select_file_dialog_(),
-      select_file_types_(),
       dialog_type_(ui::SelectFileDialog::SELECT_OPEN_FILE),
       dialog_mode_(FileChooserParams::Mode::kOpen) {}
 

+ 1 - 3
shell/browser/font_defaults.cc

@@ -103,13 +103,11 @@ const FontDefault kFontDefaults[] = {
      IDS_FIXED_FONT_FAMILY_TRADITIONAL_HAN},
 #endif
 };
-const size_t kFontDefaultsLength = std::size(kFontDefaults);
 
 // ^^^^^ DO NOT EDIT ^^^^^
 
 std::string GetDefaultFontForPref(const char* pref_name) {
-  for (size_t i = 0; i < kFontDefaultsLength; ++i) {
-    FontDefault pref = kFontDefaults[i];
+  for (auto pref : kFontDefaults) {
     if (strcmp(pref.pref_name, pref_name) == 0) {
       return l10n_util::GetStringUTF8(pref.resource_id);
     }

+ 1 - 1
shell/browser/linux/unity_service.cc

@@ -15,7 +15,7 @@
 
 // Unity data typedefs.
 typedef struct _UnityInspector UnityInspector;
-typedef UnityInspector* (*unity_inspector_get_default_func)(void);
+typedef UnityInspector* (*unity_inspector_get_default_func)();
 typedef gboolean (*unity_inspector_get_unity_running_func)(
     UnityInspector* self);
 

+ 2 - 2
shell/browser/net/asar/asar_url_loader.cc

@@ -166,8 +166,8 @@ class AsarURLLoader : public network::mojom::URLLoader {
       auto asar_validator = std::make_unique<AsarFileValidator>(
           std::move(info.integrity.value()), std::move(file));
       file_validator_raw = asar_validator.get();
-      readable_data_source.reset(new mojo::FilteredDataSource(
-          std::move(file_data_source), std::move(asar_validator)));
+      readable_data_source = std::make_unique<mojo::FilteredDataSource>(
+          std::move(file_data_source), std::move(asar_validator));
     } else {
       readable_data_source = std::move(file_data_source);
     }

+ 1 - 2
shell/browser/ui/file_dialog_gtk.cc

@@ -36,8 +36,7 @@ std::string MakeCaseInsensitivePattern(const std::string& extension) {
     return extension;
 
   std::string pattern("*.");
-  for (std::size_t i = 0, n = extension.size(); i < n; i++) {
-    char ch = extension[i];
+  for (char ch : extension) {
     if (!base::IsAsciiAlpha(ch)) {
       pattern.push_back(ch);
       continue;

+ 1 - 1
shell/browser/ui/file_dialog_mac.mm

@@ -283,7 +283,7 @@ void ReadDialogPathsWithBookmarks(NSOpenPanel* dialog,
   NSArray* urls = [dialog URLs];
   for (NSURL* url in urls)
     if ([url isFileURL]) {
-      paths->push_back(base::FilePath(base::SysNSStringToUTF8([url path])));
+      paths->emplace_back(base::SysNSStringToUTF8([url path]));
       bookmarks->push_back(GetBookmarkDataFromNSURL(url));
     }
 }

+ 1 - 1
shell/browser/ui/webui/accessibility_ui.cc

@@ -152,7 +152,7 @@ void AddPropertyFilters(std::vector<ui::AXPropertyFilter>* property_filters,
                         ui::AXPropertyFilter::Type type) {
   for (const std::string& attribute : base::SplitString(
            attributes, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
-    property_filters->push_back(ui::AXPropertyFilter(attribute, type));
+    property_filters->emplace_back(attribute, type);
   }
 }
 

+ 1 - 1
shell/browser/usb/usb_chooser_context_factory.cc

@@ -15,7 +15,7 @@ UsbChooserContextFactory::UsbChooserContextFactory()
           "UsbChooserContext",
           BrowserContextDependencyManager::GetInstance()) {}
 
-UsbChooserContextFactory::~UsbChooserContextFactory() {}
+UsbChooserContextFactory::~UsbChooserContextFactory() = default;
 
 KeyedService* UsbChooserContextFactory::BuildServiceInstanceFor(
     content::BrowserContext* context) const {

+ 4 - 4
shell/browser/usb/usb_chooser_controller.cc

@@ -54,7 +54,7 @@ UsbChooserController::UsbChooserController(
 }
 
 UsbChooserController::~UsbChooserController() {
-  RunCallback(/*device=*/nullptr);
+  RunCallback(/*device_info=*/nullptr);
 }
 
 api::Session* UsbChooserController::GetSession() {
@@ -85,7 +85,7 @@ void UsbChooserController::OnDeviceRemoved(
 void UsbChooserController::OnDeviceChosen(gin::Arguments* args) {
   std::string device_id;
   if (!args->GetNext(&device_id) || device_id.empty()) {
-    RunCallback(/*device=*/nullptr);
+    RunCallback(/*device_info=*/nullptr);
   } else {
     auto* device_info = chooser_context_->GetDeviceInfo(device_id);
     if (device_info) {
@@ -95,7 +95,7 @@ void UsbChooserController::OnDeviceChosen(gin::Arguments* args) {
       node::Environment* env = node::Environment::GetCurrent(isolate);
       EmitWarning(env, "The device id " + device_id + " was not found.",
                   "UnknownUsbDeviceId");
-      RunCallback(/*device=*/nullptr);
+      RunCallback(/*device_info=*/nullptr);
     }
   }
 }
@@ -131,7 +131,7 @@ void UsbChooserController::GotUsbDeviceList(
                                          weak_factory_.GetWeakPtr())));
   }
   if (!prevent_default) {
-    RunCallback(/*port=*/nullptr);
+    RunCallback(/*device_info=*/nullptr);
   }
 }
 

+ 2 - 2
shell/common/gin_helper/trackable_object.cc

@@ -21,7 +21,7 @@ class IDUserData : public base::SupportsUserData::Data {
  public:
   explicit IDUserData(int32_t id) : id_(id) {}
 
-  operator int32_t() const { return id_; }
+  explicit operator int32_t() const { return id_; }
 
  private:
   int32_t id_;
@@ -58,7 +58,7 @@ int32_t TrackableObjectBase::GetIDFromWrappedClass(
     auto* id =
         static_cast<IDUserData*>(wrapped->GetUserData(kTrackedObjectKey));
     if (id)
-      return *id;
+      return int32_t(*id);
   }
   return 0;
 }

+ 1 - 1
shell/common/platform_util_linux.cc

@@ -61,7 +61,7 @@ class ShowItemHelper {
     return *instance;
   }
 
-  ShowItemHelper() {}
+  ShowItemHelper() = default;
 
   ShowItemHelper(const ShowItemHelper&) = delete;
   ShowItemHelper& operator=(const ShowItemHelper&) = delete;

+ 1 - 1
shell/renderer/electron_autofill_agent.cc

@@ -46,7 +46,7 @@ void GetDataListSuggestions(const blink::WebInputElement& element,
     if (option.Value() != option.Label())
       labels->push_back(option.Label().Utf16());
     else
-      labels->push_back(std::u16string());
+      labels->emplace_back();
   }
 
   TrimStringVectorForIPC(values);