示例#1
0
        private static async Task <int> SpellcheckAsync(SpellcheckCommandLineOptions options)
        {
            if (!TryParseOptionValueAsEnumFlags(
                    options.Scope,
                    OptionNames.Scope,
                    out SpellingScopeFilter scopeFilter,
                    SpellingScopeFilter.Comment | SpellingScopeFilter.Region | SpellingScopeFilter.Symbol))
            {
                return(ExitCodes.Error);
            }

            if (!TryParseOptionValueAsEnumFlags(options.IgnoredScope, OptionNames.IgnoredScope, out SpellingScopeFilter ignoredScopeFilter, SpellingScopeFilter.None))
            {
                return(ExitCodes.Error);
            }

            scopeFilter &= ~ignoredScopeFilter;

            if (!TryParseOptionValueAsEnum(options.Visibility, OptionNames.Visibility, out Visibility visibility))
            {
                return(ExitCodes.Error);
            }

            if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))
            {
                return(ExitCodes.Error);
            }

            if (!ParseHelpers.TryEnsureFullPath(options.Words, out ImmutableArray <string> wordListPaths))
            {
                return(ExitCodes.Error);
            }

            if (!TryParsePaths(options.Paths, out ImmutableArray <string> paths))
            {
                return(ExitCodes.Error);
            }

            WordListLoaderResult loaderResult = WordListLoader.Load(
                wordListPaths,
                options.MinWordLength,
                options.MaxWordLength,
                (options.CaseSensitive) ? WordListLoadOptions.None : WordListLoadOptions.IgnoreCase);

            var data = new SpellingData(loaderResult.List, loaderResult.CaseSensitiveList, loaderResult.FixList);

            var command = new SpellcheckCommand(options, projectFilter, data, visibility, scopeFilter);

            CommandStatus status = await command.ExecuteAsync(paths, options.MSBuildPath, options.Properties);

            return(GetExitCode(status));
        }
        internal bool TryGetProjectFilter(out ProjectFilter projectFilter)
        {
            projectFilter = default;

            string language = null;

            if (Language != null &&
                !ParseHelpers.TryParseLanguage(Language, out language))
            {
                return(false);
            }

            if (Projects?.Any() == true &&
                IgnoredProjects?.Any() == true)
            {
                Logger.WriteLine($"Cannot specify both '{ParameterNames.Projects}' and '{ParameterNames.IgnoredProjects}'.", Roslynator.Verbosity.Quiet);
                return(false);
            }

            projectFilter = new ProjectFilter(Projects, IgnoredProjects, language);
            return(true);
        }
示例#3
0
        public static bool TryCreateFromCodeFile <TDelegate>(
            string filePath,
            Type returnType,
            Type parameterType,
            out TDelegate result) where TDelegate : Delegate
        {
            if (!ParseHelpers.TryReadAllText(filePath, out string content, f => Logger.WriteError(f)))
            {
                result = null;
                return(false);
            }

            Assembly assembly = AssemblyFactory.FromSourceText(content);

            if (assembly == null)
            {
                result = null;
                return(false);
            }

            result = CreateDelegateAndCatchIfThrows <TDelegate>(assembly, returnType, new Type[] { parameterType });
            return(result != null);
        }
示例#4
0
 internal bool TryParseDiagnosticSeverity(DiagnosticSeverity defaultValue, out DiagnosticSeverity value)
 {
     return(ParseHelpers.TryParseOptionValueAsEnum(SeverityLevel, ParameterNames.SeverityLevel, out value, defaultValue));
 }