Exemplo n.º 1
0
        public void Initialize()
        {
            var analyzerLoader = new AnalyzerLoader(RuleSetFilePath);

            this.allAnalyzers        = analyzerLoader.GetAnalyzers();
            this.allCodeFixProviders = analyzerLoader.GetCodeFixProviders();
        }
Exemplo n.º 2
0
        // private readonly Stopwatch stopwatch = new Stopwatch();

        // [Conditional("DEBUG")]
        // private void DebugTimeLog(string message)
        // {
        //     this.logger.LogDebug($"{message} in {stopwatch.ElapsedMilliseconds}ms");
        // }

        public async Task Check(CancellationToken cancellationToken)
        {
            RuleSetFilePath      = CommandHelper.GetAbsoluteOrDefaultFilePath(RuleSetFilePath, "./stylecop.ruleset");
            StyleCopJsonFilePath = CommandHelper.GetAbsoluteOrDefaultFilePath(StyleCopJsonFilePath, "./stylecop.json");

            if (!Targets.Any())
            {
                return;
            }

            this.logger.LogDebug("Arguments ============================");
            this.logger.LogDebug($"ruleset : {RuleSetFilePath}");
            this.logger.LogDebug($"stylecop.json : {RuleSetFilePath}");
            this.logger.LogDebug($"format : {OutputFormat}");
            this.logger.LogDebug($"check : \n{string.Join("\n", Targets)}");
            this.logger.LogDebug("======================================");

            var projects = ImmutableArray.CreateBuilder <Project>();

            foreach (var target in Targets)
            {
                var targetFileOrDirectory = CommandHelper.GetAbsolutePath(target);

                var inputKind = CommandHelper.GetInputKindFromFileOrDirectory(targetFileOrDirectory);
                if (!inputKind.HasValue)
                {
                    return;
                }

                var readableProjects = inputKind.Value.ToReader().ReadAllSourceCodeFiles(targetFileOrDirectory, StyleCopJsonFilePath);
                if (readableProjects.Length == 0)
                {
                    return;
                }

                projects.AddRange(readableProjects);
            }

            var outputKind = OutputKindHelper.ToOutputKind(OutputFormat);

            if (outputKind == OutputKind.Undefined)
            {
                Console.Error.WriteLine($"output format is undefined. -f {OutputFormat}");
                return;
            }

            var analyzerLoader = new AnalyzerLoader(RuleSetFilePath);
            var analyzers      = analyzerLoader.GetAnalyzers();
            var diagnostics    = await CommandHelper.GetAnalyzerDiagnosticsAsync(
                projects.ToImmutable(),
                analyzers,
                analyzerLoader.RuleSets,
                cancellationToken).ConfigureAwait(false);

            var writer = outputKind.ToWriter();

            writer.Write(diagnostics);
        }
        public async Task Check(CancellationToken cancellationToken)
        {
            RuleSetFilePath       = CommandHelper.GetAbsoluteOrDefaultFilePath(RuleSetFilePath, "./stylecop.ruleset");
            StyleCopJsonFilePath  = CommandHelper.GetAbsoluteOrDefaultFilePath(StyleCopJsonFilePath, "./stylecop.json");
            TargetFileOrDirectory = CommandHelper.GetAbsolutePath(TargetFileOrDirectory);

            this.logger.LogDebug($"Arguments ============================");
            this.logger.LogDebug($"ruleset : {RuleSetFilePath}");
            this.logger.LogDebug($"stylecop.json : {RuleSetFilePath}");
            this.logger.LogDebug($"format : {OutputFormat}");
            this.logger.LogDebug($"check : {TargetFileOrDirectory}");
            this.logger.LogDebug($"======================================");

            var inputKind = CommandHelper.GetInputKindFromFileOrDirectory(TargetFileOrDirectory);

            if (!inputKind.HasValue)
            {
                return;
            }

            var projects = inputKind.Value.ToReader().ReadAllSourceCodeFiles(TargetFileOrDirectory, StyleCopJsonFilePath);

            if (projects.Length <= 0)
            {
                return;
            }

            var outputKind = OutputKindHelper.ToOutputKind(OutputFormat);

            if (outputKind == OutputKind.Undefined)
            {
                Console.Error.WriteLine($"output format is undefined. -f {OutputFormat}");
                return;
            }

            var analyzerLoader = new AnalyzerLoader(RuleSetFilePath);
            var analyzers      = analyzerLoader.GetAnalyzers();
            var diagnostics    = await CommandHelper.GetAnalyzerDiagnosticsAsync(projects, analyzers, cancellationToken).ConfigureAwait(false);

            var writer = outputKind.ToWriter();

            writer.Write(diagnostics);
        }