chore: fix clang-tidy warnings (#38079)

* chore: fix clang-tidy warnings

* refactor: avoid need for NOLINTNEXTLINE
This commit is contained in:
David Sanders 2023-04-26 07:09:54 -07:00 committed by GitHub
parent fe5cdd39d6
commit 08593fd2bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 41 additions and 37 deletions

4
.clang-tidy Normal file
View file

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

View file

@ -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

View file

@ -17,17 +17,21 @@ namespace electron::api {
gin::WrapperInfo SystemPreferences::kWrapperInfo = {gin::kEmbedderNativeGin};
#if BUILDFLAG(IS_WIN)
SystemPreferences::SystemPreferences() {
#if BUILDFLAG(IS_WIN)
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()

View file

@ -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;

View file

@ -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

View file

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

View file

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

View file

@ -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);
}
}

View file

@ -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) {}

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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;

View file

@ -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));
}
}

View file

@ -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);
}
}

View file

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

View file

@ -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);
}
}

View file

@ -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;
}

View file

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

View file

@ -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);