All files / plugins removeEmptyGroups.ts

100% Statements 2/2
100% Branches 5/5
100% Functions 1/1
100% Lines 2/2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                  12x         1x              
import { JsApi } from '../lib/jsapi';
import { Plugin } from './_types';
 
/**
 * Remove empty groups.
 * TODO: are there any empty containers that could be removed in an animated-vector?
 */
function fn(item: JsApi) {
  // TODO: detect if the group w/ a name is being referenced by an AVD
  return item.isElem('group') && !item.hasAttr('android:name') && item.isEmpty()
    ? undefined
    : item;
}
 
export const removeEmptyGroups: Plugin<undefined> = {
  type: 'perItemReverse',
  active: true,
  description: 'removes empty groups',
  params: undefined,
  fn,
};