Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

fix: Fix false positives for comment lookup #32

Merged
merged 1 commit into from
Apr 25, 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
26 changes: 26 additions & 0 deletions src/transformers/addMigrationComments/addMigrationComments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ function doSomethingElse() {
);
});

it('works with TS', async () => {
tmpDir = makeTmpDir(getFixturePath('addMigrationComments'));
const file = 'noFalsePositives.ts';
const files = [`${tmpDir}/${file}`];
await tracingConfigTransformer.transform(files, { filePatterns: [] });

const actual = getDirFileContent(tmpDir, file);

assertStringEquals(
actual,
`function indexMembersByProject(members: Member[]): IndexedMembersByProject {
return members.reduce<IndexedMembersByProject>((acc, member) => {
for (const project of member.projects) {
if (!acc.hasOwnProperty(project)) {
acc[project] = [];
}
if (member.user) {
acc[project].push(member.user);
}
}
return acc;
}, {});
}`
);
});

it('works with span.startChild', async () => {
tmpDir = makeTmpDir(getFixturePath('addMigrationComments'));
const file = 'startChild.js';
Expand Down
21 changes: 13 additions & 8 deletions src/transformers/addMigrationComments/transform.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ module.exports = function (fileInfo, api) {
return wrapJscodeshift(j, source, fileName, (j, source) => {
const tree = j(source);

/** @type {Record<string,string>} */
const methodCommentMap = {
startTransaction:
const methodCommentMap = new Map([
[
'startTransaction',
'Use `startInactiveSpan()` instead - see https://github.com/getsentry/sentry-javascript/blob/develop/docs/v8-new-performance-apis.md',
startChild:
],
[
'startChild',
'Use `startInactiveSpan()` instead - see https://github.com/getsentry/sentry-javascript/blob/develop/docs/v8-new-performance-apis.md',
makeMain:
],
[
'makeMain',
'Use `setCurrentClient()` instead - see https://github.com/getsentry/sentry-javascript/blob/develop/docs/v8-initializing.md',
};
],
]);

// Find `xxx()` calls
tree
Expand All @@ -33,7 +38,7 @@ module.exports = function (fileInfo, api) {
})
.forEach(path => {
if (path.value.callee.type === 'Identifier') {
const comment = methodCommentMap[path.value.callee.name];
const comment = methodCommentMap.get(path.value.callee.name);
if (comment) {
addTodoComment(j, path, comment);
}
Expand All @@ -52,7 +57,7 @@ module.exports = function (fileInfo, api) {
})
.forEach(path => {
if (path.value.callee.type === 'MemberExpression' && path.value.callee.property.type === 'Identifier') {
const comment = methodCommentMap[path.value.callee.property.name];
const comment = methodCommentMap.get(path.value.callee.property.name);
if (comment) {
addTodoComment(j, path, comment);
}
Expand Down
13 changes: 13 additions & 0 deletions test-fixtures/addMigrationComments/noFalsePositives.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function indexMembersByProject(members: Member[]): IndexedMembersByProject {
return members.reduce<IndexedMembersByProject>((acc, member) => {
for (const project of member.projects) {
if (!acc.hasOwnProperty(project)) {
acc[project] = [];
}
if (member.user) {
acc[project].push(member.user);
}
}
return acc;
}, {});
}
Loading