/// <summary> /// Validates that importFrom is used in package and root config files in V1, where the argument passed to importFrom is not a package name. /// </summary> protected override void ValidateImportFrom(IExpression argument, ILiteralExpression stringLiteral, DiagnosticContext context) { string text = stringLiteral?.Text; if (!string.IsNullOrEmpty(text)) { if (ImportPathHelpers.IsPackageName(text)) { // add error because importFrom must be passed file names, not package names context.Logger.ReportNamedImportInConfigOrPackage( context.LoggingContext, argument.LocationForLogging(context.SourceFile), Names.InlineImportFunction, argument.GetFormattedText()); } CheckForFilesThatExposeNothing(text, argument, Names.InlineImportFunction, context); } }
/// <summary> /// Validates that the module specifier of the inline import is a string literal. /// </summary> protected override void ValidateImportFrom(IExpression argument, ILiteralExpression stringLiteral, DiagnosticContext context) { if (stringLiteral == null || stringLiteral.As <IStringLiteral>()?.LiteralKind == LiteralExpressionKind.None) { // Must pass a string literal to importFrom context.Logger.ReportImportFromNotPassedAStringLiteral( context.LoggingContext, argument.LocationForLogging(context.SourceFile), argument.GetFormattedText()); } // V2 validation if (context.Workspace?.SpecBelongsToImplicitSemanticsModule(context.SourceFile.GetAbsolutePath(context.PathTable)) ?? false) { string text = stringLiteral?.Text; if (!string.IsNullOrEmpty(text)) { if (!ImportPathHelpers.IsPackageName(text)) { // add error because importFrom must be passed package names context.Logger.ReportImportFromV2Package( context.LoggingContext, argument.LocationForLogging(context.SourceFile), argument.GetFormattedText()); } else if (text.IndexOfAny(ImportPathHelpers.InvalidPackageChars) != -1) { context.Logger.ReportNamedImportInConfigOrPackageLikePath( context.LoggingContext, argument.LocationForLogging(context.SourceFile), Names.InlineImportFunction, argument.GetFormattedText()); } } } }