Skip to content

annotaterb models --delete doesn't remove annotations from files excluded via exclude_* #340

Description

@jeduardo824

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

  1. With exclude_tests: false (the default), annotate — the model and its test files get an annotation block.
  2. Decide you no longer want annotations in test files and set exclude_tests: true.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions