Skip to content

Commit

Permalink
chore: fix clang-tidy warnings (electron#38079)
Browse files Browse the repository at this point in the history
* chore: fix clang-tidy warnings

* refactor: avoid need for NOLINTNEXTLINE
  • Loading branch information
dsanders11 authored Apr 26, 2023
1 parent fe5cdd3 commit 08593fd
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Checks: '-modernize-use-nullptr'
InheritParentConfig: true
...
7 changes: 3 additions & 4 deletions shell/browser/api/electron_api_desktop_capturer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_));
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions shell/browser/api/electron_api_system_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions shell/browser/api/electron_api_system_preferences_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ AVMediaType ParseMediaType(const std::string& media_type) {
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]);
Expand All @@ -470,6 +471,7 @@ AVMediaType ParseMediaType(const std::string& media_type) {
gin_helper::Promise<void>::ResolvePromise,
std::move(p)));
}
// NOLINTEND(bugprone-use-after-move)
}];

return handle;
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_utility_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/gpu_info_enumerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace electron {

GPUInfoEnumerator::GPUInfoEnumerator() : value_stack_(), current_{} {}
GPUInfoEnumerator::GPUInfoEnumerator() = default;

GPUInfoEnumerator::~GPUInfoEnumerator() = default;

Expand Down
2 changes: 1 addition & 1 deletion shell/browser/bluetooth/electron_bluetooth_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::string ElectronBluetoothDelegate::GetDeviceAddress(
RenderFrameHost* frame,
const WebBluetoothDeviceId& device_id) {
NOTIMPLEMENTED();
return nullptr;
return "";
}

WebBluetoothDeviceId ElectronBluetoothDelegate::AddScannedDevice(
Expand Down
10 changes: 5 additions & 5 deletions shell/browser/electron_permission_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 0 additions & 2 deletions shell/browser/file_select_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
4 changes: 1 addition & 3 deletions shell/browser/font_defaults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/linux/unity_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions shell/browser/net/asar/asar_url_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions shell/browser/ui/file_dialog_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/ui/file_dialog_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/ui/webui/accessibility_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion shell/browser/usb/usb_chooser_context_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ UsbChooserContextFactory::UsbChooserContextFactory()
"UsbChooserContext",
BrowserContextDependencyManager::GetInstance()) {}

UsbChooserContextFactory::~UsbChooserContextFactory() {}
UsbChooserContextFactory::~UsbChooserContextFactory() = default;

KeyedService* UsbChooserContextFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Expand Down
8 changes: 4 additions & 4 deletions shell/browser/usb/usb_chooser_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ UsbChooserController::UsbChooserController(
}

UsbChooserController::~UsbChooserController() {
RunCallback(/*device=*/nullptr);
RunCallback(/*device_info=*/nullptr);
}

api::Session* UsbChooserController::GetSession() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ void UsbChooserController::GotUsbDeviceList(
weak_factory_.GetWeakPtr())));
}
if (!prevent_default) {
RunCallback(/*port=*/nullptr);
RunCallback(/*device_info=*/nullptr);
}
}

Expand Down
4 changes: 2 additions & 2 deletions shell/common/gin_helper/trackable_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion shell/common/platform_util_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ShowItemHelper {
return *instance;
}

ShowItemHelper() {}
ShowItemHelper() = default;

ShowItemHelper(const ShowItemHelper&) = delete;
ShowItemHelper& operator=(const ShowItemHelper&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion shell/renderer/electron_autofill_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 08593fd

Please sign in to comment.