All files / src/rules unused_ddic.ts

100% Statements 63/63
100% Branches 15/15
100% Functions 7/7
100% Lines 63/63

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 631x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11217x 11217x 11217x 11217x 11217x 33437x 33437x 33437x 33437x 33437x 33437x 33437x 33437x 11217x 11217x 279x 279x 279x 11217x 11217x 10642x 10642x 11217x 11217x 266x 266x 11217x 11217x 345x 345x 345x 345x 345x 64x 64x 281x 281x 281x 11217x 11217x 64x 64x 64x 64x 64x 19x 19x 19x 45x 45x 45x 11217x 11217x
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 [];
  }
 
}