Summary
When a related file type is excluded from annotation (e.g. exclude_tests: true), annotaterb models --delete does not remove annotations that were previously written to those files. The annotations become orphaned, and there's no built-in way to clean them up other than temporarily reverting the config.
Steps to reproduce
- With
exclude_tests: false (the default), annotate — the model and its test files get an annotation block.
- Decide you no longer want annotations in test files and set
exclude_tests: true.
- Run
annotaterb models --delete.
Expected: the annotation blocks are removed from the test files as well.
Actual: the model/fixture annotations are removed, but the test files keep their (now stale) annotation blocks. The only workaround is to set exclude_tests: false, run --delete, then set it back to true.
The same applies to any related type that can be excluded (fixtures, factories, serializers, scaffolds, controllers, helpers).
Root cause
ProjectAnnotationRemover#build_instructions_for_file builds its related-file list with the same RelatedFilesListBuilder that is used for annotating:
https://github.com/drwl/annotaterb/blob/9538099/lib/annotate_rb/model_annotator/project_annotation_remover.rb#L51
RelatedFilesListBuilder#build gates each related file type on the exclude_* options, so an excluded type is never added to the list — and removal therefore never visits it.
Proposed fix
The exclude_* options describe where annotations should be added; they shouldn't block removal. When removing, the builder should reach every related file type regardless of the exclude settings (removing an annotation from a file that has none is a no-op).
I have a small patch + unit test ready and am happy to open a PR if this direction sounds good to you.
Summary
When a related file type is excluded from annotation (e.g.
exclude_tests: true),annotaterb models --deletedoes not remove annotations that were previously written to those files. The annotations become orphaned, and there's no built-in way to clean them up other than temporarily reverting the config.Steps to reproduce
exclude_tests: false(the default), annotate — the model and its test files get an annotation block.exclude_tests: true.annotaterb models --delete.Expected: the annotation blocks are removed from the test files as well.
Actual: the model/fixture annotations are removed, but the test files keep their (now stale) annotation blocks. The only workaround is to set
exclude_tests: false, run--delete, then set it back totrue.The same applies to any related type that can be excluded (fixtures, factories, serializers, scaffolds, controllers, helpers).
Root cause
ProjectAnnotationRemover#build_instructions_for_filebuilds its related-file list with the sameRelatedFilesListBuilderthat is used for annotating:https://github.com/drwl/annotaterb/blob/9538099/lib/annotate_rb/model_annotator/project_annotation_remover.rb#L51
RelatedFilesListBuilder#buildgates each related file type on theexclude_*options, so an excluded type is never added to the list — and removal therefore never visits it.Proposed fix
The
exclude_*options describe where annotations should be added; they shouldn't block removal. When removing, the builder should reach every related file type regardless of the exclude settings (removing an annotation from a file that has none is a no-op).I have a small patch + unit test ready and am happy to open a PR if this direction sounds good to you.