@abaplint/core
Version:
abaplint - Core API
73 lines (71 loc) • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SevenBitAscii = exports.SevenBitAsciiConf = void 0;
const issue_1 = require("../issue");
const position_1 = require("../position");
const _basic_rule_config_1 = require("./_basic_rule_config");
const _irule_1 = require("./_irule");
class SevenBitAsciiConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.SevenBitAsciiConf = SevenBitAsciiConf;
class SevenBitAscii {
constructor() {
this.conf = new SevenBitAsciiConf();
}
getMetadata() {
return {
key: "7bit_ascii",
title: "Check for 7bit ascii",
shortDescription: `Only allow characters from the 7bit ASCII set.`,
extendedInformation: `https://docs.abapopenchecks.org/checks/05/
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abencharacter_set_guidl.htm
Checkes files with extensions ".abap" and ".asddls"`,
tags: [_irule_1.RuleTag.SingleFile],
badExample: `WRITE '뽑'.`,
goodExample: `WRITE cl_abap_conv_in_ce=>uccp( 'BF51' ).`,
};
}
initialize(_reg) {
return this;
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
run(obj) {
const output = [];
for (const file of obj.getFiles()) {
const filename = file.getFilename();
if (filename.endsWith(".abap") || filename.endsWith(".asddls")) {
const rows = file.getRawRows();
for (let i = 0; i < rows.length; i++) {
const found = /[\u007f-\uffff]/.exec(rows[i]);
if (found !== null) {
const column = found.index + 1;
const start = new position_1.Position(i + 1, column);
const end = new position_1.Position(i + 1, column + 1);
const message = "Contains non 7 bit ascii character";
const issue = issue_1.Issue.atRange(file, start, end, message, this.getMetadata().key, this.conf.severity);
output.push(issue);
}
// method getRawRows() splits by newline, so the carraige return
// should always be last character if present
const carriage = /\r.+$/.exec(rows[i]);
if (carriage !== null) {
const column = carriage.index + 1;
const start = new position_1.Position(i + 1, column);
const end = new position_1.Position(i + 1, column + 1);
const message = "Dangling carriage return";
const issue = issue_1.Issue.atRange(file, start, end, message, this.getMetadata().key, this.conf.severity);
output.push(issue);
}
}
}
}
return output;
}
}
exports.SevenBitAscii = SevenBitAscii;
//# sourceMappingURL=7bit_ascii.js.map