protected internal StyleCopSettings(JsonObject settingsObject)
            : this()
        {
            foreach (var kvp in settingsObject)
            {
                var childSettingsObject = kvp.Value.AsJsonObject;
                switch (kvp.Key)
                {
                case "indentation":
                    kvp.AssertIsObject();
                    this.indentation = new IndentationSettings(childSettingsObject);
                    break;

                case "spacingRules":
                    kvp.AssertIsObject();
                    this.spacingRules = new SpacingSettings(childSettingsObject);
                    break;

                case "readabilityRules":
                    kvp.AssertIsObject();
                    this.readabilityRules = new ReadabilitySettings(childSettingsObject);
                    break;

                case "orderingRules":
                    kvp.AssertIsObject();
                    this.orderingRules = new OrderingSettings(childSettingsObject);
                    break;

                case "namingRules":
                    kvp.AssertIsObject();
                    this.namingRules = new NamingSettings(childSettingsObject);
                    break;

                case "maintainabilityRules":
                    kvp.AssertIsObject();
                    this.maintainabilityRules = new MaintainabilitySettings(childSettingsObject);
                    break;

                case "layoutRules":
                    kvp.AssertIsObject();
                    this.layoutRules = new LayoutSettings(childSettingsObject);
                    break;

                case "documentationRules":
                    kvp.AssertIsObject();
                    this.documentationRules = new DocumentationSettings(childSettingsObject);
                    break;

                case "alignmentRules":
                    kvp.AssertIsObject();
                    this.alignmentRules = new AlignmentSettings(childSettingsObject);
                    break;

                default:
                    break;
                }
            }
        }
 protected internal StyleCopSettings()
 {
     this.spacingRules         = new SpacingSettings();
     this.readabilityRules     = new ReadabilitySettings();
     this.orderingRules        = new OrderingSettings();
     this.namingRules          = new NamingSettings();
     this.maintainabilityRules = new MaintainabilitySettings();
     this.documentationRules   = new DocumentationSettings();
 }
 protected internal StyleCopSettings()
 {
     this.spacingRules = new SpacingSettings();
     this.readabilityRules = new ReadabilitySettings();
     this.orderingRules = new OrderingSettings();
     this.namingRules = new NamingSettings();
     this.maintainabilityRules = new MaintainabilitySettings();
     this.documentationRules = new DocumentationSettings();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="StyleCopSettings"/> class.
        /// </summary>
        protected internal StyleCopSettings()
        {
            this.indentation = new IndentationSettings();

            this.spacingRules         = new SpacingSettings();
            this.readabilityRules     = new ReadabilitySettings();
            this.orderingRules        = new OrderingSettings();
            this.namingRules          = new NamingSettings();
            this.maintainabilityRules = new MaintainabilitySettings();
            this.layoutRules          = new LayoutSettings();
            this.documentationRules   = new DocumentationSettings();
            this.alignmentRules       = new AlignmentSettings();
        }
        protected internal StyleCopSettings()
        {
            this.indentation = new IndentationSettings();

            this.spacingRules         = new SpacingSettings();
            this.readabilityRules     = new ReadabilitySettings();
            this.orderingRules        = new OrderingSettings();
            this.namingRules          = new NamingSettings();
            this.maintainabilityRules = new MaintainabilitySettings();
            this.layoutRules          = new LayoutSettings();
            this.documentationRules   = new DocumentationSettings();
            this.excludedFileFilters  = default(string[]);
            this.excludedFiles        = default(string[]);
        }
            private static bool NeedsComment(DocumentationSettings documentationSettings, SyntaxKind syntaxKind, SyntaxKind parentSyntaxKind, Accessibility declaredAccessibility, Accessibility effectiveAccessibility)
            {
                if (documentationSettings.DocumentInterfaces
                    && (syntaxKind == SyntaxKind.InterfaceDeclaration || parentSyntaxKind == SyntaxKind.InterfaceDeclaration))
                {
                    // DocumentInterfaces => all interfaces must be documented
                    return true;
                }

                if (documentationSettings.DocumentPrivateElements)
                {
                    // DocumentPrivateMembers => everything except declared private fields must be documented
                    return true;
                }

                switch (effectiveAccessibility)
                {
                case Accessibility.Public:
                case Accessibility.Protected:
                case Accessibility.ProtectedOrInternal:
                    // These items are part of the exposed API surface => document if configured
                    return documentationSettings.DocumentExposedElements;

                case Accessibility.ProtectedAndInternal:
                case Accessibility.Internal:
                    // These items are part of the internal API surface => document if configured
                    return documentationSettings.DocumentInternalElements;

                case Accessibility.NotApplicable:
                case Accessibility.Private:
                default:
                    return false;
                }
            }
 public Analyzer(AnalyzerOptions options)
 {
     StyleCopSettings settings = options.GetStyleCopSettings();
     this.documentationSettings = settings.DocumentationRules;
 }
            private static bool CompareCopyrightText(DocumentationSettings documentationSettings, string copyrightText)
            {
                // make sure that both \n and \r\n are accepted from the settings.
                var reformattedCopyrightTextParts = documentationSettings.CopyrightText.Replace("\r\n", "\n").Split('\n');
                var fileHeaderCopyrightTextParts = copyrightText.Replace("\r\n", "\n").Split('\n');

                if (reformattedCopyrightTextParts.Length != fileHeaderCopyrightTextParts.Length)
                {
                    return false;
                }

                // compare line by line, ignoring leading and trailing whitespace on each line.
                for (var i = 0; i < reformattedCopyrightTextParts.Length; i++)
                {
                    if (string.CompareOrdinal(reformattedCopyrightTextParts[i].Trim(), fileHeaderCopyrightTextParts[i].Trim()) != 0)
                    {
                        return false;
                    }
                }

                return true;
            }
            private static void CheckCompanyName(SyntaxTreeAnalysisContext context, DocumentationSettings documentationSettings, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement)
            {
                var companyName = copyrightElement.Attribute("company")?.Value;
                if (string.IsNullOrWhiteSpace(companyName))
                {
                    var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                    context.ReportDiagnostic(Diagnostic.Create(SA1640Descriptor, location));
                    return;
                }

                if (compilation.IsAnalyzerSuppressed(SA1641Identifier))
                {
                    return;
                }

                if (string.Equals(documentationSettings.CompanyName, DocumentationSettings.DefaultCompanyName, StringComparison.OrdinalIgnoreCase))
                {
                    // The company name is meaningless until configured by the user.
                    return;
                }

                if (string.CompareOrdinal(companyName, documentationSettings.CompanyName) != 0)
                {
                    var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                    context.ReportDiagnostic(Diagnostic.Create(SA1641Descriptor, location));
                }
            }
            private static void CheckCopyrightText(SyntaxTreeAnalysisContext context, DocumentationSettings documentationSettings, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement)
            {
                var copyrightText = copyrightElement.Value;
                if (string.IsNullOrWhiteSpace(copyrightText))
                {
                    var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                    context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, location));
                    return;
                }

                if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
                {
                    return;
                }

                var settingsCopyrightText = documentationSettings.CopyrightText;
                if (string.Equals(settingsCopyrightText, DocumentationSettings.DefaultCopyrightText, StringComparison.OrdinalIgnoreCase))
                {
                    // The copyright text is meaningless until the company name is configured by the user.
                    return;
                }

                // trim any leading / trailing new line or whitespace characters (those are a result of the XML formatting)
                if (!CompareCopyrightText(documentationSettings, copyrightText.Trim('\r', '\n', ' ', '\t')))
                {
                    var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                    context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, location));
                }
            }
            private static void CheckCopyrightHeader(SyntaxTreeAnalysisContext context, DocumentationSettings documentationSettings, Compilation compilation, XmlFileHeader fileHeader)
            {
                var copyrightElement = fileHeader.GetElement("copyright");
                if (copyrightElement == null)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1634Descriptor, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1637Identifier))
                {
                    CheckFile(context, compilation, fileHeader, copyrightElement);
                }

                if (!compilation.IsAnalyzerSuppressed(SA1640Identifier))
                {
                    CheckCompanyName(context, documentationSettings, compilation, fileHeader, copyrightElement);
                }

                if (!compilation.IsAnalyzerSuppressed(SA1635Identifier))
                {
                    CheckCopyrightText(context, documentationSettings, compilation, fileHeader, copyrightElement);
                }
            }
 public Analyzer(AnalyzerOptions options, CancellationToken cancellationToken)
 {
     StyleCopSettings settings = options.GetStyleCopSettings(cancellationToken);
     this.documentationSettings = settings.DocumentationRules;
 }
        protected internal StyleCopSettings(JsonObject settingsObject, AnalyzerConfigOptionsWrapper analyzerConfigOptions)
        {
            foreach (var kvp in settingsObject)
            {
                var childSettingsObject = kvp.Value.AsJsonObject;
                switch (kvp.Key)
                {
                case "indentation":
                    kvp.AssertIsObject();
                    this.indentation = new IndentationSettings(childSettingsObject, analyzerConfigOptions);
                    break;

                case "spacingRules":
                    kvp.AssertIsObject();
                    this.spacingRules = new SpacingSettings(childSettingsObject, analyzerConfigOptions);
                    break;

                case "readabilityRules":
                    kvp.AssertIsObject();
                    this.readabilityRules = new ReadabilitySettings(childSettingsObject, analyzerConfigOptions);
                    break;

                case "orderingRules":
                    kvp.AssertIsObject();
                    this.orderingRules = new OrderingSettings(childSettingsObject, analyzerConfigOptions);
                    break;

                case "namingRules":
                    kvp.AssertIsObject();
                    this.namingRules = new NamingSettings(childSettingsObject, analyzerConfigOptions);
                    break;

                case "maintainabilityRules":
                    kvp.AssertIsObject();
                    this.maintainabilityRules = new MaintainabilitySettings(childSettingsObject, analyzerConfigOptions);
                    break;

                case "layoutRules":
                    kvp.AssertIsObject();
                    this.layoutRules = new LayoutSettings(childSettingsObject, analyzerConfigOptions);
                    break;

                case "documentationRules":
                    kvp.AssertIsObject();
                    this.documentationRules = new DocumentationSettings(childSettingsObject, analyzerConfigOptions);
                    break;

                default:
                    break;
                }
            }

            this.indentation ??= new IndentationSettings(new JsonObject(), analyzerConfigOptions);

            this.spacingRules ??= new SpacingSettings(new JsonObject(), analyzerConfigOptions);
            this.readabilityRules ??= new ReadabilitySettings(new JsonObject(), analyzerConfigOptions);
            this.orderingRules ??= new OrderingSettings(new JsonObject(), analyzerConfigOptions);
            this.namingRules ??= new NamingSettings(new JsonObject(), analyzerConfigOptions);
            this.maintainabilityRules ??= new MaintainabilitySettings(new JsonObject(), analyzerConfigOptions);
            this.layoutRules ??= new LayoutSettings(new JsonObject(), analyzerConfigOptions);
            this.documentationRules ??= new DocumentationSettings(new JsonObject(), analyzerConfigOptions);
        }
 protected internal StyleCopSettings()
 {
     this.documentationRules = new DocumentationSettings();
     this.namingRules        = new NamingSettings();
 }
 protected internal StyleCopSettings()
 {
     this.documentationRules = new DocumentationSettings();
 }