RFC Coding Guidelines: Formatting Class Member Declarations | Haiku Project

I have tried playing around with the configuration a bit more, and I found AlignConsecutiveDeclarations. If this is enabled, the BHandler example for the article is reformatted as follows:

class BHandler : public BArchivable
{
public:
	BHandler(const char* name = NULL);
	virtual ~BHandler();

	// BHandler guts.
	virtual void MessageReceived(BMessage* message);
	BLooper*	 Looper() const;
	const char*	 Name() const;

	// Fictional very long member function declaration
	status_t	 Launch(const entry_ref* ref, const BMessage* initialMessage = NULL,
			team_id* _appTeam = NULL) const volatile noexcept;

private:
	typedef BArchivable _inherited;
	friend inline int32 _get_object_token_(const BHandler*);
	friend class BLooper;

	int32 fToken;
	char* fName;
};

Observations from this example and after running it on Window.h:

  • The constructor and destructor do not have return types and are thus not aligned with other members
  • With the configuration as given, each block demarcated by public, protected or private will have it’s own alignment calculations.
  • The style is very similar to what we have right now, and we can describe the rules so that the formatting can be applied manually and automatically.
  • Running it over Window.h gives some strange results (i.e. suddenly a new block starts and the alignment changes without any reason), but that must be a bug so that can be fixed.

The style can be manually applied by adding a style instruction to haiku-format like:

 haiku-format -style="{BasedOnStyle: Haiku, AlignConsecutiveDeclarations: {Enabled: true, AcrossEmptyLines: true, AcrossComments: true}} FILENAME"
1 Like