Skip to content

Commit

Permalink
Add QualifierAlignment to Clang Format Config (facebook#44098)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#44098

This sets `QualiferAlignment` so that code is automatically formatted to west const.

I did a pass at this before, but now that we are on new Clang Format, we can enforce it automatically, and I think a couple more cases not previously changed now are.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D56143678

fbshipit-source-id: 8f12b288476ea6019fd7d7a93a39b4fe2e75af14
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Apr 15, 2024
1 parent d53a2bd commit d1e8328
Show file tree
Hide file tree
Showing 55 changed files with 100 additions and 99 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
QualifierAlignment: Left
---
Language: ObjC
ColumnLimit: 120
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ - (instancetype)initWithConfiguration:(RCTRootViewFactoryConfiguration *)configu
{
if (self = [super init]) {
_configuration = configuration;
_contextContainer = std::make_shared<facebook::react::ContextContainer const>();
_reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
_contextContainer = std::make_shared<const facebook::react::ContextContainer>();
_reactNativeConfig = std::make_shared<const facebook::react::EmptyReactNativeConfig>();
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
_turboModuleManagerDelegate = turboModuleManagerDelegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ - (void)updateState:(const State::Shared &)state oldState:(const State::Shared &
{
RCTAssert(state, @"`state` must not be null.");
RCTAssert(
std::dynamic_pointer_cast<ImageShadowNode::ConcreteState const>(state),
std::dynamic_pointer_cast<const ImageShadowNode::ConcreteState>(state),
@"`state` must be a pointer to `ImageShadowNode::ConcreteState`.");

auto oldImageState = std::static_pointer_cast<ImageShadowNode::ConcreteState const>(_state);
auto newImageState = std::static_pointer_cast<ImageShadowNode::ConcreteState const>(state);
auto oldImageState = std::static_pointer_cast<const ImageShadowNode::ConcreteState>(_state);
auto newImageState = std::static_pointer_cast<const ImageShadowNode::ConcreteState>(state);

[self _setStateAndResubscribeImageResponseObserver:newImageState];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
- (void)updateState:(const facebook::react::State::Shared &)state
oldState:(const facebook::react::State::Shared &)oldState
{
_state = std::static_pointer_cast<InputAccessoryShadowNode::ConcreteState const>(state);
_state = std::static_pointer_cast<const InputAccessoryShadowNode::ConcreteState>(state);
CGSize oldScreenSize = RCTCGSizeFromSize(_state->getData().viewportSize);
CGSize viewportSize = RCTViewportSize();
viewportSize.height = std::nan("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState
{
_state = std::static_pointer_cast<LegacyViewManagerInteropShadowNode::ConcreteState const>(state);
_state = std::static_pointer_cast<const LegacyViewManagerInteropShadowNode::ConcreteState>(state);
}

- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
Expand All @@ -217,7 +217,7 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
if (weakSelf) {
__typeof(self) strongSelf = weakSelf;
const auto &eventEmitter =
static_cast<LegacyViewManagerInteropViewEventEmitter const &>(*strongSelf->_eventEmitter);
static_cast<const LegacyViewManagerInteropViewEventEmitter &>(*strongSelf->_eventEmitter);
eventEmitter.dispatchEvent(eventName, event);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (void)_updateStateIfNecessary

auto newData = oldData;
newData.padding = newPadding;
return std::make_shared<SafeAreaViewShadowNode::ConcreteState::Data const>(newData);
return std::make_shared<const SafeAreaViewShadowNode::ConcreteState::Data>(newData);
});
}

Expand All @@ -77,7 +77,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider
- (void)updateState:(const facebook::react::State::Shared &)state
oldState:(const facebook::react::State::Shared &)oldState
{
_state = std::static_pointer_cast<SafeAreaViewShadowNode::ConcreteState const>(state);
_state = std::static_pointer_cast<const SafeAreaViewShadowNode::ConcreteState>(state);
}

- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &

- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState
{
assert(std::dynamic_pointer_cast<ScrollViewShadowNode::ConcreteState const>(state));
_state = std::static_pointer_cast<ScrollViewShadowNode::ConcreteState const>(state);
assert(std::dynamic_pointer_cast<const ScrollViewShadowNode::ConcreteState>(state));
_state = std::static_pointer_cast<const ScrollViewShadowNode::ConcreteState>(state);
auto &data = _state->getData();

auto contentOffset = RCTCGPointFromPoint(data.contentOffset);
Expand Down Expand Up @@ -412,7 +412,7 @@ - (void)_updateStateWithContentOffset
_state->updateState([contentOffset](const ScrollViewShadowNode::ConcreteState::Data &data) {
auto newData = data;
newData.contentOffset = contentOffset;
return std::make_shared<ScrollViewShadowNode::ConcreteState::Data const>(newData);
return std::make_shared<const ScrollViewShadowNode::ConcreteState::Data>(newData);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &

- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState
{
_state = std::static_pointer_cast<ParagraphShadowNode::ConcreteState const>(state);
_state = std::static_pointer_cast<const ParagraphShadowNode::ConcreteState>(state);
[self setNeedsDisplay];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &

- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState
{
_state = std::static_pointer_cast<TextInputShadowNode::ConcreteState const>(state);
_state = std::static_pointer_cast<const TextInputShadowNode::ConcreteState>(state);

if (!_state) {
assert(false && "State is `null` for <TextInput> component.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
RCTAssert(
propsRawPtr &&
([self class] == [RCTViewComponentView class] ||
typeid(*propsRawPtr).hash_code() != typeid(ViewProps const).hash_code()),
typeid(*propsRawPtr).hash_code() != typeid(const ViewProps).hash_code()),
@"`RCTViewComponentView` subclasses (and `%@` particularly) must setup `_props`"
" instance variable with a default value in the constructor.",
NSStringFromClass([self class]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ - (BOOL)registerComponentIfPossible:(const std::string &)name
@"Legacy ViewManagers should be migrated to Fabric ComponentViews in the new architecture to reduce risk. Component using interop layer: %@",
componentNameString]);

auto flavor = std::make_shared<std::string const>(name);
auto flavor = std::make_shared<const std::string>(name);
auto componentName = ComponentName{flavor->c_str()};
auto componentHandle = reinterpret_cast<ComponentHandle>(componentName);
auto constructor = [RCTLegacyViewManagerInteropComponentView componentDescriptorProvider].constructor;
Expand All @@ -159,7 +159,7 @@ - (BOOL)registerComponentIfPossible:(const std::string &)name
}

// Fallback 4: use <UnimplementedView> if component doesn't exist.
auto flavor = std::make_shared<std::string const>(name);
auto flavor = std::make_shared<const std::string>(name);
auto componentName = ComponentName{flavor->c_str()};
auto componentHandle = reinterpret_cast<ComponentHandle>(componentName);
auto constructor = [RCTUnimplementedViewComponentView componentDescriptorProvider].constructor;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ - (RCTScheduler *)_createScheduler
toolbox.asynchronousEventBeatFactory =
[runtimeExecutor](const EventBeat::SharedOwnerBox &ownerBox) -> std::unique_ptr<EventBeat> {
auto runLoopObserver =
std::make_unique<MainRunLoopObserver const>(RunLoopObserver::Activity::BeforeWaiting, ownerBox->owner);
std::make_unique<const MainRunLoopObserver>(RunLoopObserver::Activity::BeforeWaiting, ownerBox->owner);
return std::make_unique<AsynchronousEventBeat>(std::move(runLoopObserver), runtimeExecutor);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ - (void)setUp
std::shared_ptr<ParagraphShadowNode> paragraphShadowNode)
{
auto sharedState =
std::static_pointer_cast<ParagraphShadowNode::ConcreteState const>(paragraphShadowNode->getState());
std::static_pointer_cast<const ParagraphShadowNode::ConcreteState>(paragraphShadowNode->getState());
return sharedState;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/cxxreact/MoveWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class MoveWrapper {

// If you want these you're probably doing it wrong, though they'd be
// easy enough to implement
MoveWrapper& operator=(MoveWrapper const&) = delete;
MoveWrapper& operator=(const MoveWrapper&) = delete;
MoveWrapper& operator=(MoveWrapper&&) = delete;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct DummySystraceSection {
public:
template <typename... ConvertsToStringPiece>
explicit DummySystraceSection(
__unused const char* name,
const __unused char* name,
__unused ConvertsToStringPiece&&... args) {}
};
using SystraceSection = DummySystraceSection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::string as_string(folly::dynamic value) {
}

std::string explain_error(
folly::dynamic::json_pointer_resolution_error<folly::dynamic const> error) {
folly::dynamic::json_pointer_resolution_error<const folly::dynamic> error) {
using err_code = folly::dynamic::json_pointer_resolution_error_code;

switch (error.error_code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace folly_dynamic_matchers_utils {
std::string as_string(std::string value);
std::string as_string(folly::dynamic value);
std::string explain_error(
folly::dynamic::json_pointer_resolution_error<folly::dynamic const> error);
folly::dynamic::json_pointer_resolution_error<const folly::dynamic> error);

} // namespace folly_dynamic_matchers_utils

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ComponentDescriptorProviderRegistry final {
mutable std::shared_mutex mutex_;
mutable std::vector<std::weak_ptr<const ComponentDescriptorRegistry>>
componentDescriptorRegistries_;
mutable std::unordered_map<ComponentHandle, ComponentDescriptorProvider const>
mutable std::unordered_map<ComponentHandle, const ComponentDescriptorProvider>
componentDescriptorProviders_;
mutable ComponentDescriptorProviderRequest
componentDescriptorProviderRequest_{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static Class getViewManagerClass(const std::string &componentName, RCTBridge *br
bridgeProxy = unwrapManagedObjectWeakly(optionalBridgeProxy.value());
}

auto componentName = *std::static_pointer_cast<std::string const>(flavor);
auto componentName = *std::static_pointer_cast<const std::string>(flavor);
Class viewManagerClass = getViewManagerClass(componentName, bridge, bridgeProxy);
assert(viewManagerClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LegacyViewManagerInteropViewProps final : public ViewProps {

#pragma mark - Props

folly::dynamic const otherProps;
const folly::dynamic otherProps;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ParagraphShadowNode final : public ConcreteViewShadowNode<
*/
void updateStateIfNeeded(const Content& content);

std::shared_ptr<TextLayoutManager const> textLayoutManager_;
std::shared_ptr<const TextLayoutManager> textLayoutManager_;

/*
* Cached content of the subtree started from the node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class ParagraphState final {
* This is not on every platform. This is not used on Android, but is
* used on the iOS mounting layer.
*/
std::weak_ptr<TextLayoutManager const> layoutManager;
std::weak_ptr<const TextLayoutManager> layoutManager;

#ifdef ANDROID
ParagraphState(
AttributedString const& attributedString,
ParagraphAttributes const& paragraphAttributes,
std::weak_ptr<const TextLayoutManager> const& layoutManager)
const AttributedString& attributedString,
const ParagraphAttributes& paragraphAttributes,
const std::weak_ptr<const TextLayoutManager>& layoutManager)
: attributedString(attributedString),
paragraphAttributes(paragraphAttributes),
layoutManager(layoutManager) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TextInputProps final : public BaseTextInputProps {
*/
std::optional<Selection> selection{};

std::string const inputAccessoryViewID{};
const std::string inputAccessoryViewID{};

bool onKeyPressSync{false};
bool onChangeSync{false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ BorderMetrics BaseViewProps::resolveBorderMetrics(
}

Transform BaseViewProps::resolveTransform(
LayoutMetrics const& layoutMetrics) const {
const LayoutMetrics& layoutMetrics) const {
float viewWidth = layoutMetrics.frame.size.width;
float viewHeight = layoutMetrics.frame.size.height;
if (!transformOrigin.isSet() || (viewWidth == 0 && viewHeight == 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ TEST_F(YogaDirtyFlagTest, removingLastChildMustDirtyYogaNode) {

return oldShadowNode.clone(
{ShadowNodeFragment::propsPlaceholder(),
std::make_shared<ShadowNode::ListOfShared const>(children)});
std::make_shared<const ShadowNode::ListOfShared>(children)});
});

EXPECT_TRUE(
Expand All @@ -193,7 +193,7 @@ TEST_F(YogaDirtyFlagTest, reversingListOfChildrenMustDirtyYogaNode) {

return oldShadowNode.clone(
{ShadowNodeFragment::propsPlaceholder(),
std::make_shared<ShadowNode::ListOfShared const>(children)});
std::make_shared<const ShadowNode::ListOfShared>(children)});
});

EXPECT_TRUE(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ConcreteState : public State {
*/
void updateState(Data&& newData) const {
updateState([data{std::move(newData)}](const Data& oldData) -> SharedData {
return std::make_shared<Data const>(data);
return std::make_shared<const Data>(data);
});
}

Expand All @@ -85,7 +85,7 @@ class ConcreteState : public State {
auto stateUpdate = StateUpdate{
family, [=](const StateData::Shared& oldData) -> StateData::Shared {
react_native_assert(oldData);
return callback(*static_cast<Data const*>(oldData.get()));
return callback(*static_cast<const Data*>(oldData.get()));
}};

family->dispatchRawState(std::move(stateUpdate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ template <class T>
using LayoutableSmallVector = std::vector<T>;

static LayoutableSmallVector<Rect> calculateTransformedFrames(
const LayoutableSmallVector<ShadowNode const*>& shadowNodeList,
const LayoutableSmallVector<const ShadowNode*>& shadowNodeList,
LayoutableShadowNode::LayoutInspectingPolicy policy) {
auto size = shadowNodeList.size();
auto transformedFrames = LayoutableSmallVector<Rect>{size};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const RawValue* RawProps::at(

void RawProps::iterateOverValues(
const std::function<
void(RawPropsPropNameHash, const char*, RawValue const&)>& fn) const {
void(RawPropsPropNameHash, const char*, const RawValue&)>& fn) const {
return parser_->iterateOverValues(*this, fn);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class RawProps final {
*/
void iterateOverValues(
const std::function<
void(RawPropsPropNameHash, const char*, RawValue const&)>& fn) const;
void(RawPropsPropNameHash, const char*, const RawValue&)>& fn) const;

private:
friend class RawPropsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void RawPropsParser::preparse(const RawProps& rawProps) const noexcept {
void RawPropsParser::iterateOverValues(
const RawProps& rawProps,
const std::function<
void(RawPropsPropNameHash, const char*, RawValue const&)>& visit)
void(RawPropsPropNameHash, const char*, const RawValue&)>& visit)
const {
switch (rawProps.mode_) {
case RawProps::Mode::Empty:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class RawPropsParser final {
void iterateOverValues(
const RawProps& rawProps,
const std::function<
void(RawPropsPropNameHash, const char*, RawValue const&)>& visit)
void(RawPropsPropNameHash, const char*, const RawValue&)>& visit)
const;

mutable std::vector<RawPropsKey> keys_{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ const ShadowNodeFamily& ShadowNode::getFamily() const {

ShadowNode::Unshared ShadowNode::cloneTree(
const ShadowNodeFamily& shadowNodeFamily,
const std::function<ShadowNode::Unshared(ShadowNode const& oldShadowNode)>&
const std::function<ShadowNode::Unshared(const ShadowNode& oldShadowNode)>&
callback,
ShadowNodeTraits traits) const {
auto ancestors = shadowNodeFamily.getAncestors(*this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ShadowNode : public Sealable,
*/
Unshared cloneTree(
const ShadowNodeFamily& shadowNodeFamily,
const std::function<Unshared(ShadowNode const& oldShadowNode)>& callback,
const std::function<Unshared(const ShadowNode& oldShadowNode)>& callback,
ShadowNodeTraits traits = {}) const;

#pragma mark - Getters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ShadowNodeFamily final {
* Sets and gets the most recent state.
*/
std::shared_ptr<const State> getMostRecentState() const;
void setMostRecentState(const std::shared_ptr<State const>& state) const;
void setMostRecentState(const std::shared_ptr<const State>& state) const;

/*
* Dispatches a state update with given priority.
Expand Down Expand Up @@ -134,7 +134,7 @@ class ShadowNodeFamily final {
/*
* Weak reference to the React instance handle
*/
InstanceHandle::Shared const instanceHandle_;
const InstanceHandle::Shared instanceHandle_;

/*
* `EventEmitter` associated with all nodes of the family.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ T convertRawProp(
const PropsParserContext& context,
const RawProps& rawProps,
const char* name,
T const& sourceValue,
U const& defaultValue,
const T& sourceValue,
const U& defaultValue,
const char* namePrefix = nullptr,
const char* nameSuffix = nullptr) {
const auto* rawValue = rawProps.at(name, namePrefix, nameSuffix);
Expand Down
Loading

0 comments on commit d1e8328

Please sign in to comment.