All files / src/rules tables_declared_locally.ts

100% Statements 59/59
100% Branches 10/10
100% Functions 5/5
100% Lines 59/59

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 591x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10892x 10892x 10892x 10892x 32489x 32489x 32489x 32489x 32489x 32489x 32489x 32489x 32489x 32489x 32489x 32489x 10892x 10892x 10345x 10345x 10892x 10892x 258x 258x 10892x 10892x 272x 272x 272x 272x 12x 12x 260x 260x 272x 39x 39x 1x 1x 1x 1x 39x 260x 260x 260x 260x 10892x 10892x
import {Issue} from "../issue";
import * as Statements from "../abap/2_statements/statements";
import * as Structures from "../abap/3_structures/structures";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class TablesDeclaredLocallyConf extends BasicRuleConfig {
}
 
export class TablesDeclaredLocally extends ABAPRule {
  private conf = new TablesDeclaredLocallyConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "tables_declared_locally",
      title: "Check for locally declared TABLES",
      shortDescription: `TABLES are always global, so declare them globally`,
      extendedInformation: `https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-us/abaptables.htm`,
      tags: [RuleTag.SingleFile],
      badExample: `FORM foo.
  TABLES t100.
ENDFORM.`,
      goodExample: `TABLES t000.`,
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: TablesDeclaredLocallyConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    const structure = file.getStructure();
    if (structure === undefined) {
      return issues;
    }
 
    const procedures = structure.findAllStructuresMulti([Structures.Form, Structures.FunctionModule]);
    for (const p of procedures) {
      const tablesStatement = p.findFirstStatement(Statements.Tables);
      if (tablesStatement) {
        const message = "Declare TABLES globaly";
        const issue = Issue.atStatement(file, tablesStatement, message, this.getMetadata().key, this.conf.severity);
        issues.push(issue);
      }
    }
 
 
    return issues;
  }
 
}