All files / src/rules cloud_types.ts

83.09% Statements 59/71
30% Branches 6/20
85.71% Functions 6/7
83.09% Lines 59/71

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 64 65 66 67 68 69 70 711x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8921x 8921x 8921x 8921x 8921x 77517x 77517x 77517x 77517x 77517x 77517x 77517x 8921x 8921x     8921x 8921x 8485x 8485x 8921x 8921x 202x 202x 8921x 8921x 202x 202x 202x 8921x 8921x 257x 257x 257x 257x 257x 257x 257x 257x 257x 257x 257x 257x 257x 257x 257x 257x                     8921x 8921x
import {IRule, IRuleMetadata, RuleTag} from "./_irule";
import {Issue} from "../issue";
import {Version} from "../version";
import * as Objects from "../objects";
import {IObject} from "../objects/_iobject";
import {IRegistry} from "../_iregistry";
import {BasicRuleConfig} from "./_basic_rule_config";
import {Position} from "../position";
 
export class CloudTypesConf extends BasicRuleConfig {
}
 
export class CloudTypes implements IRule {
  private reg: IRegistry;
  private conf = new CloudTypesConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "cloud_types",
      title: "Check cloud types",
      shortDescription: `Checks that the package does not contain any object types unsupported in cloud ABAP.`,
      tags: [RuleTag.SingleFile],
    };
  }
 
  private getDescription(objectType: string): string {
    return "Object type " + objectType + " not supported in cloud";
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: CloudTypesConf) {
    this.conf = conf;
  }
 
  public initialize(reg: IRegistry) {
    this.reg = reg;
    return this;
  }
 
  public run(obj: IObject): Issue[] {
    if (this.reg.getConfig().getVersion() !== Version.Cloud
        || obj instanceof Objects.Class
        || obj instanceof Objects.Interface
        || obj instanceof Objects.MessageClass
        || obj instanceof Objects.Package
        || obj instanceof Objects.Table
        || obj instanceof Objects.TableType
        || obj instanceof Objects.DataDefinition
        || obj instanceof Objects.DataControl
        || obj instanceof Objects.LockObject
        || obj instanceof Objects.Transformation
        || obj instanceof Objects.FunctionGroup
        || obj instanceof Objects.DataElement
        || obj instanceof Objects.Domain) {
      return [];
    }

    const position = new Position(1, 1);
    const issue = Issue.atPosition(
      obj.getFiles()[0],
      position,
      this.getDescription(obj.getType()),
      this.getMetadata().key,
      this.conf.severity);
    return [issue];
  }
 
}