Ejemplo n.º 1
0
                protected override void DefaultVisit(SyntaxNode node)
                {
                    var cfg = Configuration;

                    if (node is StatementNode stmt &&
                        !(node is ExpressionStatementNode e && e.Expression is MissingExpressionNode))
                    {
                        Linter.RunLints(SyntaxLintContexts.Statement, cfg, lint => lint.Run(stmt));
                    }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            Media.SearchPath = args[0];
            string directory = args[0];
            var    linter    = new Linter();

            CompileRecurse(linter, directory);
            Console.WriteLine("VEngine Lint program finished");
        }
Ejemplo n.º 3
0
        public bool Next()
        {
            int matched = LookAhead(out TokenEnum token, out string content, out int position, out LintType lint);

            if (Lint != lint)
            {
                Linter.Add(new LintElement(LineNumber, Position, lint)); Lint = lint;
            }

            return(DoNext(matched, token, content, position));
        }
Ejemplo n.º 4
0
        private int LookAhead(out TokenEnum token, out string content, out int position, out LintType lint)
        {
            if (lineRemaining == null)
            {
                token    = 0;
                content  = "";
                position = Position;
                lint     = LintType.NONE;
                return(0);
            }
            foreach (var def in m_tokenDefinitions)
            {
                var matched = def.Matcher.Match(lineRemaining);
                if (matched > 0)
                {
                    position = Position + matched;
                    token    = def.Token;
                    lint     = def.Lint;
                    content  = lineRemaining.Substring(0, matched);

                    // special case for linting for type
                    if (lint == LintType.VARIABLE_OR_TYPE && token == TokenEnum.VARIABLE)
                    {
                        if (Parser.TypeTokens.Contains(content))
                        {
                            lint = LintType.TYPE;
                        }
                        else
                        {
                            lint = LintType.VARIABLE;
                        }
                    }

                    // whitespace elimination
                    if (content.Trim().Length == 0)
                    {
                        DoNext(matched, token, content, position);
                        return(LookAhead(out token, out content, out position, out lint));
                    }

                    // comment elimination
                    if (token == TokenEnum.COMMENT)
                    {
                        Linter.Add(new LintElement(LineNumber, Position, LintType.COMMENT));
                        nextLine();
                        return(LookAhead(out token, out content, out position, out lint));
                    }

                    return(matched);
                }
            }
            throw new Exception(Resource.Strings.Error_Lexer_InvalidToken.F(LineNumber, Position, lineRemaining));
        }
 public static bool IsLintableTsTsxJsJsxFile(string fileName, bool checkIgnoreOptions = true)
 {
     // Check if filename is absolute because when debugging, script files are sometimes dynamically created.
     if (!IsValidFile(fileName))
     {
         return(false);
     }
     if (!Linter.IsLintableFileExtension(fileName, WebLinterPackage.Settings.LintJsFiles))
     {
         return(false);
     }
     return(IsLintableFile(fileName, checkIgnoreOptions));
 }
Ejemplo n.º 6
0
        private void Parse()
        {
            List <TaskItem> Items = new List <TaskItem>();
            int             CharIndex = -1, lineNumber = 0;

            string code = "";

            this.Invoke((MethodInvoker) delegate
            {
                code = GetText();
            });

            string[] Lines = code.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (string Line in Lines)
            {
                lineNumber++;

                foreach (string Keyword in Program.TaskKeywords)
                {
                    CharIndex = Line.IndexOf("//" + Keyword);
                    if (CharIndex >= 0)
                    {
                        Items.Add(new TaskItem()
                        {
                            Line = lineNumber, Text = Line.Substring(CharIndex + 2)
                        });
                    }
                }
            }
            this.Tasks = Items.ToArray();

            try
            {
                switch (this.Language)
                {
                case Language.RPG:
                    rpglint.Linter rpglinter = new Linter();
                    rpglinter.ParseContent(Lines);
                    this.Hints = rpglinter.GetMessages();
                    break;
                }
            }
            catch (Exception e)
            {
                Editor.TheEditor.SetStatus("Unable to lint code.");
                this.Hints = null;
            }
        }
Ejemplo n.º 7
0
        private void nextLine()
        {
            do
            {
                lineRemaining = m_reader.ReadLine();
                LineText      = lineRemaining;
                if (LineNumber > 0)
                {
                    Linter.Add(new LintElement(LineNumber, Position, LintType.NONE));
                    Lint = LintType.NONE;
                }

                ++LineNumber;
                Position      = 0;
                TokenPosition = 0;
            } while (lineRemaining != null && lineRemaining.Length == 0);
        }
Ejemplo n.º 8
0
        private static void CompileRecurse(Linter linter, string directory)
        {
            var files = Directory.GetFiles(directory);

            foreach (var f in files)
            {
                if (linter.IsEntryPoint(f))
                {
                    linter.Lint(f);
                }
            }
            var dirs = Directory.GetDirectories(directory);

            foreach (var d in dirs)
            {
                CompileRecurse(linter, d);
            }
        }
Ejemplo n.º 9
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);
        }
        public static async Task <bool> Lint(bool showErrorList, bool fixErrors, bool callSync,
                                             string[] fileNames, bool clearAllErrors, Dictionary <string, string> fileToProjectMap)
        {
#if DEBUG
            if (fileNames.Length == 0)
            {
                throw new Exception("LinterService/Lint called with empty fileNames list");
            }
#endif
            bool hasVSErrors = false;
            try
            {
                WebLinterPackage.Dte.StatusBar.Text = "Analyzing...";
                WebLinterPackage.Dte.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationGeneral);

                await CopyResourceFilesToUserProfile(false, callSync);

                Linter        linter = new Linter(WebLinterPackage.Settings, fixErrors, Logger.LogAndWarn);
                LintingResult result = await linter.Lint(callSync, fileNames);

                if (result != null)
                {
                    ErrorListService.ProcessLintingResults(result, fileNames, clearAllErrors,
                                                           showErrorList, fixErrors, fileToProjectMap);
                    hasVSErrors = result.HasVsErrors;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            finally
            {
                WebLinterPackage.Dte.StatusBar.Clear();
                WebLinterPackage.Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationGeneral);
            }
            return(hasVSErrors);
        }
Ejemplo n.º 11
0
 public static void AnalyseDatabase_GivenNullDatabase_ThrowsArgumentNullException()
 {
     Assert.That(() => Linter.AnalyseDatabase(null), Throws.ArgumentNullException);
 }
Ejemplo n.º 12
0
        public async Task <LintInspector> LintAsync(Action <Case> mockCase, CancellationToken token)
        {
            if (!this.Sanitized)
            {
                this.Sanitize();
            }


            Linter linter = new Linter(this.WorkflowManager, this.Configuration);


            List <ActivityTest> activityTests = linter.AcvityLint();
            List <ActivityTest> mockTests     = null;

            //temporarily supplant implementationmanager with fake
            IImplementationManager <TModel> holdIM = this.ImplementationManager;

            //loop through each activity in activityTests and run them
            foreach (ActivityTest at in activityTests)
            {
                foreach (Case tc in at.TestCases)
                {
                    string activityId = ConventionHelper.EnsureConvention(NamePrefixOptions.Activity, at.ActivityId, this.Configuration.Convention);
                    this.ImplementationManager = new FakeImplementationManager <TModel>(tc, this.WorkflowManager.WorkFlow, this.Configuration);
                    await this.ExecuteAsync(activityId, token);

                    tc.Trace = this.Tracer.tracer.AllNodes;
                    this.Reset(true);
                }
            }

            //restore original implementation manager
            this.ImplementationManager = holdIM;

            //if the caller provided a mock callback, then we'll
            //run through it through again, but this time using the
            //existing implementation manager.
            if (mockCase != null)
            {
                mockTests = (from t in activityTests
                             select new ActivityTest(t.ActivityId)
                {
                    TestCases = (from z in t.TestCases select(Case) z.Clone()).ToList()
                }).ToList();

                foreach (ActivityTest at in mockTests)
                {
                    foreach (Case tc in at.TestCases)
                    {
                        mockCase(tc);
                        await this.ExecuteAsync(at.ActivityId, token);

                        tc.Trace = this.Tracer.tracer.AllNodes;
                        this.Reset(true);
                    }
                }
            }

            CaseAnalyzer analyzer     = new CaseAnalyzer(this.WorkflowManager, activityTests, mockTests, this.Configuration);
            List <Audit> auditResults = analyzer.Analyze();



            int lintHash = this.WorkflowManager.WorkFlow.GetHashCode();

            return(new LintInspector(new LintResult(this.lintTracer, activityTests, null, auditResults, lintHash.ToString()), this.Workflow, this.Configuration));
            //return new LintResult(this.lintTracer, activityTests, null, auditResults, lintHash.ToString());
        }
Ejemplo n.º 13
0
 public Walker(Linter linter)
 {
     Linter = linter;
 }
Ejemplo n.º 14
0
 private static void CompileRecurse(Linter linter, string directory)
 {
     var files = Directory.GetFiles(directory);
     foreach(var f in files)
     {
         if(linter.IsEntryPoint(f))
             linter.Lint(f);
     }
     var dirs = Directory.GetDirectories(directory);
     foreach(var d in dirs)
         CompileRecurse(linter, d);
 }
Ejemplo n.º 15
0
 private static void Main(string[] args)
 {
     Media.SearchPath = args[0];
     string directory = args[0];
     var linter = new Linter();
     CompileRecurse(linter, directory);
 }
Ejemplo n.º 16
0
 public static void AnalyseRoutines_GivenNullRoutines_ThrowsArgumentNullException()
 {
     Assert.That(() => Linter.AnalyseRoutines(null), Throws.ArgumentNullException);
 }
Ejemplo n.º 17
0
        public static async Task AnalyseSynonyms_GivenEmptySynonyms_ReturnsEmptyMessages()
        {
            var messages = await Linter.AnalyseSynonyms(Array.Empty <IDatabaseSynonym>()).ToListAsync().ConfigureAwait(false);

            Assert.That(messages, Is.Empty);
        }
Ejemplo n.º 18
0
        public static async Task AnalyseDatabase_GivenEmptyDatabase_ReturnsEmptyMessages()
        {
            var messages = await Linter.AnalyseDatabase(EmptyDatabase).ToListAsync().ConfigureAwait(false);

            Assert.That(messages, Is.Empty);
        }