CodeQL documentation

Lines of code in files

ID: cs/lines-of-code-in-files
Kind: treemap
Severity: 
Precision: 
Tags:
   - maintainability
   - complexity

Click to see the query in the CodeQL repository

This metric measures the number of lines of code in each file. Files with a large number of lines can be difficult to understand. They can also cause problems with version control systems by increasing the likelihood that two developers work on the same file at once. A large number of lines of code in a single file can be an indication that the file suffers from poor code organization.

Recommendation

If the file has been automatically generated by a tool then it is generally best to leave it as it is, even if it is very long.

If the file contains multiple classes they should be moved into separate files, especially if they are unrelated.

If the file contains nested classes they could be put in separate files by turning the class they are contained in into a partial class.

If the main class in a file is too big then consideration should be given as to whether it can be refactored into smaller classes.

References

  • © GitHub, Inc.
  • Terms
  • Privacy