diff --git a/EditorExtensions/Commands/JavaScript/JavaScriptCreationListener.cs b/EditorExtensions/Commands/JavaScript/JavaScriptCreationListener.cs index 4aad51e9a..4d3517b32 100644 --- a/EditorExtensions/Commands/JavaScript/JavaScriptCreationListener.cs +++ b/EditorExtensions/Commands/JavaScript/JavaScriptCreationListener.cs @@ -45,12 +45,12 @@ public void VsTextViewCreated(IVsTextView textViewAdapter) ITextDocument document; if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document)) { - var jsHintLintInvoker = new LintFileInvoker(f => new JsHintReporter(f), document); + var jsHintLintInvoker = new LintFileInvoker(f => new JavaScriptLintReporter(new JsHintCompiler(), f), document); textView.Closed += (s, e) => jsHintLintInvoker.Dispose(); textView.TextBuffer.Properties.GetOrCreateSingletonProperty(() => jsHintLintInvoker); - var jsCodeStyleLintInvoker = new LintFileInvoker(f => new LintReporter(new JsCodeStyleCompiler(), WESettings.Instance.JavaScript, f), document); + var jsCodeStyleLintInvoker = new LintFileInvoker(f => new JavaScriptLintReporter(new JsCodeStyleCompiler(), f), document); textView.Closed += (s, e) => jsCodeStyleLintInvoker.Dispose(); textView.TextBuffer.Properties.GetOrCreateSingletonProperty(() => jsCodeStyleLintInvoker); diff --git a/EditorExtensions/Commands/JavaScript/JsHintReporter.cs b/EditorExtensions/Commands/JavaScript/JavaScriptLintReporter.cs similarity index 71% rename from EditorExtensions/Commands/JavaScript/JsHintReporter.cs rename to EditorExtensions/Commands/JavaScript/JavaScriptLintReporter.cs index c5b86a661..06483321b 100644 --- a/EditorExtensions/Commands/JavaScript/JsHintReporter.cs +++ b/EditorExtensions/Commands/JavaScript/JavaScriptLintReporter.cs @@ -6,9 +6,10 @@ namespace MadsKristensen.EditorExtensions { - internal class JsHintReporter : LintReporter + internal class JavaScriptLintReporter : LintReporter { - public JsHintReporter(string fileName) : base(new JsHintCompiler(), WESettings.Instance.JavaScript, fileName) { } + public JavaScriptLintReporter(ILintCompiler lintCompiler, string fileName) : + base(lintCompiler, WESettings.Instance.JavaScript, fileName) { } public override Task RunLinterAsync() { @@ -21,7 +22,7 @@ public override Task RunLinterAsync() return base.RunLinterAsync(); } - public static bool NotJsOrIsMinifiedOrNotExists(string file) + public static bool NotJsOrMinifiedOrDocumentOrNotExists(string file) { return !Path.GetExtension(file).Equals(".js", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".min.js", StringComparison.OrdinalIgnoreCase) || @@ -33,20 +34,20 @@ public static bool NotJsOrIsMinifiedOrNotExists(string file) public static bool ShouldIgnore(string file) { - if (NotJsOrIsMinifiedOrNotExists(file)) + if (NotJsOrMinifiedOrDocumentOrNotExists(file)) { return true; } ProjectItem item = ProjectHelpers.GetProjectItem(file); - if (item == null) - return true; - - // Ignore files nested under other files such as bundle or TypeScript output - ProjectItem parent = item.Collection.Parent as ProjectItem; - if (parent != null && !Directory.Exists(parent.FileNames[1]) || File.Exists(item.FileNames[1] + ".bundle")) - return true; + if (item != null) + { + // Ignore files nested under other files such as bundle or TypeScript output + ProjectItem parent = item.Collection.Parent as ProjectItem; + if (parent != null && !Directory.Exists(parent.FileNames[1]) || File.Exists(item.FileNames[1] + ".bundle")) + return true; + } string name = Path.GetFileName(file); return _builtInIgnoreRegex.IsMatch(name); @@ -61,19 +62,19 @@ public static bool ShouldIgnore(string file) @"dojo\.js", @"ember\.js", @"ext-core\.js", - @"handlebars\.*", + @"handlebars.*", @"highlight\.js", @"history\.js", @"jquery-([0-9\.]+)\.js", - @"jquery\.blockui\.*", - @"jquery\.validate\.*", - @"jquery\.unobtrusive\.*", + @"jquery.blockui.*", + @"jquery.validate.*", + @"jquery.unobtrusive.*", @"jquery-ui-([0-9\.]+)\.js", @"json2\.js", @"knockout-([0-9\.]+)\.js", @"MicrosoftAjax([a-z]+)\.js", @"modernizr-([0-9\.]+)\.js", - @"mustache\.*", + @"mustache.*", @"prototype\.js ", @"qunit-([0-9a-z\.]+)\.js", @"require\.js", diff --git a/EditorExtensions/Commands/LintReporter.cs b/EditorExtensions/Commands/LintReporter.cs index f502b5d9e..66c21aa94 100644 --- a/EditorExtensions/Commands/LintReporter.cs +++ b/EditorExtensions/Commands/LintReporter.cs @@ -103,9 +103,27 @@ private void ReadResult(IEnumerable results) _provider.Tasks.Remove(task); } + // HACK: stop JSCS (and any other) from output more than 500 items, hope JSCS can do this + int errorLimit = 500; + int resultCount = results.Count(); + int count = 0; foreach (CompilerError error in results.Where(r => r != null)) { - ErrorTask task = CreateTask(error); + ErrorTask task; + + // JSHint has build in limit up to 500 + // the 501 one is "too many" one, no need to replace it with this hack + if (++count > errorLimit && + !(_compiler is JsHintCompiler && resultCount == 501)) + { + task = CreateTask(error, + string.Format("{0}: Too many errors. Only shows {1} errors from {2}.", + _compiler.ServiceName, errorLimit, results.Count())); + _provider.Tasks.Add(task); + break; + } + + task = CreateTask(error); _provider.Tasks.Add(task); } } @@ -116,7 +134,7 @@ private void ReadResult(IEnumerable results) } } - private ErrorTask CreateTask(CompilerError error) + private ErrorTask CreateTask(CompilerError error, string message = null) { ErrorTask task = new ErrorTask() { @@ -126,7 +144,7 @@ private ErrorTask CreateTask(CompilerError error) Category = TaskCategory.Html, Document = error.FileName, Priority = TaskPriority.Low, - Text = error.Message, + Text = message ?? error.Message, }; task.AddHierarchyItem(); diff --git a/EditorExtensions/Compilers/NodeExecutorBase.cs b/EditorExtensions/Compilers/NodeExecutorBase.cs index 48fa5dcbe..8ac9e6f7a 100644 --- a/EditorExtensions/Compilers/NodeExecutorBase.cs +++ b/EditorExtensions/Compilers/NodeExecutorBase.cs @@ -99,8 +99,11 @@ private CompilerResult ProcessResult(Process process, string errorText, string s private void ValidateResult(Process process, string outputFile, string errorText, CompilerResult result) { try - { /* Temporary hack see; //github.com/mdevils/node-jscs/issues/212 */ - if (process.ExitCode == 0 && !errorText.StartsWith("\n\n")) { if (!string.IsNullOrEmpty(outputFile)) result.Result = File.ReadAllText(outputFile); @@ -108,7 +111,7 @@ private void ValidateResult(Process process, string outputFile, string errorText } else { - result.Errors = ParseErrors(errorText.Replace("\r", "")); + result.Errors = ParseErrors(errorText); } } catch (FileNotFoundException missingFileException) diff --git a/EditorExtensions/EditorExtensionsPackage.cs b/EditorExtensions/EditorExtensionsPackage.cs index 62d4a45d8..ac2dc1930 100644 --- a/EditorExtensions/EditorExtensionsPackage.cs +++ b/EditorExtensions/EditorExtensionsPackage.cs @@ -155,9 +155,9 @@ private void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action) if (WESettings.Instance.JavaScript.LintOnBuild) { - LintFileInvoker.RunOnAllFilesInProjectAsync(".js", f => new JsHintReporter(f)) + LintFileInvoker.RunOnAllFilesInProjectAsync(".js", f => new JavaScriptLintReporter(new JsHintCompiler(), f)) .DontWait("running solution-wide JSHint"); - LintFileInvoker.RunOnAllFilesInProjectAsync(".js", f => new LintReporter(new JsCodeStyleCompiler(), WESettings.Instance.JavaScript, f)) + LintFileInvoker.RunOnAllFilesInProjectAsync(".js", f => new JavaScriptLintReporter(new JsCodeStyleCompiler(), f)) .DontWait("running solution-wide JSCS"); } diff --git a/EditorExtensions/MenuItems/JsCodeStyle.cs b/EditorExtensions/MenuItems/JsCodeStyle.cs index 071a712b0..0946c88d5 100644 --- a/EditorExtensions/MenuItems/JsCodeStyle.cs +++ b/EditorExtensions/MenuItems/JsCodeStyle.cs @@ -45,7 +45,7 @@ void menuCommand_BeforeQueryStatus(object sender, System.EventArgs e) OleMenuCommand menuCommand = sender as OleMenuCommand; files = ProjectHelpers.GetSelectedFilePaths() - .Where(f => !JsHintReporter.NotJsOrIsMinifiedOrNotExists(f)).ToList(); + .Where(f => !JavaScriptLintReporter.NotJsOrMinifiedOrDocumentOrNotExists(f)).ToList(); menuCommand.Enabled = files.Count > 0; } diff --git a/EditorExtensions/MenuItems/JsHint.cs b/EditorExtensions/MenuItems/JsHint.cs index 3e8438ae5..15e194ff4 100644 --- a/EditorExtensions/MenuItems/JsHint.cs +++ b/EditorExtensions/MenuItems/JsHint.cs @@ -44,7 +44,7 @@ void menuCommand_BeforeQueryStatus(object sender, System.EventArgs e) OleMenuCommand menuCommand = sender as OleMenuCommand; var raw = ProjectHelpers.GetSelectedFilePaths(); - files = raw.Where(f => !JsHintReporter.NotJsOrIsMinifiedOrNotExists(f)).ToList(); + files = raw.Where(f => !JavaScriptLintReporter.NotJsOrMinifiedOrDocumentOrNotExists(f)).ToList(); menuCommand.Enabled = files.Count > 0; } @@ -56,7 +56,7 @@ private void RunJsHint() foreach (string file in files) { - JsHintReporter runner = new JsHintReporter(file); + JavaScriptLintReporter runner = new JavaScriptLintReporter(new JsHintCompiler(), file); runner.RunLinterAsync().DontWait("linting " + file); } } diff --git a/EditorExtensions/Resources/settings-defaults/.jscs.json b/EditorExtensions/Resources/settings-defaults/.jscs.json index 4cbbb3f0f..e8d9426a6 100644 --- a/EditorExtensions/Resources/settings-defaults/.jscs.json +++ b/EditorExtensions/Resources/settings-defaults/.jscs.json @@ -9,7 +9,7 @@ "disallowKeywords": ["with"], "disallowMultipleLineBreaks": true, "disallowKeywordsOnNewLine": ["else"], - "excludeFiles": ["**/*.min.js", "**/*.debug.js", "**/*.intellisense.js", "**/*-vsdoc.js"], + "excludeFiles": [], "validateJSDoc": { "checkParamNames": true, "requireParamTypes": true diff --git a/EditorExtensions/WebEssentials2013.csproj b/EditorExtensions/WebEssentials2013.csproj index 8dda96d4a..288205e89 100644 --- a/EditorExtensions/WebEssentials2013.csproj +++ b/EditorExtensions/WebEssentials2013.csproj @@ -437,7 +437,7 @@ Code - + Code