Beispiel #1
0
        /// <summary>
        ///     Tool integration constructor.
        ///     This will prepare everything needed for the tool to work with codacy
        ///     integration, using the Seed.
        /// </summary>
        public CodeAnalyzer() : base(sqlExtension)
        {
            timer        = new ConsoleTimer();
            reporter     = new CodacyConsoleReporter();
            configReader = new ConfigReader(reporter);

            // create temporary directory
            var tmpTSQLLintFolder = Path.Combine(Path.GetTempPath(), "tsqllint_" + Guid.NewGuid());

            Directory.CreateDirectory(tmpTSQLLintFolder);

            tmpTSQLLintPath = Path.Combine(tmpTSQLLintFolder, defaultTSQLLintConfiguration);

            var defaultTSQLLintConfigurationPath = Path.Combine("/src", defaultTSQLLintConfiguration);

            var tsqllintConfig = new TSQLLintConfiguration();

            if (!(PatternIds is null) && PatternIds.Any())
            {
                tsqllintConfig.Rules = new Dictionary <string, string>();
                foreach (var pattern in CurrentTool.Patterns)
                {
                    tsqllintConfig.Rules.Add(pattern.PatternId, "error");
                }

                foreach (var unusedPattern in Patterns.Patterns.Select(p => p.PatternId)
                         .Except(CurrentTool.Patterns.Select(p => p.PatternId)))
                {
                    tsqllintConfig.Rules.Add(unusedPattern, "off");
                }
            }
        public CodeAnalyzer() : base(visualBasicExtension)
        {
            sonarConfigurationPath = Path.Combine(DefaultSourceFolder, defaultSonarConfiguration);
            availableAnalyzers     = ImmutableArray.Create(
                new RuleFinder()
                .GetAnalyzerTypes()
                .Select(type => (DiagnosticAnalyzer)Activator.CreateInstance(type))
                .ToArray());

            var additionalFiles = new List <AnalyzerAdditionalFile>();

            if (!(PatternIds is null) && PatternIds.Any())
            {
                // create temporary directory
                this.tmpSonarLintFolder = Path.Combine(Path.GetTempPath(), "sonarlint_" + Guid.NewGuid());
                Directory.CreateDirectory(tmpSonarLintFolder);
                var tmpSonarLintPath = Path.Combine(tmpSonarLintFolder, defaultSonarConfiguration);
                var rules            = new XElement("Rules");
                foreach (var pattern in CurrentTool.Patterns)
                {
                    var parameters = new XElement("Parameters");
                    if (!(pattern.Parameters is null))
                    {
                        foreach (var parameter in pattern.Parameters)
                        {
                            var key   = new XElement("Key", parameter.Name);
                            var value = new XElement("Value", parameter.Value);
                            parameters.Add(new XElement("Parameter", key, value));
                        }
                    }

                    rules.Add(new XElement("Rule", new XElement("Key", pattern.PatternId), parameters));
                }

                new XDocument(new XElement("AnalysisInput", rules)).Save(tmpSonarLintPath);
                additionalFiles.Add(new AnalyzerAdditionalFile(tmpSonarLintPath));
            }