[PATCH] D86671: [clang-tidy] Add new case type to check variables with Hungarian notation

Douglas Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 20:17:23 PDT 2020


dougpuob added a comment.

In D86671#2304337 <https://reviews.llvm.org/D86671#2304337>, @njames93 wrote:

> Not strictly relevant here, but this does open up the idea of enforcing the style where an enum constant is prefixed by the initials of the enum name.

I like this idea. There is a case when `EnumConstantPrefix` and `EnumConstantCase=szHungarianNotation` options are set, it may take similar affect(which will be the first) or be overwritten? I can have it a try later.

Showing my conception as the following:

  // [Before]
  typedef enum {
      RevValid             = -1,
      RevNone              = 0, 
      RevCrlReason         = 1, 
      RevHold              = 2, 
      RevKeyCompromise     = 3, 
      RevCaCompromise      = 4  
  } REVINFO_TYPE;
  
  // [After]
  typedef enum {
      rtRevValid             = -1
      rtRevNone              = 0,
      rtRevCrlReason         = 1,
      rtRevHold              = 2,
      rtRevKeyCompromise     = 3,
      rtRevCaCompromise      = 4 
  } REVINFO_TYPE;
  
  // [After] EnumConstantPrefix first case
  // EnumConstantCase=snHungarianNotation
  // EnumConstantPrefix=pre_
  typedef enum {
      pre_rtRevValid             = -1
      pre_rtRevNone              = 0,
      pre_rtRevCrlReason         = 1,
      pre_rtRevHold              = 2,
      pre_rtRevKeyCompromise     = 3,
      pre_rtRevCaCompromise      = 4 
  } REVINFO_TYPE;



================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp:25
+// RUN:     {key: readability-identifier-naming.FunctionCase       , value: CamelCase },           \
+// RUN:     {key: readability-identifier-naming.ClassCase          , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.TypedefCase        , value: szHungarianNotation }, \
----------------
njames93 wrote:
> Class names shouldn't use hungarian notation.
OK~ I have classified CheckOptions, and all test cases one by one in the next diff.

```
// RUN:   -config='{ CheckOptions: [ \
// RUN:     { key: readability-identifier-naming.ClassMemberCase              , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.ConstantCase                 , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.ConstantMemberCase           , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.ConstantParameterCase        , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.ConstantPointerParameterCase , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.ConstexprVariableCase        , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.GlobalConstantCase           , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.GlobalConstantPointerCase    , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.GlobalVariableCase           , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.LocalConstantCase            , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.LocalConstantPointerCase     , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.LocalPointerCase             , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.LocalVariableCase            , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.MemberCase                   , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.ParameterCase                , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.PointerParameterCase         , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.PrivateMemberCase            , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.StaticConstantCase           , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.StaticVariableCase           , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.StructCase                   , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.UnionCase                    , value: szHungarianNotation }, \
// RUN:     { key: readability-identifier-naming.VariableCase                 , value: szHungarianNotation }  \
// RUN:   ]}'
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86671/new/

https://reviews.llvm.org/D86671



More information about the cfe-commits mailing list