Page MenuHomePhabricator

Create phan plugin to warn if an unchecked exception is documented with `@throws`
Open, Needs TriagePublic

Description

This is somewhat the counterpart of T338426. If a method throws an unchecked exception, then phan should warn if said exception is documented with @throws. There doesn't seem to be an upstream option for this, so we'd have to write our own plugin.

Event Timeline

I'm not planning to work on the implementation right now, as there are a bunch of things to do first (e.g., all the sibling tasks). However, it would look something like this. The plugin should analyze method and function doc comments (via either AnalyzeMethodCapability + AnalyzeFunctionCapability, or a full PostAnalysis visitor), look for @throws annotations, and for each of them, check if the exception class is unchecked. The simplest way to do that would be to use the value of the exception_classes_with_optional_throws_phpdoc option added in T338426. If this is deemed insufficient, the plugin could also use a custom config property (specified in plugin_config), whose default value could be the same as exception_classes_with_optional_throws_phpdoc, but which could be overridden in the config file without affecting the other setting.