/// <summary> /// Normalizes the ignore list to a new clone. /// </summary> /// <returns>A normalized clone of the ignore list.</returns> public IList <string> NormalizeIgnore() { var clone = new List <string>(); if (this.Ignore != null) { var directorySeparator = Path.DirectorySeparatorChar.ToString(); for (int i = 0; i < this.Ignore.Count; i++) { var normalized = this.Ignore[i]; normalized = normalized.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (!normalized.StartsWith(directorySeparator)) { normalized = directorySeparator + normalized; } if (!JSLint.CanLint(normalized) && !normalized.EndsWith(directorySeparator)) { normalized += directorySeparator; } clone.Add(normalized); } } return(clone); }
private void OnBeforeCodeWindowRun(object sender, EventArgs e) { var menuCommand = (OleMenuCommand)sender; var document = this.Environment.ActiveDocument; menuCommand.Visible = document != null && JSLint.CanLint(document.Name); }
private bool IsSelectionLintable() { var selectedItems = this.Environment.SelectedItems; return(selectedItems.Count > 0 && selectedItems .OfType <SelectedItem>() .All(x => JSLint.CanLint(x.Name))); }
private void OnCodeWindowGenerateProperty(object sender, EventArgs e) { var document = this.Environment.ActiveDocument; if (document != null && JSLint.CanLint(document.Name)) { this.VisualStudioJSLintProvider.GeneratePropertyDirective(document); } }
private void OnBeforeItemNodeIgnore(object sender, EventArgs e) { var menuCommand = (OleMenuCommand)sender; var selections = this.Environment.SelectedItems; menuCommand.Visible = selections.Count == 1 && JSLint.CanLint(selections.Item(1).Name); this.SetIgnoreMenuItemState(menuCommand, selections); }
private void OnDocumentSaved(Document document) { if (JSLint.CanLint(document.Name)) { var settings = this.VisualStudioJSLintProvider.LoadSettings(document.ProjectItem.ContainingProject); var ignored = settings.NormalizeIgnore(); if (settings.RunOnSave.GetValueOrDefault() && !document.ProjectItem.Is().Ignored(ignored)) { this.VisualStudioJSLintProvider.LintDocument(document, settings); } } }
public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag { var doc = GetBufferProperty <ITextDocument>(buffer); if (doc != null) { var fileName = doc.FilePath; if (JSLint.CanLint(fileName)) { return(buffer.Properties.GetOrCreateSingletonProperty(() => (ITagger <T>) new JSLintTagger(buffer, this.ErrorListProvider, fileName))); } } return(null); }
private static void AddLintable(ProjectItem projectItem, List <ProjectItem> projectItemList, IList <string> ignore) { var fileName = projectItem.Access().FileName; if (!projectItem.Is().Folder) { if (JSLint.CanLint(fileName) && !projectItem.Is().Ignored(ignore)) { projectItemList.Add(projectItem); } return; } foreach (ProjectItem subItem in projectItem.ProjectItems) { AddLintable(subItem, projectItemList, ignore); } }
private IList <ProjectItem> SelectedLintables() { var selectedItems = this.Environment.SelectedItems; var projectItems = new List <ProjectItem>(); foreach (SelectedItem selectedItem in selectedItems) { if (JSLint.CanLint(selectedItem.Name)) { var projectItem = selectedItem.ProjectItem; if (projectItem != null) { projectItems.Add(projectItem); } } } return(projectItems); }
public int Lint(ConsoleOptions options) { var sourceDirectory = options.SourceDirectory; var settings = this.settingRepository.Load(options.SettingsFile); var ignored = settings.NormalizeIgnore(); var sourceFiles = options.SourceFiles.Where(x => JSLint.CanLint(x) && !IsIgnored(sourceDirectory, x, ignored)).ToArray(); var errorLimit = settings.ErrorLimitOrDefault(); var fileLimit = settings.FileLimitOrDefault(); var exceptions = 0; using (var context = this.jsLintFactory.CreateContext()) using (var reportBuilder = this.jsLintFactory.CreateReportBuilder()) { reportBuilder.SourceDirectory = sourceDirectory; reportBuilder.AddSettings(settings.Files); foreach (var file in sourceFiles) { var relative = GetRelativePath(sourceDirectory, file); var result = ExecutionHelper.Try(() => { var source = this.fileSystemWrapper.ReadAllText(file, Encoding.UTF8); return(context.Lint(source, settings.Options)); }); if (result.Success) { var data = result.Data; var count = data.Errors.Count; reportBuilder.AddFile(relative, data); if (count > 0 && options.LogLevel == LogLevel.Verbose) { this.consoleWriter .WriteErrorLine() .WriteErrorLine(Resources.ErrorFileSummaryFormat, relative, count); foreach (var error in data.Errors) { this.consoleWriter .WriteErrorLine(4, Resources.ErrorItemFormat, error.Reason, error.Line, error.Character); } } if (reportBuilder.ErrorCount >= errorLimit) { this.consoleWriter .WriteErrorLine() .WriteErrorLine(CoreResources.ErrorLimitReachedFormat, reportBuilder.ErrorCount); break; } } else { var ex = result.Exception; this.consoleWriter .WriteErrorLine() .WriteErrorLine(Resources.ExceptionFileFormat, relative) .WriteErrorLine(ex.Message); exceptions += 1; if (exceptions >= JSLintNetSettings.ExceptionLimit) { this.consoleWriter .WriteErrorLine() .WriteErrorLine(CoreResources.ExceptionLimitReachedFormat, exceptions); break; } } if (reportBuilder.ProcessedFileCount >= fileLimit) { this.consoleWriter .WriteErrorLine() .WriteErrorLine(CoreResources.FileLimitReachedFormat, reportBuilder.ProcessedFileCount); break; } } if (options.LogLevel != LogLevel.Silent) { this.consoleWriter .WriteLine() .WriteLine(Resources.SummarySourceDirectoryFormat, reportBuilder.SourceDirectory) .WriteLine(Resources.SummarySettingsFileFormat, string.Join(", ", reportBuilder.SettingsFiles)) .WriteLine(Resources.SummaryProcessedFileCountFormat, reportBuilder.ProcessedFileCount) .WriteLine(Resources.SummaryErrorFileCountFormat, reportBuilder.ErrorFileCount) .WriteLine(Resources.SummaryErrorCountFormat, reportBuilder.ErrorCount); } if (!string.IsNullOrEmpty(options.ReportFile)) { this.fileSystemWrapper.WriteAllText(options.ReportFile, reportBuilder.ToString(), Encoding.UTF8); } return(reportBuilder.ErrorCount); } }