Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: False-positive global findings in controllers #427

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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!");
},
Expand Down Expand Up @@ -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;
});
29 changes: 26 additions & 3 deletions test/lib/linter/snapshots/linter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 6,
errorCount: 7,
fatalErrorCount: 0,
filePath: 'webapp/controller/Main.controller.js',
messages: [
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -1147,7 +1155,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 6,
errorCount: 7,
fatalErrorCount: 0,
filePath: 'webapp/controller/Main.controller.js',
messages: [
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -2623,7 +2638,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 6,
errorCount: 7,
fatalErrorCount: 0,
filePath: 'webapp/controller/Main.controller.js',
messages: [
Expand Down Expand Up @@ -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,
},
Expand Down
Binary file modified test/lib/linter/snapshots/linter.ts.snap
Binary file not shown.
45 changes: 40 additions & 5 deletions test/lib/snapshots/index.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 6,
errorCount: 7,
fatalErrorCount: 0,
filePath: 'webapp/controller/Main.controller.js',
messages: [
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -454,7 +461,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 6,
errorCount: 7,
fatalErrorCount: 0,
filePath: 'webapp/controller/Main.controller.js',
messages: [
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -1455,7 +1469,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 6,
errorCount: 7,
fatalErrorCount: 0,
filePath: 'webapp/controller/Main.controller.js',
messages: [
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -1852,7 +1873,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 6,
errorCount: 7,
fatalErrorCount: 0,
filePath: 'webapp/controller/Main.controller.js',
messages: [
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -2249,7 +2277,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 6,
errorCount: 7,
fatalErrorCount: 0,
filePath: 'webapp/controller/Main.controller.js',
messages: [
Expand Down Expand Up @@ -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,
},
Expand Down
Binary file modified test/lib/snapshots/index.ts.snap
Binary file not shown.