CodeQL documentation

Lines of code in files

ID: py/lines-of-code-in-files
Kind: treemap
Severity: 
Precision: very-high
Tags:
   - maintainability

Click to see the query in the CodeQL repository

This metric measures the number of lines of code in each file. The value excludes docstrings, comments and blank lines.

Organizing source into very large files is not recommended because:

  • it can be difficult to understand and maintain the code, even with good support from development tools

  • it increases the risk that multiple developers will work on the same file at once, and increases the incidence of merge conflicts

  • it may be a symptom of weak code organization, where many different features are handled by functions in a single file.

Recommendation

The solution depends on the underlying cause:

  • if individual classes or functions are too large then they should be refactored into smaller modules

  • if the class contains many classes or functions, they should be moved to their own modules (sometimes in a subsidiary module, where appropriate)

  • if the file has been automatically generated by a tool, then it should be left alone.

References