All files / src/rules inline_data_old_versions.ts

86.67% Statements 26/30
66.67% Branches 8/12
100% Functions 5/5
86.67% Lines 26/30

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 651x 1x 1x 1x 1x 1x     1x     1x 7272x     21674x                 7013x       114x       131x   131x   130x     1x   1x 1x 1x     1x     1x     1x       1x 1x 1x       1x    
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.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();
        Iif (tokens.length !== 4) {
          continue;
        }
        Iif (!tokens[0].getStr().match(/DATA/i)) {
          continue;
        }
        Iif (tokens[1].getStr() !== "(") {
          continue;
        }
        Iif (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;
  }
}