@abaplint/core
Version:
abaplint - Core API
75 lines • 3.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpaceBeforeColon = exports.SpaceBeforeColonConf = void 0;
const position_1 = require("../position");
const edit_helper_1 = require("../edit_helper");
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const _irule_1 = require("./_irule");
const _statement_1 = require("../abap/2_statements/statements/_statement");
const tokens_1 = require("../abap/1_lexer/tokens");
class SpaceBeforeColonConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.SpaceBeforeColonConf = SpaceBeforeColonConf;
class SpaceBeforeColon extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new SpaceBeforeColonConf();
}
getMetadata() {
return {
key: "space_before_colon",
title: "Space before colon",
shortDescription: `Checks that there are no spaces in front of colons in chained statements.`,
extendedInformation: `https://docs.abapopenchecks.org/checks/80/`,
tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
badExample: `DATA : foo TYPE string.`,
goodExample: `DATA: foo TYPE string.`,
};
}
getMessage() {
return "Remove space before colon";
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
for (const statement of file.getStatements()) {
const colon = statement.getColon();
if (colon === undefined
|| statement.get() instanceof _statement_1.NativeSQL
|| statement.get() instanceof tokens_1.Comment) {
continue;
}
// todo: this can be more smart, performance wise
const tokens = [...statement.getTokens()];
tokens.push(colon);
tokens.sort((a, b) => a.getStart().isAfter(b.getStart()) ? 1 : -1);
let prev = tokens[0];
for (const token of tokens) {
if (token.getStr() === ":" && !prev) {
const issue = issue_1.Issue.atToken(file, token, this.getMessage(), this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
else if (token.getStr() === ":"
&& prev.getRow() === token.getRow()
&& prev.getCol() + prev.getStr().length < token.getCol()) {
const start = new position_1.Position(token.getRow(), prev.getEnd().getCol());
const end = new position_1.Position(token.getRow(), token.getStart().getCol());
const fix = edit_helper_1.EditHelper.deleteRange(file, start, end);
const issue = issue_1.Issue.atRowRange(file, start.getRow(), start.getCol(), end.getCol(), this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
}
prev = token;
}
}
return issues;
}
}
exports.SpaceBeforeColon = SpaceBeforeColon;
//# sourceMappingURL=space_before_colon.js.map