Skip to content

Commit

Permalink
(chocolatey#3000) Update rules to include id and help
Browse files Browse the repository at this point in the history
This commit updates the rule results and its
implemented rules to include an identifier
and optionally a url to where more information
can be found about the rule.

This is done to make it easier in the future
to add/update additional functionality in
extensions.
  • Loading branch information
AdmiringWorm committed Feb 20, 2023
1 parent a276706 commit 140155f
Show file tree
Hide file tree
Showing 17 changed files with 3,473 additions and 3,411 deletions.
1,051 changes: 526 additions & 525 deletions src/chocolatey/chocolatey.csproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System;
using System.Collections.Generic;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class EmptyOrInvalidUrlMetadataRule : MetadataRuleBase
{
public override IEnumerable<RuleResult> validate(NuspecReader reader)
{
var items = new[]
{
"projectUrl",
"projectSourceUrl",
"docsUrl",
"bugTrackerUrl",
"mailingListUrl",
"iconUrl",
"licenseUrl"
};

foreach (var item in items)
{
if (has_element(reader, item))
{
var value = get_element_value(reader, item);

if (string.IsNullOrWhiteSpace(value))
{
yield return new RuleResult(RuleType.Error, "The {0} element in the package nuspec file cannot be empty.".format_with(item));
}
else if (!Uri.TryCreate(value, UriKind.Absolute, out _))
{
yield return new RuleResult(RuleType.Error, "'{0}' is not a valid URL for the {1} element in the package nuspec file.".format_with(value, item));
}
}
}
}
}
}
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System;
using System.Collections.Generic;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class EmptyOrInvalidUrlMetadataRule : MetadataRuleBase
{
public override IEnumerable<RuleResult> validate(NuspecReader reader)
{
var items = new[]
{
"projectUrl",
"projectSourceUrl",
"docsUrl",
"bugTrackerUrl",
"mailingListUrl",
"iconUrl",
"licenseUrl"
};

foreach (var item in items)
{
if (has_element(reader, item))
{
var value = get_element_value(reader, item);

if (string.IsNullOrWhiteSpace(value))
{
yield return new RuleResult(RuleType.Error, RuleIdentifiers.EmptyRequiredElement, "The {0} element in the package nuspec file cannot be empty.".format_with(item));
}
else if (!Uri.TryCreate(value, UriKind.Absolute, out _))
{
yield return new RuleResult(RuleType.Error, RuleIdentifiers.InvalidTypeElement, "'{0}' is not a valid URL for the {1} element in the package nuspec file.".format_with(value, item));
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System.Collections.Generic;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class FrameWorkReferencesMetadataRule : MetadataRuleBase
{
public override IEnumerable<RuleResult> validate(NuspecReader reader)
{
if (has_element(reader, "frameworkReferences"))
{
yield return new RuleResult(RuleType.Error, "<frameworkReferences> elements are not supported in Chocolatey CLI.");
}
}
}
}
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System.Collections.Generic;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class FrameWorkReferencesMetadataRule : MetadataRuleBase
{
public override IEnumerable<RuleResult> validate(NuspecReader reader)
{
if (has_element(reader, "frameworkReferences"))
{
yield return new RuleResult(RuleType.Error, RuleIdentifiers.UnsupportedElementUsed, "<frameworkReferences> elements are not supported in Chocolatey CLI.");
}
}
}
}
64 changes: 32 additions & 32 deletions src/chocolatey/infrastructure.app/rules/IconMetadataRule.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System.Collections.Generic;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class IconMetadataRule : IMetadataRule
{
public IEnumerable<RuleResult> validate(NuspecReader reader)
{
if (!(reader.GetIcon() is null))
{
yield return new RuleResult(RuleType.Error, "<icon> elements are not supported in Chocolatey CLI, use <iconUrl> instead.");
}
}
}
}
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System.Collections.Generic;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class IconMetadataRule : IMetadataRule
{
public IEnumerable<RuleResult> validate(NuspecReader reader)
{
if (!(reader.GetIcon() is null))
{
yield return new RuleResult(RuleType.Error, RuleIdentifiers.UnsupportedElementUsed, "<icon> elements are not supported in Chocolatey CLI, use <iconUrl> instead.");
}
}
}
}
66 changes: 33 additions & 33 deletions src/chocolatey/infrastructure.app/rules/LicenseMetadataRule.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class LicenseMetadataRule : IMetadataRule
{
public IEnumerable<RuleResult> validate(NuspecReader reader)
{
if (!(reader.GetLicenseMetadata() is null))
{
yield return new RuleResult(RuleType.Error, "<license> elements are not supported in Chocolatey CLI, use <licenseUrl> instead.");
}
}
}
}
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class LicenseMetadataRule : IMetadataRule
{
public IEnumerable<RuleResult> validate(NuspecReader reader)
{
if (!(reader.GetLicenseMetadata() is null))
{
yield return new RuleResult(RuleType.Error, RuleIdentifiers.UnsupportedElementUsed, "<license> elements are not supported in Chocolatey CLI, use <licenseUrl> instead.");
}
}
}
}
64 changes: 32 additions & 32 deletions src/chocolatey/infrastructure.app/rules/PackageTypesMetadataRule.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System.Collections.Generic;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class PackageTypesMetadataRule : MetadataRuleBase
{
public override IEnumerable<RuleResult> validate(NuspecReader reader)
{
if (has_element(reader, "packageTypes"))
{
yield return new RuleResult(RuleType.Error, "<packageTypes> elements are not supported in Chocolatey CLI.");
}
}
}
}
// Copyright © 2023-Present Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.rules
{
using System.Collections.Generic;
using chocolatey.infrastructure.rules;
using NuGet.Packaging;

internal sealed class PackageTypesMetadataRule : MetadataRuleBase
{
public override IEnumerable<RuleResult> validate(NuspecReader reader)
{
if (has_element(reader, "packageTypes"))
{
yield return new RuleResult(RuleType.Error, RuleIdentifiers.UnsupportedElementUsed, "<packageTypes> elements are not supported in Chocolatey CLI.");
}
}
}
}
Loading

0 comments on commit 140155f

Please sign in to comment.