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: handle-empty-property-group #88

Merged
merged 1 commit into from
Jan 20, 2025
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
21 changes: 13 additions & 8 deletions lib/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,19 @@ export function getTargetFrameworksFromProjectFile(manifestFile) {
if (!projectPropertyGroup) {
return targetFrameworksResult;
}
const propertyList =
projectPropertyGroup.find((propertyGroup) => {
return (
'TargetFramework' in propertyGroup ||
'TargetFrameworks' in propertyGroup ||
'TargetFrameworkVersion' in propertyGroup
);
}) || {};
let propertyList: any = {};
try {
propertyList =
projectPropertyGroup.find((propertyGroup) => {
return (
'TargetFramework' in propertyGroup ||
'TargetFrameworks' in propertyGroup ||
'TargetFrameworkVersion' in propertyGroup
);
}) || {};
} catch (err) {
propertyList = {};
}

if (isEmpty(propertyList)) {
return targetFrameworksResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "",
"version": "",
"hasDevDependencies": false,
"dependencies": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?>
22 changes: 22 additions & 0 deletions test/lib/dependencies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ test('.Net dotnet-empty-manifest returns empty tree', async () => {
expect(tree).toEqual(expectedTree);
});

test('.Net dotnet-empty-property-group returns empty tree', async () => {
const includeDev = false;
const tree = await buildDepTreeFromFiles(
`${__dirname}/../fixtures/dotnet-empty-property-group`,
'packages.config',
includeDev,
);
const expectedTree = load('dotnet-empty-property-group/expected-tree.json');
expect(tree).toEqual(expectedTree);
});

test('.Net dotnet-invalid-manifest throws', async () => {
const unparsableManifestError =
new OpenSourceEcosystems.UnparseableManifestError(
Expand Down Expand Up @@ -196,6 +207,17 @@ test('.Net .csproj dotnet-empty-manifest returns empty tree', async () => {
expect(tree).toEqual(expectedTree);
});

test('.Net .csproj dotnet-empty-property-group returns empty tree', async () => {
const includeDev = false;
const tree = await buildDepTreeFromFiles(
`${__dirname}/../fixtures/dotnet-empty-property-group`,
'empty-property-group.csproj',
includeDev,
);
const expectedTree = load('dotnet-empty-property-group/expected-tree.json');
expect(tree).toEqual(expectedTree);
});

test('.Net .csproj core dotnet-invalid-manifest throws', async () => {
const unparsableManifestError =
new OpenSourceEcosystems.UnparseableManifestError(
Expand Down
22 changes: 22 additions & 0 deletions test/lib/target-frameworks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ describe('Target framework tests', () => {
},
);

it.concurrent(
'.Net .csproj dotnet-empty-property-group target framework extracted',
async () => {
const targetFrameworks = await extractTargetFrameworksFromFiles(
`${__dirname}/../fixtures/dotnet-empty-property-group`,
'empty-property-group.csproj',
);
expect(targetFrameworks).toEqual([]);
},
);

it.concurrent(
'.Net .csproj multiple target frameworks extracted as expected',
async () => {
Expand Down Expand Up @@ -131,6 +142,17 @@ describe('Target framework tests', () => {
},
);

it.concurrent(
'.Net packages.config dotnet-empty-property-group target framework extracted',
async () => {
const targetFrameworks = await extractTargetFrameworksFromFiles(
`${__dirname}/../fixtures/dotnet-empty-property-group`,
'packages.config',
);
expect(targetFrameworks).toEqual([]);
},
);

/*
****** project.json ******
*/
Expand Down