diff --git a/test/fixtures/linter/rules/NoDeprecatedApi/Controller.js b/test/fixtures/linter/rules/NoDeprecatedApi/Controller.js new file mode 100644 index 000000000..b4d7ea227 --- /dev/null +++ b/test/fixtures/linter/rules/NoDeprecatedApi/Controller.js @@ -0,0 +1,20 @@ +sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/core/UIComponent", "sap/ui/core/routing/History", "sap/m/Button"], + function (Controller, UIComponent, History, Button) { + "use strict"; + + const BaseController = Controller.extend("com.ui5.troublesome.app.controller.BaseController", { + + createButton: function() { + var btn = new Button({ + blocked: true + }); + return btn; + }, + }); + + const btn = new BaseController().createButton(); + btn.attachTap(function() { + console.log("Tapped"); + }); + return BaseController; +}); diff --git a/test/fixtures/transpiler/amd/NameConflict.js b/test/fixtures/transpiler/amd/Factory_ExtendNameConflict.js similarity index 55% rename from test/fixtures/transpiler/amd/NameConflict.js rename to test/fixtures/transpiler/amd/Factory_ExtendNameConflict.js index 7433cf934..806d5e045 100644 --- a/test/fixtures/transpiler/amd/NameConflict.js +++ b/test/fixtures/transpiler/amd/Factory_ExtendNameConflict.js @@ -1,5 +1,7 @@ sap.ui.define(["sap/ui/core/UIComponent", `sap/ui/Device`], function (UIComponent) { "use strict"; + // Given class name "[...].UIComponent" is identical to an existing variable and therefore must not + // be used for the generated ES class return UIComponent.extend("com.ui5.troublesome.app.UIComponent", {}); }); diff --git a/test/fixtures/transpiler/amd/Factory_ExtendToVar.js b/test/fixtures/transpiler/amd/Factory_ExtendToVar.js new file mode 100644 index 000000000..edb22afb1 --- /dev/null +++ b/test/fixtures/transpiler/amd/Factory_ExtendToVar.js @@ -0,0 +1,18 @@ +sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/core/UIComponent", "sap/ui/core/routing/History", "sap/m/Button"], + function (Controller, UIComponent, History, Button) { + "use strict"; + + const BaseController = Controller.extend("com.ui5.troublesome.app.controller.BaseController", {}); + BaseController.prototype.createButton = function() { + var btn = new Button({ + blocked: true + }); + return btn; + }; + + const btn = new BaseController().createButton(); + btn.attachTap(function() { + console.log("Tapped"); + }); + return BaseController; +}); diff --git a/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md b/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md index de54edd73..7d8da8f16 100644 --- a/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md +++ b/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md @@ -365,6 +365,64 @@ Generated by [AVA](https://avajs.dev). version: 3, } +## Transpile Factory_ExtendNameConflict.js + +> Snapshot 1 + + `import UIComponent from "sap/ui/core/UIComponent";␊ + import "sap/ui/Device";␊ + export default class UIComponent_1 extends UIComponent {␊ + }␊ + //# sourceMappingURL=Factory_ExtendNameConflict.js.map` + +> Snapshot 2 + + { + file: 'Factory_ExtendNameConflict.js', + mappings: 'OAAsE,WAAW,MAAlE,yBAAyB;OAAE;2CAKlC,WAAW', + names: [], + sourceRoot: '', + sources: [ + 'Factory_ExtendNameConflict.js', + ], + version: 3, + } + +## Transpile Factory_ExtendToVar.js + +> Snapshot 1 + + `import Controller from "sap/ui/core/mvc/Controller";␊ + import UIComponent from "sap/ui/core/UIComponent";␊ + import History from "sap/ui/core/routing/History";␊ + import Button from "sap/m/Button";␊ + const BaseController = Controller.extend("com.ui5.troublesome.app.controller.BaseController", {});␊ + BaseController.prototype.createButton = function () {␊ + var btn = new Button({␊ + blocked: true␊ + });␊ + return btn;␊ + };␊ + const btn = new BaseController().createButton();␊ + btn.attachTap(function () {␊ + console.log("Tapped");␊ + });␊ + export default BaseController;␊ + //# sourceMappingURL=Factory_ExtendToVar.js.map` + +> Snapshot 2 + + { + file: 'Factory_ExtendToVar.js', + mappings: 'OACW,UAAU,MADN,4BAA4B;OACpB,WAAW,MADW,yBAAyB;OAClC,OAAO,MAD6B,6BAA6B;OACxD,MAAM,MADoD,cAAc;AAIpH,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,mDAAmD,EAAE,EAAE,CAAC,CAAC;AAClG,cAAc,CAAC,SAAS,CAAC,YAAY,GAAG;IACvC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC;QACpB,OAAO,EAAE,IAAI;KACb,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC;AAEF,MAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC,YAAY,EAAE,CAAC;AAChD,GAAG,CAAC,SAAS,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC;eACI,cAAc', + names: [], + sourceRoot: '', + sources: [ + 'Factory_ExtendToVar.js', + ], + version: 3, + } + ## Transpile Factory_FunctionVarDeclaration.js > Snapshot 1 @@ -711,29 +769,6 @@ Generated by [AVA](https://avajs.dev). version: 3, } -## Transpile NameConflict.js - -> Snapshot 1 - - `import UIComponent from "sap/ui/core/UIComponent";␊ - import "sap/ui/Device";␊ - export default class UIComponent_1 extends UIComponent {␊ - }␊ - //# sourceMappingURL=NameConflict.js.map` - -> Snapshot 2 - - { - file: 'NameConflict.js', - mappings: 'OAAsE,WAAW,MAAlE,yBAAyB;OAAE;2CAGlC,WAAW', - names: [], - sourceRoot: '', - sources: [ - 'NameConflict.js', - ], - version: 3, - } - ## Transpile Noop_DynamicImport.js > Snapshot 1 diff --git a/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap b/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap index 3aab450f4..2e2a41b84 100644 Binary files a/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap and b/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap differ diff --git a/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md b/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md index 9fa54a370..88c9ac367 100644 --- a/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md +++ b/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md @@ -38,6 +38,46 @@ Generated by [AVA](https://avajs.dev). }, ] +## General: Controller.js + +> Snapshot 1 + + [ + { + coverageInfo: [ + { + category: 1, + column: 14, + line: 15, + message: 'Unable to analyze this method call because the type of identifier "createButton" in "new BaseController().createButton()"" could not be determined', + }, + { + category: 1, + column: 2, + line: 16, + message: `Unable to analyze this method call because the type of identifier "attachTap" in "btn.attachTap(function () {␊ + console.log("Tapped");␊ + })"" could not be determined`, + }, + ], + errorCount: 1, + fatalErrorCount: 0, + filePath: 'Controller.js', + messages: [ + { + column: 5, + fatal: undefined, + line: 9, + message: 'Use of deprecated property \'blocked\' of class \'Button\'', + messageDetails: 'Deprecated test message', + ruleId: 'ui5-linter-no-deprecated-api', + severity: 2, + }, + ], + warningCount: 0, + }, + ] + ## General: ModuleImport.js > Snapshot 1 diff --git a/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap b/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap index 95b4ba873..98fdcefeb 100644 Binary files a/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap and b/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap differ