Exemple #1
0
        public static void Main(string[] args)
        {
            args.ValidateNotNullParameter(nameof(args));

            if (args.Length != 1)
            {
                Console.Write("Must specify exactly one argument which is the path to the file to analyze.");
                Environment.Exit(1);
            }

            var filePath = args[0];

            if (!File.Exists(filePath))
            {
                Console.Write("The specified file could not be found.");
                Environment.Exit(1);
            }

            var csharpSource = File.ReadAllText(filePath);

            var analyzer = new Analyzer();
            var issues   = analyzer.Analyze(filePath, csharpSource);
            var result   = new LintResults(issues, filePath);

            Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
        }
Exemple #2
0
        public async Task RenderAsync(CancellationToken cancellationToken = default)
        {
            var tableMessages = await Linter.AnalyseTables(Tables, cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false);

            var viewMessages = await Linter.AnalyseViews(Views, cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false);

            var sequenceMessages = await Linter.AnalyseSequences(Sequences, cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false);

            var synonymMessages = await Linter.AnalyseSynonyms(Synonyms, cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false);

            var routineMessages = await Linter.AnalyseRoutines(Routines, cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false);

            var messages = tableMessages
                           .Concat(viewMessages)
                           .Concat(sequenceMessages)
                           .Concat(synonymMessages)
                           .Concat(routineMessages);

            var groupedRules = messages
                               .GroupBy(m => m.RuleId)
                               .Select(m => new LintResults.LintRule(m.First().Title, m.Select(r => new HtmlString(r.Message)).ToList()))
                               .ToList();

            var templateParameter = new LintResults(groupedRules);
            var renderedLint      = await Formatter.RenderTemplateAsync(templateParameter, cancellationToken).ConfigureAwait(false);

            var databaseName = !IdentifierDefaults.Database.IsNullOrWhiteSpace()
                ? IdentifierDefaults.Database + " Database"
                : "Database";
            var pageTitle     = "Lint · " + databaseName;
            var lintContainer = new Container(renderedLint, pageTitle, string.Empty);
            var renderedPage  = await Formatter.RenderTemplateAsync(lintContainer, cancellationToken).ConfigureAwait(false);

            if (!ExportDirectory.Exists)
            {
                ExportDirectory.Create();
            }
            var outputPath = Path.Combine(ExportDirectory.FullName, "lint.html");

            using var writer = File.CreateText(outputPath);
            await writer.WriteAsync(renderedPage.AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.FlushAsync().ConfigureAwait(false);
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            var kernel = new StandardKernel();

            kernel.Load <CSharpLibraryNinjectModule>();

            string settings = null;
            string root     = null;
            bool   version  = false;
            bool   help     = false;
            var    options  = new OptionSet
            {
                { "s|settings=", v => settings = v },
                { "settings-base64=", v => settings =
                      Encoding.ASCII.GetString(Convert.FromBase64String(v)) },
                { "r|root=", v => root = v },
                { "h|help", v => help = true },
                { "v|version", v => version = true }
            };

            List <string> files;

            try
            {
                files = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("cslint: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `cslint --help' for more information.");
                return;
            }

            if (version)
            {
                Console.WriteLine("1");
                return;
            }

            if (help)
            {
                ShowHelp(options);
                return;
            }

            if (files.Count == 0)
            {
                Console.Write("cslint: ");
                Console.WriteLine("You must supply at least one file to lint.");
                Console.WriteLine("Try `cslint --help' for more information.");
                return;
            }

            if (!files.All(File.Exists))
            {
                Console.Write("cslint: ");
                Console.WriteLine("Unable to locate one or more files specified.");
                Console.WriteLine("Try `cslint --help' for more information.");
                return;
            }

            var settingsJson = new JsonSettings(settings);

            kernel.Bind <ISettings>().ToMethod(x => settingsJson);

            var allResults = new List <LintResults>();

            foreach (var file in files)
            {
                var results = new LintResults();
                results.FileName = new FileInfo(file).FullName;
                results.BaseName = new FileInfo(file).Name;

                if (root != null && Directory.Exists(root))
                {
                    Directory.SetCurrentDirectory(root);
                }

                if (results.FileName.StartsWith(Environment.CurrentDirectory))
                {
                    results.FileName = results.FileName.Substring(Environment.CurrentDirectory.Length + 1);
                }

                var linters = kernel.GetAll <ILinter>();
                foreach (var linter in linters)
                {
                    linter.Process(results);
                }

                allResults.Add(results);
            }

            Console.Write(JsonConvert.SerializeObject(allResults));
        }