Skip to content

Commit

Permalink
[INTERNAL] Fix jquery plugin comment
Browse files Browse the repository at this point in the history
jquery plugin imports are added as dependency
with a comment.
This comment was a line comment which could break
the code during re-formatting. Therefore the
comment was changed to a block comment which cannot
break the code during re-formatting.

Fixes: #29
  • Loading branch information
tobiasso85 committed Apr 7, 2022
1 parent 6caf0e7 commit 21fca37
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/tasks/helpers/extenders/AddUnusedImportWithComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AddUnusedImportWithComment implements Extender {
config.newModulePath
) as NodeWithComments;
if (!node.comments) {
node.comments = [builders.commentLine(config.commentText)];
node.comments = [builders.commentBlock(config.commentText)];
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/addMissingDependencies/addCommentToImport.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

// A module
sap.ui.define([// My Test comment
sap.ui.define([/* My Test comment*/
"sap/ui/dom/jquery/control"],
function() {
"use strict";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"modules": {
"jQuery Function Extensions": {
"*.addAriaLabelledBy": {
"newModulePath": "sap/ui/dom/jquery/Aria",
"replacer": "AddComment",
"commentText": " jQuery Plugin \"addAriaLabelledBy\"",
"finder": "JQueryFunctionExtensionFinderWithDependencyCheck",
"extender": "AddUnusedImportWithComment",
"version": "^1.58.0"
}
}
},
"finders": {
"JQueryFunctionExtensionFinderWithDependencyCheck": "tasks/helpers/finders/JQueryFunctionExtensionFinderWithDependencyCheck.js"
},
"extenders": {
"AddUnusedImportWithComment": "tasks/helpers/extenders/AddUnusedImportWithComment.js"
},
"replacers": {
"AddComment": "tasks/helpers/replacers/AddComment.js"
},
"comments": {
"unhandledReplacementComment": "TODO unhandled replacement"
},
"excludes": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sap.ui.define([
"./library",
'sap/ui/core/Core',
"sap/ui/core/Item",
'sap/ui/core/Icon',
'sap/ui/core/IconPool',
/* jQuery Plugin "addAriaLabelledBy"*/
"sap/ui/dom/jquery/Aria"
],
function(library, Core, Item, Icon, IconPool) {
"use strict";

// jQuery Plugin "addAriaLabelledBy"
return $a.addAriaLabelledBy("");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sap.ui.define(["./library", 'sap/ui/core/Core', "sap/ui/core/Item", 'sap/ui/core/Icon', 'sap/ui/core/IconPool'],
function(library, Core, Item, Icon, IconPool) {
"use strict";

return $a.addAriaLabelledBy("");
});
2 changes: 1 addition & 1 deletion test/addMissingDependencies/zIndex.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

// A module
sap.ui.define(["sap/ui/thirdparty/jquery", // jQuery Plugin "zIndex"
sap.ui.define(["sap/ui/thirdparty/jquery", /* jQuery Plugin "zIndex"*/
"sap/ui/dom/jquery/zIndex"],
function(jQuery) {
"use strict";
Expand Down
24 changes: 24 additions & 0 deletions test/addMissingDependenciesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,30 @@ describe("addMissingDependencies", () => {
);
});

it("JQuery Plugin addAriaLabelledBy", done => {
const expectedContent = fs.readFileSync(
rootDir + "jquery-plugin-addAriaLabelledBy.expected.js",
"utf8"
);
const config = JSON.parse(
fs.readFileSync(
rootDir + "jquery-plugin-addAriaLabelledBy.config.json",
"utf8"
)
);
const module = new CustomFileInfo(
rootDir + "jquery-plugin-addAriaLabelledBy.js"
);
analyseMigrateAndTest(
module,
true,
expectedContent,
config,
done,
[]
);
});

it("Identify zIndex calls", done => {
const expectedContent = fs.readFileSync(
rootDir + "zIndex.expected.js",
Expand Down

0 comments on commit 21fca37

Please sign in to comment.