Skip to content

Commit

Permalink
TsLint: Fixed error logging.
Browse files Browse the repository at this point in the history
Using a Hack: A separate error class.
  • Loading branch information
am11 committed Jan 9, 2014
1 parent 54dca91 commit 3b7dfc8
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 19 deletions.
23 changes: 23 additions & 0 deletions EditorExtensions/Compilers/Lint/TsLintCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Web.Helpers;

namespace MadsKristensen.EditorExtensions
{
Expand All @@ -22,5 +24,26 @@ protected override string GetArguments(string sourceFileName, string targetFileN
, FindLocalSettings(sourceFileName) ?? GlobalSettings(ServiceName)
, sourceFileName);
}

protected override IEnumerable<CompilerError> ParseErrorsWithJson(string error)
{
if (string.IsNullOrEmpty(error))
return null;

try
{
TsLintCompilerError[] results = Json.Decode<TsLintCompilerError[]>(error);

if (results.Length == 0)
Logger.Log(ServiceName + " parse error: " + error);

return TsLintCompilerError.ToCompilerError(results);
}
catch (ArgumentException)
{
Logger.Log(ServiceName + " parse error: " + error);
return new[] { new CompilerError() { Message = error } };
}
}
}
}
30 changes: 30 additions & 0 deletions EditorExtensions/Compilers/Lint/TsLintCompilerError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Linq;

namespace MadsKristensen.EditorExtensions
{
internal class TsLintCompilerError
{
public string name { get; set; }
public string failure { get; set; }
public StartPosition startPosition { get; set; }

internal class StartPosition
{
public int line { get; set; }
public int character { get; set; }
public int position { get; set; }
}

public static IEnumerable<CompilerError> ToCompilerError(IEnumerable<TsLintCompilerError> rawErrors)
{
return rawErrors.Select(error => new CompilerError()
{
Message = error.failure,
Column = error.startPosition.character,
FileName = error.name,
Line = error.startPosition.line
});
}
}
}
2 changes: 1 addition & 1 deletion EditorExtensions/Compilers/NodeExecutorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void ValidateResult(Process process, string outputFile, string errorText
}
}

protected IEnumerable<CompilerError> ParseErrorsWithJson(string error)
protected virtual IEnumerable<CompilerError> ParseErrorsWithJson(string error)
{
if (string.IsNullOrEmpty(error))
return null;
Expand Down
64 changes: 46 additions & 18 deletions EditorExtensions/Resources/settings-defaults/.tslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
{
"semicolon": true,
"eqeqeq": true,
"maxlen": 140,
"whitespace": true,
"quotemark": "double",
"oneline": true,
"trailing": true,
"bitwise": true,
"evil": true,
"eofline": true,
"classname": true,
"varname": true,
"noarg": true,
"sub": true,
"debug": true,
"forin": true,
"curly": true,
"indent": 4
"rules": {
"class-name": true,
"curly": true,
"eofline": true,
"forin": true,
"indent": [true, 4],
"label-position": true,
"label-undefined": true,
"max-line-length": [true, 140],
"no-arg": true,
"no-bitwise": true,
"no-console": [true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-key": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-eval": true,
"no-string-literal": true,
"no-trailing-whitespace": true,
"no-unreachable": true,
"one-line": [true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"quotemark": [true, "double"],
"radix": true,
"semicolon": true,
"triple-equals": [true, "allow-null-check"],
"variable-name": false,
"whitespace": [true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}
}
1 change: 1 addition & 0 deletions EditorExtensions/WebEssentials2013.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
<Compile Include="Commands\TypeScript\TypeScriptCreationListener.cs" />
<Compile Include="Commands\TypeScript\TsLintProjectRunner.cs" />
<Compile Include="Commands\TypeScript\TsHintRunner.cs" />
<Compile Include="Compilers\Lint\TsLintCompilerError.cs" />
<Compile Include="Compilers\Lint\TsLintCompiler.cs" />
<Compile Include="MenuItems\TsLint.cs" />
<Compile Include="Settings\OptionPages\TsLint.cs">
Expand Down

0 comments on commit 3b7dfc8

Please sign in to comment.