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

Add [CodeCopiedFromAttribute] support #9201

Open
martin-strecker-sonarsource opened this issue Apr 24, 2024 · 0 comments
Open

Add [CodeCopiedFromAttribute] support #9201

martin-strecker-sonarsource opened this issue Apr 24, 2024 · 0 comments
Labels
Type: Improvement Making existing code better.

Comments

@martin-strecker-sonarsource
Copy link
Contributor

As described in this working document, we want to add a CodeCopiedFromAttribute to our code base, to mark code snippets from well-known sources. https://docs.google.com/document/d/1WgxCWCFyKt2mI46U83fWkpea06NT-EmwWIa_XmvWLM0/edit

A first attempt was implemented here, but needed to be reverted/removed, because the coverage exclusion did not work.
#8947 (comment)

This issue is about re-introducing the attribute and marking all existing code that was copied from Roslyn or StyleCop with the attribute instead. The attribute API can be found here:
https://github.com/SonarSource/sonar-dotnet/blob/f42578d120d51c4648ce51c1694573e9ee2c7808/analyzers/src/SonarAnalyzer.Common/Helpers/CodeCopiedFromAttribute.cs

/*
 * SonarAnalyzer for .NET
 * Copyright (C) 2015-2024 SonarSource SA
 * mailto: contact AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

namespace SonarAnalyzer.Helpers;

public enum TrustedCodeSource
{
    Roslyn,
    StyleCop
}

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property,
    AllowMultiple = true, Inherited = false)]
public sealed class CodeCopiedFromAttribute : Attribute
{
    public CodeCopiedFromAttribute(TrustedCodeSource trustedCodeSource, string permanentUrl)
    {
        TrustedCodeSource = trustedCodeSource;
        PermanentUrl = permanentUrl;
    }

    public TrustedCodeSource TrustedCodeSource { get; }
    public string PermanentUrl { get; }
    public string Reasoning {  get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Making existing code better.
Projects
None yet
Development

No branches or pull requests

1 participant