Esempio n. 1
0
		private static void Main(string[] args)
		{
			if (args.Length != 2)
			{
				Console.WriteLine(string.Concat("scan list was not entered ",
					Environment.NewLine,
					"CodeSpell.exe <ReportOutputPath> <FilesSpecsPath>",
					Environment.NewLine,
					"Example - ",
					Environment.NewLine,
					"CodeSpell.exe \"Report.xml\" \"FilesSearchRules.txt\""));
			}
			else
			{
				var fileset = new HashSet<string>();
				var filesetToExclude = new HashSet<string>();
				var reportName = args[0];
				var fileSpecsPath = args[1];

				var fileSpecs = GetFileSpecs(fileSpecsPath);

				using (var writer = new XmlErrorWriter(reportName))
				{
					foreach (var fileSpec in fileSpecs)
					{
						if (fileSpec.StartsWith("-:"))
						{
							filesetToExclude.UnionWith(FileMatcher.GetFiles("", fileSpec.Remove(0, 2)));
						}
						else
						{
							fileset.UnionWith(FileMatcher.GetFiles("", fileSpec));
						}
					}

					fileset.ExceptWith(filesetToExclude);
					var engine = new SpellCheckEngine();

					var misspellingCount = engine.AnalyzeFilesForMispellings(fileset, writer);

					Console.WriteLine("##teamcity[buildStatisticValue key='misspellingCount' value='" + misspellingCount + "']");
				}
			}
		}
Esempio n. 2
0
		public int AnalyzeFilesForMispellings(IEnumerable<string> fileset,XmlErrorWriter writer)
		{
			var builder = new StringBuilder();

			int misspellingCount = 0;

			foreach (var file in fileset)
			{
				var analyzer = _spellingAnalyzerDictionary.ContainsKey(Path.GetExtension(file))
								   ? _spellingAnalyzerDictionary[Path.GetExtension(file)]
								   : _spellingAnalyzerDictionary[".cs"];

				var spellingErrors = analyzer.GetMisspellings(File.ReadAllText(file));

				foreach (var spelling in spellingErrors)
				{
					misspellingCount++;
					writer.AddError(file,spelling);
				}
			}
			Report = builder.ToString();
			return misspellingCount;
		}