All files / src/rules inline_data_old_versions.ts

87.87% Statements 58/66
69.23% Branches 9/13
100% Functions 5/5
87.87% Lines 58/66

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 661x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11218x 11218x 11218x 11218x 33488x 33488x 33488x 33488x 33488x 33488x 33488x 11218x 11218x 10730x 10730x 11218x 11218x 227x 227x 11218x 11218x 241x 241x 241x 241x 241x 240x 240x 1x 1x 1x 1x 1x 1x     1x     1x     1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 11218x
import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {Version} from "../version";
import {Target} from "../abap/2_statements/expressions";
import {BasicRuleConfig} from "./_basic_rule_config";
import {RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class InlineDataOldVersionsConf extends BasicRuleConfig {
}
 
export class InlineDataOldVersions extends ABAPRule {
  private conf = new InlineDataOldVersionsConf();
 
  public getMetadata() {
    return {
      key: "inline_data_old_versions",
      title: "Inline data, old versions",
      shortDescription: `Checks for inline data declarations in older releases. Only active for versions less than v740sp02`,
      tags: [RuleTag.Syntax, RuleTag.SingleFile],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: InlineDataOldVersionsConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    if (this.reg.getConfig().getVersion() >= Version.v740sp02
        || this.reg.getConfig().getVersion() === Version.OpenABAP
        || this.reg.getConfig().getVersion() === Version.Cloud) {
      return [];
    }
 
    for (const statement of file.getStatements()) {
// when parsed in old versions these expressions are NOT InlineData
      for (const target of statement.findAllExpressions(Target)) {
        const tokens = target.getAllTokens();
        if (tokens.length !== 4) {
          continue;
        }
        if (!tokens[0].getStr().match(/DATA/i)) {
          continue;
        }
        if (tokens[1].getStr() !== "(") {
          continue;
        }
        if (tokens[3].getStr() !== ")") {
          continue;
        }
 
        const message = "Inline DATA not possible in " + this.reg.getConfig().getVersion();
        const issue = Issue.atToken(file, tokens[0], message, this.getMetadata().key, this.conf.severity);
        issues.push(issue);
      }
    }
 
    return issues;
  }
}