@abaplint/core
Version:
abaplint - Core API
69 lines • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColonMissingSpace = exports.ColonMissingSpaceConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const position_1 = require("../position");
const edit_helper_1 = require("../edit_helper");
const _irule_1 = require("./_irule");
const _statement_1 = require("../abap/2_statements/statements/_statement");
class ColonMissingSpaceConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.ColonMissingSpaceConf = ColonMissingSpaceConf;
class ColonMissingSpace extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new ColonMissingSpaceConf();
}
getMetadata() {
return {
key: "colon_missing_space",
title: "Colon missing space",
shortDescription: `Checks for missing spaces after colons in chained statements.`,
tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
badExample: `WRITE:hello, world.`,
goodExample: `WRITE: hello, world.`,
};
}
getMessage() {
return "Missing space after the 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 _statement_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);
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
if (token.getStr() === ":"
&& tokens[i + 1] !== undefined
&& tokens[i + 1].getRow() === token.getRow()
&& tokens[i + 1].getCol() === token.getCol() + 1) {
const start = token.getStart();
const end = new position_1.Position(start.getRow(), start.getCol() + 1);
const fix = edit_helper_1.EditHelper.insertAt(file, end, " ");
const issue = issue_1.Issue.atRange(file, start, end, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
}
}
}
return issues;
}
}
exports.ColonMissingSpace = ColonMissingSpace;
//# sourceMappingURL=colon_missing_space.js.map