diff --git a/src/linter/ui5Types/SourceFileLinter.ts b/src/linter/ui5Types/SourceFileLinter.ts index 23bca1b5b..d11d650dd 100644 --- a/src/linter/ui5Types/SourceFileLinter.ts +++ b/src/linter/ui5Types/SourceFileLinter.ts @@ -21,11 +21,11 @@ interface DeprecationInfo { } function isSourceFileOfUi5Type(sourceFile: ts.SourceFile) { - return /@openui5|@sapui5|@ui5/.test(sourceFile.fileName); + return /\/types\/(@openui5|@sapui5|@ui5\/linter\/overrides)\//.test(sourceFile.fileName); } function isSourceFileOfUi5OrThirdPartyType(sourceFile: ts.SourceFile) { - return /@openui5|@sapui5|@ui5|@types\/jquery/.test(sourceFile.fileName); + return isSourceFileOfUi5Type(sourceFile) || /\/types\/(@types\/jquery)\//.test(sourceFile.fileName); } function isSourceFileOfJquerySapType(sourceFile: ts.SourceFile) { diff --git a/test/fixtures/linter/projects/com.ui5.troublesome.app/webapp/controller/Main.controller.js b/test/fixtures/linter/projects/com.ui5.troublesome.app/webapp/controller/Main.controller.js index 846c542be..8ad0cfee0 100644 --- a/test/fixtures/linter/projects/com.ui5.troublesome.app/webapp/controller/Main.controller.js +++ b/test/fixtures/linter/projects/com.ui5.troublesome.app/webapp/controller/Main.controller.js @@ -1,7 +1,7 @@ sap.ui.define(["./BaseController", "sap/m/MessageBox"], function (BaseController, MessageBox) { "use strict"; - return BaseController.extend("com.ui5.troublesome.app.controller.Main", { + const MainController = BaseController.extend("com.ui5.troublesome.app.controller.Main", { sayHello: function () { MessageBox.show("Hello World!"); }, @@ -32,4 +32,16 @@ sap.ui.define(["./BaseController", "sap/m/MessageBox"], function (BaseController this.getView().byId("unknown").prop("foo", "bar"); } }); + + // Note: Accessing the controller prototype should not cause a false positive for global variables, + // which was appearing in combination with the declaration merging for the byId type support. + MainController.prototype.doSomething = function () { + + // byId type support should also work within methods attached to the prototype + this.byId("helloButton").attachTap(function() { + console.log("Tapped"); + }); + }; + + return MainController; }); diff --git a/test/lib/linter/snapshots/linter.ts.md b/test/lib/linter/snapshots/linter.ts.md index 0c04ca774..b0b54391b 100644 --- a/test/lib/linter/snapshots/linter.ts.md +++ b/test/lib/linter/snapshots/linter.ts.md @@ -415,7 +415,7 @@ Generated by [AVA](https://avajs.dev). }, { coverageInfo: [], - errorCount: 6, + errorCount: 7, fatalErrorCount: 0, filePath: 'webapp/controller/Main.controller.js', messages: [ @@ -467,6 +467,14 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-api', severity: 2, }, + { + column: 28, + line: 41, + message: 'Call to deprecated function \'attachTap\' of class \'Button\'', + messageDetails: 'Deprecated test message', + ruleId: 'no-deprecated-api', + severity: 2, + }, ], warningCount: 0, }, @@ -1147,7 +1155,7 @@ Generated by [AVA](https://avajs.dev). }, { coverageInfo: [], - errorCount: 6, + errorCount: 7, fatalErrorCount: 0, filePath: 'webapp/controller/Main.controller.js', messages: [ @@ -1193,6 +1201,13 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-api', severity: 2, }, + { + column: 28, + line: 41, + message: 'Call to deprecated function \'attachTap\' of class \'Button\'', + ruleId: 'no-deprecated-api', + severity: 2, + }, ], warningCount: 0, }, @@ -2623,7 +2638,7 @@ Generated by [AVA](https://avajs.dev). }, { coverageInfo: [], - errorCount: 6, + errorCount: 7, fatalErrorCount: 0, filePath: 'webapp/controller/Main.controller.js', messages: [ @@ -2675,6 +2690,14 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-api', severity: 2, }, + { + column: 28, + line: 41, + message: 'Call to deprecated function \'attachTap\' of class \'Button\'', + messageDetails: 'Deprecated test message', + ruleId: 'no-deprecated-api', + severity: 2, + }, ], warningCount: 0, }, diff --git a/test/lib/linter/snapshots/linter.ts.snap b/test/lib/linter/snapshots/linter.ts.snap index 17bb86a56..566628c28 100644 Binary files a/test/lib/linter/snapshots/linter.ts.snap and b/test/lib/linter/snapshots/linter.ts.snap differ diff --git a/test/lib/snapshots/index.ts.md b/test/lib/snapshots/index.ts.md index 3812cd7af..59e1bdc9b 100644 --- a/test/lib/snapshots/index.ts.md +++ b/test/lib/snapshots/index.ts.md @@ -57,7 +57,7 @@ Generated by [AVA](https://avajs.dev). }, { coverageInfo: [], - errorCount: 6, + errorCount: 7, fatalErrorCount: 0, filePath: 'webapp/controller/Main.controller.js', messages: [ @@ -103,6 +103,13 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-api', severity: 2, }, + { + column: 28, + line: 41, + message: 'Call to deprecated function \'attachTap\' of class \'Button\'', + ruleId: 'no-deprecated-api', + severity: 2, + }, ], warningCount: 0, }, @@ -454,7 +461,7 @@ Generated by [AVA](https://avajs.dev). }, { coverageInfo: [], - errorCount: 6, + errorCount: 7, fatalErrorCount: 0, filePath: 'webapp/controller/Main.controller.js', messages: [ @@ -500,6 +507,13 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-api', severity: 2, }, + { + column: 28, + line: 41, + message: 'Call to deprecated function \'attachTap\' of class \'Button\'', + ruleId: 'no-deprecated-api', + severity: 2, + }, ], warningCount: 0, }, @@ -1455,7 +1469,7 @@ Generated by [AVA](https://avajs.dev). }, { coverageInfo: [], - errorCount: 6, + errorCount: 7, fatalErrorCount: 0, filePath: 'webapp/controller/Main.controller.js', messages: [ @@ -1501,6 +1515,13 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-api', severity: 2, }, + { + column: 28, + line: 41, + message: 'Call to deprecated function \'attachTap\' of class \'Button\'', + ruleId: 'no-deprecated-api', + severity: 2, + }, ], warningCount: 0, }, @@ -1852,7 +1873,7 @@ Generated by [AVA](https://avajs.dev). }, { coverageInfo: [], - errorCount: 6, + errorCount: 7, fatalErrorCount: 0, filePath: 'webapp/controller/Main.controller.js', messages: [ @@ -1898,6 +1919,13 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-api', severity: 2, }, + { + column: 28, + line: 41, + message: 'Call to deprecated function \'attachTap\' of class \'Button\'', + ruleId: 'no-deprecated-api', + severity: 2, + }, ], warningCount: 0, }, @@ -2249,7 +2277,7 @@ Generated by [AVA](https://avajs.dev). }, { coverageInfo: [], - errorCount: 6, + errorCount: 7, fatalErrorCount: 0, filePath: 'webapp/controller/Main.controller.js', messages: [ @@ -2295,6 +2323,13 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-api', severity: 2, }, + { + column: 28, + line: 41, + message: 'Call to deprecated function \'attachTap\' of class \'Button\'', + ruleId: 'no-deprecated-api', + severity: 2, + }, ], warningCount: 0, }, diff --git a/test/lib/snapshots/index.ts.snap b/test/lib/snapshots/index.ts.snap index 69dbdff36..5c541f1eb 100644 Binary files a/test/lib/snapshots/index.ts.snap and b/test/lib/snapshots/index.ts.snap differ