<commit_before>﻿namespace StyleCop.Analyzers.LayoutRules
{
    using System.Collections.Immutable;

    using Microsoft.CodeAnalysis;
    using Microsoft.CodeAnalysis.CSharp;
    using Microsoft.CodeAnalysis.CSharp.Syntax;
    using Microsoft.CodeAnalysis.Diagnostics;

    /// <summary>
    /// A C# statement containing opening and closing curly brackets is written completely on a single line.
    /// </summary>
    /// <remarks>
    /// <para>A violation of this rule occurs when a statement that is wrapped in opening and closing curly brackets is
    /// written on a single line. For example:</para>
    ///
    /// <code language="csharp">
    /// public object Method()
    /// {
    ///     lock (this) { return this.value; }
    /// }
    /// </code>
    ///
    /// <para>When StyleCop checks this code, a violation of this rule will occur because the entire lock statement is
    /// written on one line. The statement should be written across multiple lines, with the opening and closing curly
    /// brackets each on their own line, as follows:</para>
    ///
    /// <code language="csharp">
    /// public object Method()
    /// {
    ///     lock (this) 
    ///     {
    ///         return this.value; 
    ///     }
    /// }
    /// </code>
    /// </remarks>
    [DiagnosticAnalyzer(LanguageNames.CSharp)]
    public class SA1501StatementMustNotBeOnASingleLine : DiagnosticAnalyzer
    {
        /// <summary>
        /// The ID for diagnostics produced by the <see cref="SA1501StatementMustNotBeOnASingleLine"/> analyzer.
        /// </summary>
        public const string DiagnosticId = "SA1501";
        private const string Title = "Statement must not be on a single line";
        private const string MessageFormat = "Statement must not be on a single line";
        private const string Category = "StyleCop.CSharp.LayoutRules";
        private const string Description = "A C# statement containing opening and closing curly brackets is written completely on a single line.";
        private const string HelpLink = "http://www.stylecop.com/docs/SA1501.html";

        private static readonly DiagnosticDescriptor Descriptor =
            new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, true, Description, HelpLink);

        private static readonly ImmutableArray<DiagnosticDescriptor> SupportedDiagnosticsValue =
            ImmutableArray.Create(Descriptor);

        /// <inheritdoc/>
        public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
        {
            get
            {
                return SupportedDiagnosticsValue;
            }
        }

        /// <inheritdoc/>
        public override void Initialize(AnalysisContext context)
        {
            context.RegisterSyntaxNodeAction(this.HandleBlock, SyntaxKind.Block);
        }

        private void HandleBlock(SyntaxNodeAnalysisContext context)
        {
            var block = context.Node as BlockSyntax;
            if ((block != null) && 
                !block.OpenBraceToken.IsMissing && 
                !block.CloseBraceToken.IsMissing && 
                this.IsPartOfStatement(block))
            {
                var openBraceLineNumber = block.SyntaxTree.GetLineSpan(block.OpenBraceToken.Span).StartLinePosition.Line;
                var closeBraceLineNumber = block.SyntaxTree.GetLineSpan(block.CloseBraceToken.Span).StartLinePosition.Line;

                if (openBraceLineNumber == closeBraceLineNumber)
                {
                    switch (block.Parent.Kind())
                    {
                        case SyntaxKind.AnonymousMethodExpression:
                            // Single line anonymous method declarations are allowed.
                            break;
                        case SyntaxKind.SimpleLambdaExpression:
                            // Single line lambda expressions are allowed.
                            break;
                        default:
                            context.ReportDiagnostic(Diagnostic.Create(Descriptor, block.OpenBraceToken.GetLocation()));
                            break;
                    }
                }
            }
        }

        private bool IsPartOfStatement(BlockSyntax block)
        {
            var parent = block.Parent;

            while ((parent != null) && !(parent is StatementSyntax))
            {
                parent = parent.Parent;
            }

            return parent != null;
        }
    }
}
<commit_msg>Now using AnalyzerConstants<commit_after>﻿namespace StyleCop.Analyzers.LayoutRules
{
    using System.Collections.Immutable;

    using Microsoft.CodeAnalysis;
    using Microsoft.CodeAnalysis.CSharp;
    using Microsoft.CodeAnalysis.CSharp.Syntax;
    using Microsoft.CodeAnalysis.Diagnostics;

    /// <summary>
    /// A C# statement containing opening and closing curly brackets is written completely on a single line.
    /// </summary>
    /// <remarks>
    /// <para>A violation of this rule occurs when a statement that is wrapped in opening and closing curly brackets is
    /// written on a single line. For example:</para>
    ///
    /// <code language="csharp">
    /// public object Method()
    /// {
    ///     lock (this) { return this.value; }
    /// }
    /// </code>
    ///
    /// <para>When StyleCop checks this code, a violation of this rule will occur because the entire lock statement is
    /// written on one line. The statement should be written across multiple lines, with the opening and closing curly
    /// brackets each on their own line, as follows:</para>
    ///
    /// <code language="csharp">
    /// public object Method()
    /// {
    ///     lock (this) 
    ///     {
    ///         return this.value; 
    ///     }
    /// }
    /// </code>
    /// </remarks>
    [DiagnosticAnalyzer(LanguageNames.CSharp)]
    public class SA1501StatementMustNotBeOnASingleLine : DiagnosticAnalyzer
    {
        /// <summary>
        /// The ID for diagnostics produced by the <see cref="SA1501StatementMustNotBeOnASingleLine"/> analyzer.
        /// </summary>
        public const string DiagnosticId = "SA1501";
        private const string Title = "Statement must not be on a single line";
        private const string MessageFormat = "Statement must not be on a single line";
        private const string Category = "StyleCop.CSharp.LayoutRules";
        private const string Description = "A C# statement containing opening and closing curly brackets is written completely on a single line.";
        private const string HelpLink = "http://www.stylecop.com/docs/SA1501.html";

        private static readonly DiagnosticDescriptor Descriptor =
            new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);

        private static readonly ImmutableArray<DiagnosticDescriptor> SupportedDiagnosticsValue =
            ImmutableArray.Create(Descriptor);

        /// <inheritdoc/>
        public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
        {
            get
            {
                return SupportedDiagnosticsValue;
            }
        }

        /// <inheritdoc/>
        public override void Initialize(AnalysisContext context)
        {
            context.RegisterSyntaxNodeAction(this.HandleBlock, SyntaxKind.Block);
        }

        private void HandleBlock(SyntaxNodeAnalysisContext context)
        {
            var block = context.Node as BlockSyntax;
            if ((block != null) && 
                !block.OpenBraceToken.IsMissing && 
                !block.CloseBraceToken.IsMissing && 
                this.IsPartOfStatement(block))
            {
                var openBraceLineNumber = block.SyntaxTree.GetLineSpan(block.OpenBraceToken.Span).StartLinePosition.Line;
                var closeBraceLineNumber = block.SyntaxTree.GetLineSpan(block.CloseBraceToken.Span).StartLinePosition.Line;

                if (openBraceLineNumber == closeBraceLineNumber)
                {
                    switch (block.Parent.Kind())
                    {
                        case SyntaxKind.AnonymousMethodExpression:
                            // Single line anonymous method declarations are allowed.
                            break;
                        case SyntaxKind.SimpleLambdaExpression:
                            // Single line lambda expressions are allowed.
                            break;
                        default:
                            context.ReportDiagnostic(Diagnostic.Create(Descriptor, block.OpenBraceToken.GetLocation()));
                            break;
                    }
                }
            }
        }

        private bool IsPartOfStatement(BlockSyntax block)
        {
            var parent = block.Parent;

            while ((parent != null) && !(parent is StatementSyntax))
            {
                parent = parent.Parent;
            }

            return parent != null;
        }
    }
}

{'fraction_non_alphanumeric': 0.08851990323290082, 'fraction_numerical': 0.003518803606773697, 'mean_word_length': 1.8510971786833856, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '423952', 'n_tokens_mistral': 2251, 'n_tokens_neox': 2102, 'n_words': 604}