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 void JsonTest()
        {
            var config = new TSQLLintConfiguration
            {
                Rules = new Dictionary <string, string>
                {
                    { "rule1", "error" },
                    { "rule2", "off" }
                },
                Plugins = new Dictionary <string, string>
                {
                    { "tuna-plugin", "plugins/tuna-plugin/TunaPlugin.dll" }
                },
                CompatibilityLevel = 120
            };

            var configJSON =
                "{\"rules\":{\"rule1\": \"error\",\"rule2\": \"off\"},\"plugins\":{\"tuna-plugin\": \"plugins/tuna-plugin/TunaPlugin.dll\"},\"compatability-level\": 120}";

            Assert.Equal(config.ToString(),
                         JsonConvert.DeserializeObject <TSQLLintConfiguration>(configJSON).ToString());
        }