Skip to content

Commit

Permalink
2.58.11, downport, outline READ TABLE INTO (#1485)
Browse files Browse the repository at this point in the history
* downport, outline READ TABLE INTO

* downport EMPTY KEY, #1479

* 2.58.11
  • Loading branch information
larshp committed Oct 24, 2020
1 parent ac1f9a7 commit a0b0526
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 26 deletions.
8 changes: 4 additions & 4 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@abaplint/cli",
"version": "2.58.10",
"version": "2.58.11",
"description": "abaplint - Command Line Interface",
"bin": {
"abaplint": "./abaplint"
Expand Down Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://abaplint.org",
"devDependencies": {
"@abaplint/core": "^2.58.10",
"@abaplint/core": "^2.58.11",
"@types/chai": "^4.2.14",
"@types/glob": "^7.1.3",
"@types/minimist": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/package.json
@@ -1,6 +1,6 @@
{
"name": "@abaplint/core",
"version": "2.58.10",
"version": "2.58.11",
"description": "abaplint - Core API",
"main": "build/src/index.js",
"typings": "build/abaplint.d.ts",
Expand Down
35 changes: 31 additions & 4 deletions packages/core/src/rules/downport.ts
Expand Up @@ -39,6 +39,7 @@ Target downport version is always v702, thus rule is only enabled if target vers
Current rules:
* NEW transformed to CREATE OBJECT, opposite of https://rules.abaplint.org/use_new/
* outline, opposite of https://rules.abaplint.org/prefer_inline/
* EMPTY KEY is changed to DEFAULT KEY
Future rules, todo:
* boolc, opposite of https://rules.abaplint.org/prefer_xsdbool/
Expand Down Expand Up @@ -144,7 +145,12 @@ Only one transformation is applied to a statement at a time, so multiple steps m
return undefined;
}

let found = this.outlineData(high, lowFile, highSyntax);
let found = this.emptyKey(high, lowFile);
if (found) {
return found;
}

found = this.outlineData(high, lowFile, highSyntax);
if (found) {
return found;
}
Expand All @@ -161,6 +167,25 @@ Only one transformation is applied to a statement at a time, so multiple steps m

//////////////////////////////////////////

private emptyKey(node: StatementNode, lowFile: ABAPFile): Issue | undefined {

for (const i of node.findAllExpressions(Expressions.TypeTable)) {
const concat = i.concatTokens();
if (concat.includes("WITH EMPTY KEY") === false) {
continue;
}
const token = i.findDirectTokenByText("EMPTY");
if (token === undefined) {
continue;
}

const fix = EditHelper.replaceToken(lowFile, token, "DEFAULT");
return Issue.atToken(lowFile, i.getFirstToken(), "Downport EMPTY KEY", this.getMetadata().key, this.conf.severity, fix);
}

return;
}

private outlineData(node: StatementNode, lowFile: ABAPFile, highSyntax: ISyntaxResult): Issue | undefined {

for (const i of node.findAllExpressions(Expressions.InlineData)) {
Expand All @@ -179,9 +204,11 @@ Only one transformation is applied to a statement at a time, so multiple steps m
}
const type = found.getType().getQualifiedName() ? found.getType().getQualifiedName() : found.getType().toABAP();

// todo, this assumes that the statement starts with "DATA("
const code = `DATA ${name} TYPE ${type}.\n${name}`;
const fix = EditHelper.replaceRange(lowFile, i.getFirstToken().getStart(), i.getLastToken().getEnd(), code);
const code = `DATA ${name} TYPE ${type}.\n`;
const fix1 = EditHelper.insertAt(lowFile, node.getFirstToken().getStart(), code);
const fix2 = EditHelper.replaceRange(lowFile, i.getFirstToken().getStart(), i.getLastToken().getEnd(), name);
const fix = EditHelper.merge(fix2, fix1);

return Issue.atToken(lowFile, i.getFirstToken(), "Outline DATA", this.getMetadata().key, this.conf.severity, fix);
}

Expand Down
23 changes: 23 additions & 0 deletions packages/core/test/rules/downport.ts
Expand Up @@ -304,4 +304,27 @@ foobar = lcl_class=>m( ).
testFix(abap, expected);
});

it("outline, READ TABLE INTO", async () => {
const abap = `
DATA tab TYPE STANDARD TABLE OF i WITH DEFAULT KEY.
APPEND 2 TO tab.
READ TABLE tab INDEX 1 INTO DATA(row).`;

const expected = `
DATA tab TYPE STANDARD TABLE OF i WITH DEFAULT KEY.
APPEND 2 TO tab.
DATA row TYPE i.
READ TABLE tab INDEX 1 INTO row.`;

testFix(abap, expected);
});

it("EMPTY KEY", async () => {
const abap = `DATA tab TYPE STANDARD TABLE OF i WITH EMPTY KEY.`;

const expected = `DATA tab TYPE STANDARD TABLE OF i WITH DEFAULT KEY.`;

testFix(abap, expected);
});

});
8 changes: 4 additions & 4 deletions packages/monaco/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/monaco/package.json
@@ -1,6 +1,6 @@
{
"name": "@abaplint/monaco",
"version": "2.58.10",
"version": "2.58.11",
"description": "ABAP language support for Monaco Editor",
"main": "build/index.js",
"typings": "build/index.d.ts",
Expand All @@ -24,6 +24,6 @@
"vscode-languageserver-types": "^3.15.1"
},
"dependencies": {
"@abaplint/core": "^2.58.10"
"@abaplint/core": "^2.58.11"
}
}
14 changes: 7 additions & 7 deletions web/playground/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/playground/package.json
Expand Up @@ -21,7 +21,7 @@
"vscode-languageserver-types": "^3.15.1"
},
"devDependencies": {
"@abaplint/monaco": "^2.58.10",
"@abaplint/monaco": "^2.58.11",
"css-loader": "^5.0.0",
"file-loader": "^6.1.1",
"html-webpack-plugin": "^4.5.0",
Expand Down

0 comments on commit a0b0526

Please sign in to comment.