Mozilla Add-ons, Mozilla Firefox, Programming

Finding unused entities in your Firefox extensions

If you’ve maintained a Firefox extension for any amount of time, you know that you can accumulate unused entities as you change the UI or add/remove features. They just pile up in your .dtd and .properties files, taking up space. Here’s a bash script that will list out any entities or entries in .properties files in your extension that is no longer being used so that you can prune them out.

Usage: $ ./unused-entities.sh path/to/locale-directory/ path/to/content-directory/


#!/bin/bash

echo "Unused entities:"

for dtdfile in `ls $1*.dtd` 
do
	awk '/<!ENTITY/ {print $2}' < $dtdfile | while read line
	do
		search=`grep -R "${line}" "$2"`
		if [ "$search" == "" ]
		then
			echo "${line}";
		fi
	done;
done;

echo ""
echo "Unused properties:"

for propfile in `ls $1*.properties`
do
	awk -F "=" '{if (!($2 == "")) { print $1 }}' < $propfile | while read line
	do
		search=`grep -R "${line}" "$2"`
		if [ "$search" == "" ]
		then
			echo "${line}";
		fi
	done;
done;
Standard

2 comments on “Finding unused entities in your Firefox extensions

  1. Philipp Kewisch says:

    While this script will probably catch every entitiy, it won’t work for all properties. I only realized this after fitting the script for my purposes and wondering that there were so many unused properties. If your extension compiles property names at runtime, then this script will obviously not catch them, i.e

    calGetString(“repeatDetailsDay” + day_of_week(byday[0]))

    where repeatDetailsDay1 to repeatDetailsDay7 are vaild property strings. This script is a good start though.

  2. Stephen says:

    Before I start diving into the sensitive Firefox files, can you please tell me where the link goes, where the script goes, and where do I view the results to do the pruning?

    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *