Fortran-FOSS-Programmers / ford

Automatically generates FORtran Documentation from comments within the code.
https://forddocs.readthedocs.io
GNU General Public License v3.0
402 stars 131 forks source link

Fix bug with `hide_undoc = True` #651

Closed thundermoose closed 1 month ago

thundermoose commented 1 month ago

The hide_undoc flag didn't work correctly. When running FORD on a project with the hide_undoc flag set to true, FORD crashes with the following traceback:

Traceback (most recent call last):
  File "/home/thundermoose/ExternalGits/ford/ford.py", line 7, in <module>
    run()
  File "/home/thundermoose/ExternalGits/ford/ford/__init__.py", line 489, in run
    main(proj_data, proj_docs)
  File "/home/thundermoose/ExternalGits/ford/ford/__init__.py", line 420, in main
    project.correlate()
  File "/home/thundermoose/ExternalGits/ford/ford/fortran_project.py", line 343, in correlate
    container.prune()
  File "/home/thundermoose/ExternalGits/ford/ford/sourceform.py", line 1415, in prune
    self.functions = self.filter_display(self.functions)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/thundermoose/ExternalGits/ford/ford/sourceform.py", line 615, in filter_display
    return [obj for obj in collection if self._should_display(obj)]
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/thundermoose/ExternalGits/ford/ford/sourceform.py", line 608, in _should_display
    if self.settings.hide_undoc and not item.doc:
                                        ^^^^^^^^
AttributeError: 'FortranFunction' object has no attribute 'doc'

The reason this happen is that the project.correlate() function is called before the project.markdown(md) line where the doc attributes are setup. Switching order of these lines is not possible since the markdown parser md depend on project.correlate(). The solution was simple, check if the doc_list attribute is non-empty instead of checking for the doc attribute. Perhaps I should check if the items in the doc_list are not empty strings as well?

ZedThree commented 1 month ago

Thank you for finding and fixing this @thundermoose! Sorry for the delay in getting around to looking at it. I've added a test and simplified the check a bit.