Skip to content

Commit

Permalink
fix: Unhandled CallExpression expression syntax: CallExpression
Browse files Browse the repository at this point in the history
A CallExpression on a CallExpression wasn't handled yet and caused a
fatal error.

This commit also adds a test case for another issue that was already
fixed via #73 (SuperKeyword).

Fixes: #246
  • Loading branch information
matz3 committed Aug 12, 2024
1 parent 829e826 commit 3a7716d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export default class SourceFileLinter {

if (!ts.isPropertyAccessExpression(exprNode) &&
!ts.isElementAccessExpression(exprNode) &&
!ts.isIdentifier(exprNode)) {
!ts.isIdentifier(exprNode) &&
!ts.isCallExpression(exprNode)) {
// TODO: Transform into coverage message if it's really ok not to handle this
throw new Error(`Unhandled CallExpression expression syntax: ${ts.SyntaxKind[exprNode.kind]}`);
}
Expand All @@ -229,7 +230,7 @@ export default class SourceFileLinter {
reportNode = exprNode.name;
} else if (ts.isElementAccessExpression(exprNode)) {
reportNode = exprNode.argumentExpression;
} else { // Identifier
} else { // Identifier / CallExpression
reportNode = exprNode;
}

Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/linter/general/Class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import BaseObject from "sap/ui/base/Object";

class Foo extends BaseObject {
constructor() {
super();
}
}
3 changes: 3 additions & 0 deletions test/fixtures/linter/general/FunctionCall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import values from "sap/base/util/values";
const getValues = () => values;
getValues()({foo: "bar"}); // Special case: CallExpression on a CallExpression
3 changes: 3 additions & 0 deletions test/fixtures/linter/rules/NoDeprecatedApi/NoDeprecatedApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ sap.ui.define([

includes([1], 1); // Function "includes" is deprecated

const getIncludesFunction = () => includes;
getIncludesFunction()([1], 1); // Function "includes" is deprecated

Configuration.getCompatibilityVersion("sapMDialogWithPadding"); // Method "getCompatibilityVersion" is deprecated
Configuration["getCompatibilityVersion"]("sapMDialogWithPadding"); // Method "getCompatibilityVersion" is deprecated

Expand Down
27 changes: 18 additions & 9 deletions test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [],
errorCount: 18,
errorCount: 19,
fatalErrorCount: 0,
filePath: 'NoDeprecatedApi.js',
messages: [
Expand Down Expand Up @@ -164,10 +164,19 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 2,
fatal: undefined,
line: 27,
message: 'Call to deprecated function \'getIncludesFunction()\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 16,
fatal: undefined,
line: 26,
line: 29,
message: 'Call to deprecated function \'getCompatibilityVersion\' of class \'Configuration\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-api',
Expand All @@ -176,7 +185,7 @@ Generated by [AVA](https://avajs.dev).
{
column: 16,
fatal: undefined,
line: 27,
line: 30,
message: 'Call to deprecated function \'getCompatibilityVersion\' of class \'Configuration\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-api',
Expand All @@ -185,7 +194,7 @@ Generated by [AVA](https://avajs.dev).
{
column: 2,
fatal: undefined,
line: 29,
line: 32,
message: 'Access of deprecated property \'webview\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-property',
Expand All @@ -194,7 +203,7 @@ Generated by [AVA](https://avajs.dev).
{
column: 2,
fatal: undefined,
line: 30,
line: 33,
message: 'Access of deprecated property \'webview\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-property',
Expand All @@ -203,7 +212,7 @@ Generated by [AVA](https://avajs.dev).
{
column: 2,
fatal: undefined,
line: 32,
line: 35,
message: 'Access of deprecated property \'AnimationMode\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-property',
Expand All @@ -212,7 +221,7 @@ Generated by [AVA](https://avajs.dev).
{
column: 2,
fatal: undefined,
line: 34,
line: 37,
message: 'Access of deprecated property \'MessageType\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-property',
Expand All @@ -221,7 +230,7 @@ Generated by [AVA](https://avajs.dev).
{
column: 2,
fatal: undefined,
line: 36,
line: 39,
message: 'Access of deprecated property \'Date\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-property',
Expand All @@ -230,7 +239,7 @@ Generated by [AVA](https://avajs.dev).
{
column: 20,
fatal: undefined,
line: 39,
line: 42,
message: 'Call to deprecated function \'storeInnerAppState\' of class \'NavigationHandler\'',
messageDetails: 'Deprecated test message',
ruleId: 'ui5-linter-no-deprecated-api',
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap
Binary file not shown.
30 changes: 30 additions & 0 deletions test/lib/linter/snapshots/linter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ The actual snapshot is saved in `linter.ts.snap`.

Generated by [AVA](https://avajs.dev).

## General: Class.js

> Snapshot 1
[
{
coverageInfo: [],
errorCount: 0,
fatalErrorCount: 0,
filePath: 'Class.js',
messages: [],
warningCount: 0,
},
]

## General: Coverage.js

> Snapshot 1
Expand Down Expand Up @@ -92,6 +107,21 @@ Generated by [AVA](https://avajs.dev).
},
]

## General: FunctionCall.js

> Snapshot 1
[
{
coverageInfo: [],
errorCount: 0,
fatalErrorCount: 0,
filePath: 'FunctionCall.js',
messages: [],
warningCount: 0,
},
]

## General: JSDoc.js

> Snapshot 1
Expand Down
Binary file modified test/lib/linter/snapshots/linter.ts.snap
Binary file not shown.

0 comments on commit 3a7716d

Please sign in to comment.