Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updates to support a JS Hint engine

  • Loading branch information...
commit a99220f668b25689f2e785589b2a341785a37756 1 parent a466827
@andyedinborough authored jamesfoster committed
View
4 Chirpy/Chirp.cs
@@ -116,6 +116,10 @@ IEnumerable<FileAssociation> ProcessEngine(ProjectItem projectItem, string filen
{
foreach (var exception in engineResult.Exceptions)
{
+ if (string.IsNullOrEmpty(exception.FileName))
+ {
+ exception.FileName = filename;
+ }
TaskList.Add(exception);
}
continue;
View
1  Chirpy/Chirpy.csproj
@@ -69,6 +69,7 @@
<ItemGroup>
<Compile Include="Chirp.cs" />
<Compile Include="ChirpyAddIn.cs" />
+ <Compile Include="Engines\JsHintEngine.cs" />
<Compile Include="Engines\CssLintEngine.cs" />
<Compile Include="Composition\DirectoryCatalogWatcher.cs" />
<Compile Include="Composition\MefComposer.cs" />
View
51 Chirpy/Engines/JsHintEngine.cs
@@ -0,0 +1,51 @@
+namespace Chirpy.Engines
+{
+ using System.Collections.Generic;
+ using System.ComponentModel.Composition;
+ using ChirpyInterface;
+
+ [Export(typeof (IEngine))]
+ [EngineMetadata("JS Hint", "1.0", ".js", true)]
+ public class JsHintEngine : IEngine
+ {
+ [Import] public IJavascriptRunner JavascriptRunner { get; set; }
+
+ public List<string> GetDependancies(string contents, string filename)
+ {
+ return null;
+ }
+
+ public List<EngineResult> Process(string contents, string filename)
+ {
+ var result = new EngineResult {FileName = filename};
+ var properties = new Dictionary<string, object>();
+
+ properties["js"] = contents;
+
+ const string script = @"
+var exports = require('https://raw.github.com/jshint/jshint/master/jshint.js', null, '');
+var JSHINT = exports.JSHINT;
+
+var js = external.Get('js');
+var result = JSHINT(js);
+var errors = JSHINT.errors;
+
+external.Set('result', result);
+external.Set('errors', errors.length);
+if (!result)
+{
+ for (var i = 0; i < errors.length; i++)
+ {
+ external.LogWarning((errors[i].reason || '') + ': ' + (errors[i].evidence || ''), errors[i].line || 0, errors[i].character || 0);
+ }
+}
+";
+
+ var javascriptResult = JavascriptRunner.Execute(script, properties);
+
+ result.Exceptions.AddRange(javascriptResult.Messages);
+
+ return new List<EngineResult> {result};
+ }
+ }
+}
View
2  Chirpy/Exports/ExtensionResolver.cs
@@ -11,7 +11,7 @@ public string GetExtensionFromCategory(string category)
if(!category.Contains("."))
return ".chirp." + category;
- return "." + category;
+ return "." + category.TrimStart('.');
}
}
}
View
2  Chirpy/Javascript/JavascriptRunner.cs
@@ -48,8 +48,6 @@ string GetHtml(string script)
</head>
<body>
<script>
- var window = {};
-
var module = window;
var onerror = window.onerror = function(msg, file, line){
View
11 ChirpyInterface/JavascriptResult.cs
@@ -40,17 +40,22 @@ public object Get(string name)
public void LogMessage(string message, int? lineNumber = null, int? column = null, string filename = null, string line = null)
{
- Messages.Add(new ChirpyException(message, filename, lineNumber, column, line, ErrorCategory.Message));
+ Log(ErrorCategory.Message, message, lineNumber, column, filename, line);
}
public void LogWarning(string message, int? lineNumber = null, int? column = null, string filename = null, string line = null)
{
- Messages.Add(new ChirpyException(message, filename, lineNumber, column, line, ErrorCategory.Warning));
+ Log(ErrorCategory.Warning, message, lineNumber, column, filename, line);
}
public void LogError(string message, int? lineNumber = null, int? column = null, string filename = null, string line = null)
{
- Messages.Add(new ChirpyException(message, filename, lineNumber, column, line, ErrorCategory.Error));
+ Log(ErrorCategory.Error, message, lineNumber, column, filename, line);
+ }
+
+ private void Log(ErrorCategory category, string message, int? lineNumber = null, int? column = null, string filename = null, string line = null)
+ {
+ Messages.Add(new ChirpyException(message, filename, lineNumber, column, line, category));
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.