All files / src/rules unused_ddic.ts

100% Statements 21/21
100% Branches 11/11
100% Functions 7/7
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63  1x 1x     1x   1x     1x   7374x     21959x                   147x 147x       7061x       138x       172x         25x     147x       25x 25x 25x   25x 8x 8x     17x      
import {IRule, IRuleMetadata} from "./_irule";
import {Issue} from "../issue";
import * as Objects from "../objects";
import {IObject} from "../objects/_iobject";
import {IRegistry} from "../_iregistry";
import {BasicRuleConfig} from "./_basic_rule_config";
 
export class UnusedDDICConf extends BasicRuleConfig {
}
 
export class UnusedDDIC implements IRule {
  private reg: IRegistry;
  private conf = new UnusedDDICConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "unused_ddic",
      title: "Unused DDIC",
      shortDescription: `Checks the usage of DDIC objects`,
      extendedInformation: `Objects checked: DOMA + DTEL + TABL + TTYP + VIEW`,
      tags: [],
    };
  }
 
  public initialize(reg: IRegistry) {
    this.reg = reg;
    return this;
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: UnusedDDICConf) {
    this.conf = conf;
  }
 
  public run(obj: IObject): Issue[] {
    if (obj instanceof Objects.Domain
        || obj instanceof Objects.TableType
        || obj instanceof Objects.View
        || obj instanceof Objects.Table
        || obj instanceof Objects.DataElement) {
      return this.check(obj);
    }
 
    return [];
  }
 
  private check(obj: IObject): Issue[] {
    const id = obj.getIdentifier();
    const refs = this.reg.getDDICReferences();
    const list = refs.listWhereUsed(obj);
 
    if (id && list.length === 0) {
      const message = obj.getType() + " " + obj.getName() + " not statically referenced";
      return [Issue.atIdentifier(id, message, this.getMetadata().key, this.conf.severity)];
    }
 
    return [];
  }
 
}