@abaplint/core
Version:
abaplint - Core API
71 lines • 2.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContainsTab = exports.ContainsTabConf = 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 _irule_1 = require("./_irule");
const edit_helper_1 = require("../edit_helper");
class ContainsTabConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** quick fix replace with number of spaces */
this.spaces = 1;
}
}
exports.ContainsTabConf = ContainsTabConf;
class ContainsTab extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new ContainsTabConf();
}
getMetadata() {
return {
key: "contains_tab",
title: "Code contains tab",
shortDescription: `Checks for usage of tabs (enable to enforce spaces)`,
extendedInformation: `
https://docs.abapopenchecks.org/checks/09/
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#indent-and-snap-to-tab`,
tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
badExample: `\tWRITE 'hello world'.`,
goodExample: ` WRITE 'hello world'.`,
};
}
getMessage() {
return "Code should not contain tabs";
}
getConfig() {
if (this.conf.spaces === undefined) {
this.conf.spaces = 1;
}
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
const lines = file.getRaw().split("\n");
lines.forEach((_, i) => {
const tabCol = lines[i].indexOf("\t");
if (tabCol >= 0) {
let tabAmount = 1;
while (lines[i].indexOf("\t", tabCol + tabAmount - 1) >= 0) {
tabAmount++;
}
issues.push(this.createIssue(i, tabCol, tabAmount, file));
}
});
return issues;
}
createIssue(line, tabCol, tabAmount, file) {
const tabStartPos = new position_1.Position(line + 1, tabCol + 1);
const tabEndPos = new position_1.Position(line + 1, tabCol + tabAmount);
const fix = edit_helper_1.EditHelper.replaceRange(file, tabStartPos, tabEndPos, " ".repeat(this.getConfig().spaces));
return issue_1.Issue.atRange(file, tabStartPos, tabEndPos, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
}
}
exports.ContainsTab = ContainsTab;
//# sourceMappingURL=contains_tab.js.map