All files / src/rules cloud_types.ts

48% Statements 48/100
75% Branches 6/8
75% Functions 6/8
48% Lines 48/100

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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1001x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10501x 10501x 10501x 10501x 10501x 31324x 31324x 31324x 31324x 31324x 31324x 31324x 10501x 10501x     10501x 10501x 9969x 9969x 10501x 10501x 251x 251x 10501x 10501x 251x 251x 251x 10501x 10501x                                                                                 10501x 10501x 317x 317x 317x                     10501x 10501x
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, RuleTag.Syntax],
    };
  }
 
  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 static isCloud(obj: IObject): boolean {
    return obj instanceof Objects.ApplicationJobCatalogEntry
      || obj instanceof Objects.ApplicationJobTemplate
      || obj instanceof Objects.AssignmentServiceToAuthorizationGroup
      || obj instanceof Objects.ATCCheckCategory
      || obj instanceof Objects.ATCCheckObject
      || obj instanceof Objects.ATCCheckVariant
      || obj instanceof Objects.AuthorizationCheckField
      || obj instanceof Objects.AuthorizationObject
      || obj instanceof Objects.AuthorizationObjectExtension
      || obj instanceof Objects.BehaviorDefinition
      || obj instanceof Objects.BusinessCatalog
      || obj instanceof Objects.BusinessCatalogAppAssignment
      || obj instanceof Objects.CDSMetadataExtension
      || obj instanceof Objects.Class
      || obj instanceof Objects.ApplicationLogObject
      || obj instanceof Objects.CommunicationScenario
      || obj instanceof Objects.DataControl
      || obj instanceof Objects.DataDefinition
      || obj instanceof Objects.DataElement
      || obj instanceof Objects.Domain
      || obj instanceof Objects.EventBinding
      || obj instanceof Objects.EventConsumer
      || obj instanceof Objects.FunctionGroup
      || obj instanceof Objects.HttpService
      || obj instanceof Objects.IAMApp
      || obj instanceof Objects.InboundService
      || obj instanceof Objects.Interface
      || obj instanceof Objects.LockObject
      || obj instanceof Objects.MessageClass
      || obj instanceof Objects.NumberRange
      || obj instanceof Objects.OutboundService
      || obj instanceof Objects.Package
      || obj instanceof Objects.RestrictionField
      || obj instanceof Objects.RestrictionType
      || obj instanceof Objects.ServiceBinding
      || obj instanceof Objects.ServiceDefinition
      || obj instanceof Objects.Table
      || obj instanceof Objects.TableType
      || obj instanceof Objects.Transformation;
  }
 
  public run(obj: IObject): Issue[] {
    if (this.reg.getConfig().getVersion() !== Version.Cloud || CloudTypes.isCloud(obj)) {
      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];
  }
 
}