Ejemplo n.º 1
0
        private bool AnalyzeSourceFile(ISourceFile file, RuleAnalysisScope analysisScope, Logger logger, LoggingContext loggingContext, PathTable pathTable, Workspace workspace = null)
        {
            var context = new DiagnosticContext(file, analysisScope, logger, loggingContext, pathTable, workspace);

            // If the file is a public facade one, we don't need to run any linter rule on it since its original version has been already validated
            if (file.IsPublicFacade)
            {
                return(true);
            }

            VisitFile(file, context);

            return(logger.HasErrors);
        }
Ejemplo n.º 2
0
        private void ParallelVisitNode(INode node, DiagnosticContext context)
        {
            ParallelAlgorithms.WhileNotEmpty(new[] { node }, (item, adder) =>
            {
                // Only non-injected nodes are checked by the linter.
                if (item.IsInjectedForDScript())
                {
                    return;
                }

                Handle(item, context);
                using (var list = NodeWalker.GetChildrenFast(item))
                {
                    foreach (var child in list.Instance)
                    {
                        foreach (var e in child)
                        {
                            adder(e);
                        }
                    }
                }
            });
        }
Ejemplo n.º 3
0
        private static QualifierSpaceDeclaration ExtractQualifierSpace(IObjectLiteralExpression objectLiteral, DiagnosticContext context, bool emitLogEvents)
        {
            QualifierSpaceDeclaration result = new QualifierSpaceDeclaration();
            bool hasErrors = false;

            foreach (var objectLiteralElement in objectLiteral.Properties)
            {
                switch (objectLiteralElement.Kind)
                {
                case TypeScript.Net.Types.SyntaxKind.PropertyAssignment:
                {
                    var propertyAssignment = objectLiteralElement.Cast <IPropertyAssignment>();
                    var initializer        = propertyAssignment.Initializer;
                    var valueSpace         = initializer.As <IArrayLiteralExpression>();
                    if (valueSpace == null || valueSpace.Elements.Count == 0)
                    {
                        if (emitLogEvents)
                        {
                            context.Logger.ReportQualifierSpacePossibleValuesMustBeNonEmptyArrayLiteral(
                                context.LoggingContext,
                                initializer.LocationForLogging(context.SourceFile));
                        }

                        hasErrors = true;
                    }
                    else
                    {
                        var values = ExtractQualifierSpaceValues(valueSpace, context, emitLogEvents);
                        if (values == null)
                        {
                            hasErrors = true;
                        }
                        else
                        {
                            var text = propertyAssignment.Name.Text;
                            if (!QualifierTable.IsValidQualifierKey(text))
                            {
                                if (emitLogEvents)
                                {
                                    context.Logger.ReportQualifierSpaceValueMustBeValidKey(context.LoggingContext, propertyAssignment.LocationForLogging(context.SourceFile), text);
                                }

                                hasErrors = true;
                            }
                            else
                            {
                                result.Add(propertyAssignment.Name.Text, values);
                            }
                        }
                    }

                    break;
                }

                case TypeScript.Net.Types.SyntaxKind.ShorthandPropertyAssignment:
                {
                    if (emitLogEvents)
                    {
                        context.Logger.ReportQualifierSpacePropertyCannotBeInShorthand(
                            context.LoggingContext,
                            objectLiteralElement.LocationForLogging(context.SourceFile));
                    }

                    hasErrors = true;
                    break;
                }
                }
            }

            return(hasErrors ? null : result);
        }
Ejemplo n.º 4
0
        private static List <string> ExtractQualifierSpaceValues(IArrayLiteralExpression valueSpace, DiagnosticContext context, bool emitLogEvents)
        {
            var  values    = new List <string>(valueSpace.Elements.Count);
            bool hasErrors = false;

            foreach (var value in valueSpace.Elements)
            {
                if (value.Kind != TypeScript.Net.Types.SyntaxKind.StringLiteral)
                {
                    if (emitLogEvents)
                    {
                        context.Logger.ReportQualifierSpaceValueMustBeStringLiteral(context.LoggingContext, value.LocationForLogging(context.SourceFile));
                    }

                    hasErrors = true;
                }

                var text = value.Cast <IStringLiteral>().Text;
                if (!QualifierTable.IsValidQualifierValue(text))
                {
                    if (emitLogEvents)
                    {
                        context.Logger.ReportQualifierSpaceValueMustBeValidValue(context.LoggingContext, value.LocationForLogging(context.SourceFile), text);
                    }

                    hasErrors = true;
                }

                values.Add(text);
            }

            return(hasErrors ? null : values);
        }