/// <summary> /// Generates a property directive for the specified document. /// </summary> /// <param name="document">The document.</param> public void GeneratePropertyDirective(Document document) { const string UnixLineEnding = "\n"; var settings = this.LoadSettings(document.ProjectItem.ContainingProject); using (var jsLintContext = this.jsLintFactory()) { var docAccess = document.Access(); var results = jsLintContext.Lint(docAccess.Source, settings.Options, settings.GlobalVariables); var propertyDirective = results.PropertyDirective; if (string.IsNullOrEmpty(propertyDirective)) { return; } var lineEnding = docAccess.LineEnding; if (lineEnding != UnixLineEnding) { propertyDirective = propertyDirective.Replace(UnixLineEnding, lineEnding); } var existing = results.Directives.FirstOrDefault(x => x.Directive == "property"); var startPoint = docAccess.TextDocument.StartPoint.CreateEditPoint(); if (existing != null) { var lines = existing.Value.Count - 1; var endLine = existing.Line + 1; var endChar = existing.Thru + 1; var startLine = endLine - lines; var startChar = existing.From + 1; startPoint.MoveToLineAndOffset(startLine, startChar); var endPoint = startPoint.CreateEditPoint(); if (lines > 0) { endPoint.LineDown(lines); endPoint.CharRight(endChar); } else { endPoint.CharRight(endChar - existing.From); } startPoint.ReplaceText(endPoint, propertyDirective, (int)(vsEPReplaceTextOptions.vsEPReplaceTextNormalizeNewlines | vsEPReplaceTextOptions.vsEPReplaceTextAutoformat)); } else { startPoint.Insert(propertyDirective); } } }
/// <summary> /// Validates the specified document using JSLint. /// </summary> /// <param name="document">The document.</param> /// <param name="settings">The settings.</param> /// <returns> /// The total number of JSLint errors found. /// </returns> public int LintDocument(Document document, JSLintNetSettings settings) { this.errorListProvider.ClearJSLintErrors(document.FullName); int errors; var source = document.Access().Source; var hierarchy = this.GetHierarchy(document.ProjectItem.ContainingProject); using (var jsLintContext = this.jsLintFactory()) { var result = jsLintContext.Lint(source, settings.Options, settings.GlobalVariables); this.errorListProvider.AddJSLintErrors(document.FullName, result.Warnings, settings.Output, hierarchy); errors = result.Warnings.Count; var text = GetMessageText(errors); this.SetStatusBar(text); } return(errors); }
/// <summary> /// Validates the specified document using JSLint. /// </summary> /// <param name="document">The document.</param> /// <param name="settings">The settings.</param> /// <returns> /// The total number of JSLint errors found. /// </returns> public int LintDocument(Document document, JSLintNetSettings settings) { this.errorListProvider.ClearJSLintErrors(document.FullName); int errors; var source = document.Access().Source; var hierarchy = this.GetHierarchy(document.ProjectItem.ContainingProject); using (var jsLintContext = this.jsLintFactory.CreateContext()) { var result = jsLintContext.Lint(source, settings.Options); this.errorListProvider.AddJSLintErrors(document.FullName, result.Errors, settings.Output, hierarchy); errors = result.Errors.Count; var text = GetMessageText(errors); this.SetStatusBar(text); } return errors; }