@abaplint/core
Version:
abaplint - Core API
88 lines • 3.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LineOnlyPunc = exports.LineOnlyPuncConf = void 0;
const issue_1 = require("../issue");
const position_1 = require("../position");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const objects_1 = require("../objects");
const _irule_1 = require("./_irule");
const edit_helper_1 = require("../edit_helper");
const ddic_1 = require("../ddic");
class LineOnlyPuncConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** Ignore lines with only puncutation in global exception classes */
this.ignoreExceptions = true;
}
}
exports.LineOnlyPuncConf = LineOnlyPuncConf;
class LineOnlyPunc extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new LineOnlyPuncConf();
}
getMetadata() {
return {
key: "line_only_punc",
title: "Line containing only punctuation",
shortDescription: `Detects lines containing only punctuation.`,
extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#close-brackets-at-line-end
https://docs.abapopenchecks.org/checks/16/`,
tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
badExample: "zcl_class=>method(\n).",
goodExample: "zcl_class=>method( ).",
};
}
getMessage() {
return "A line should not contain only \".\" or \").\"";
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file, obj) {
const issues = [];
const ddic = new ddic_1.DDIC(this.reg);
if (obj instanceof objects_1.Class) {
const definition = obj.getClassDefinition();
if (definition === undefined) {
return [];
}
else if (this.conf.ignoreExceptions && ddic.isException(definition, obj)) {
return [];
}
}
const rows = file.getRawRows();
const reg = new RegExp("^\\)?\\. *(\\\".*)?$");
for (let i = 0; i < rows.length; i++) {
if (reg.exec(rows[i].trim())) {
const column = rows[i].indexOf(")") >= 0 ? rows[i].indexOf(")") + 1 : rows[i].indexOf(".") + 1;
const position = new position_1.Position(i + 1, column);
// merge punc into previous row
let rowContent = rows[i].trim();
// if reported row contains parentheses, prefix with space if needed
if (rowContent.length > 1 && !rows[i - 1].endsWith(" ") && !rows[i - 1].endsWith(" \r")) {
rowContent = " " + rowContent;
}
let offset = 0;
if (rows[i - 1].endsWith("\r")) {
offset = -1;
}
const startPos = new position_1.Position(i, rows[i - 1].length + 1 + offset);
const endPos = new position_1.Position(i + 1, rows[i].length + 1);
let fix = edit_helper_1.EditHelper.replaceRange(file, startPos, endPos, rowContent);
if (rows[i - 1] === undefined || rows[i - 1].indexOf("*") === 0 || rows[i - 1].includes(`"`)) {
fix = undefined;
}
const issue = issue_1.Issue.atPosition(file, position, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
}
}
return issues;
}
}
exports.LineOnlyPunc = LineOnlyPunc;
//# sourceMappingURL=line_only_punc.js.map