Browse Source

Use lines instead of statements for readability-function-size clang-tidy (#6594)

Geoff Romer 3 months ago
parent
commit
9106f9533c

+ 9 - 0
.clang-tidy

@@ -143,3 +143,12 @@ CheckOptions:
   # Don't require writing a return type on lambdas.
   - key: modernize-use-trailing-return-type.TransformLambdas
     value: none
+
+  # Use lines rather than statements to measure function size, because
+  # for readability purposes we care about the code as written, before
+  # preprocessing.
+  - key: readability-function-size.StatementThreshold
+    value: none
+  - key: readability-function-size.LineThreshold
+    # Chose 800 to match the default for StatementThreshold.
+    value: 800

+ 0 - 1
toolchain/check/check_unit.cpp

@@ -374,7 +374,6 @@ auto CheckUnit::ImportOtherPackages(SemIR::TypeId namespace_type_id) -> void {
 
 // Loops over all nodes in the tree. On some errors, this may return early,
 // for example if an unrecoverable state is encountered.
-// NOLINTNEXTLINE(readability-function-size)
 auto CheckUnit::ProcessNodeIds() -> bool {
   NodeIdTraversal traversal(&context_);
 

+ 0 - 1
toolchain/check/check_unit.h

@@ -185,7 +185,6 @@ class CheckUnit {
 
   // Loops over all nodes in the tree. On some errors, this may return early,
   // for example if an unrecoverable state is encountered.
-  // NOLINTNEXTLINE(readability-function-size)
   auto ProcessNodeIds() -> bool;
 
   UnitAndImports* unit_and_imports_;

+ 0 - 1
toolchain/check/node_stack.cpp

@@ -37,7 +37,6 @@ auto NodeStack::PrintForStackDump(int indent, llvm::raw_ostream& output) const
   }
 }
 
-// NOLINTNEXTLINE(readability-function-size)
 auto NodeStack::CheckIdKindTable() -> void {
 #define CARBON_PARSE_NODE_KIND(Name)                                     \
   {                                                                      \

+ 0 - 1
toolchain/lower/constant.cpp

@@ -325,7 +325,6 @@ static auto MaybeEmitAsConstant(ConstantContext& context, InstT inst)
   }
 }
 
-// NOLINTNEXTLINE(readability-function-size): Macro-generated.
 auto LowerConstants(FileContext& file_context,
                     FileContext::LoweredConstantStore& constants) -> void {
   ConstantContext context(file_context, &constants);

+ 0 - 1
toolchain/lower/function_context.cpp

@@ -113,7 +113,6 @@ static auto LowerInstHelper(FunctionContext& context, SemIR::InstId inst_id,
 // TODO: Consider renaming Handle##Name, instead relying on typed_inst overload
 // resolution. That would allow putting the nonexistent handler implementations
 // in `requires`-style overloads.
-// NOLINTNEXTLINE(readability-function-size): The define confuses lint.
 auto FunctionContext::LowerInst(SemIR::InstId inst_id) -> void {
   // Skip over constants. `FileContext::GetConstant` lowers them as needed.
   if (sem_ir().constant_values().Get(inst_id).is_constant()) {

+ 0 - 2
toolchain/sem_ir/expr_info.cpp

@@ -22,7 +22,6 @@ static auto AsAnyInstId(Inst::ArgAndKind arg) -> InstId {
   return arg.As<SemIR::AbsoluteInstId>();
 }
 
-// NOLINTBEGIN(readability-function-size)
 auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory {
   const File* ir = &file;
 
@@ -137,7 +136,6 @@ auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory {
     }
   }
 }
-// NOLINTEND(readability-function-size)
 
 auto FindReturnSlotArgForInitializer(const File& sem_ir, InstId init_id)
     -> InstId {

+ 0 - 1
toolchain/sem_ir/stringify.cpp

@@ -734,7 +734,6 @@ class Stringifier {
 
 }  // namespace
 
-// NOLINTNEXTLINE(readability-function-size)
 static auto Stringify(const File& sem_ir, StepStack& step_stack)
     -> std::string {
   RawStringOstream out;