Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Commit

Permalink
Use linterhub output schema (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Safonov authored and xferra committed Jul 26, 2017
1 parent 0d8ecc7 commit 912c305
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 73 deletions.
34 changes: 34 additions & 0 deletions docs/hub/.schema/linterhub.output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Linterhub Output
This document describes the structure of linterhub output
## Structure
Linterhub output is an array of engines results
### result
The engine result

|Key|Type|Required|Description|
|-|:-:|:-:|-|
|engine|string|+|The engine name that performed analysis|
|result|object|-|The analysis result|
|error|[error](#error)|-|The problem definition if analysis is not possible|
### error
The problem definition if analysis is not possible

|Key|Type|Required|Description|
|-|:-:|:-:|-|
|code|integer|+|The error code|
|title|string|+|The error title|
|description|string|-|The error decription|
## Example
```
[
{
"engine": "string",
"result": {},
"error": {
"code": 0,
"title": "string",
"description": "string"
}
}
]
```
11 changes: 9 additions & 2 deletions script/js/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ Object.resolve = (path, obj) => path.replace('#/', '').split('/').reduce((prev,

const format = {
undef: (name) => name.replace('#/definitions/', ''),
class: (name) => `public class ${format.highCase(format.undef(name))}`,
class: (name, type) => {
let gname = format.highCase(format.undef(name));
return `public class ${gname}` + (type ? ` : List<${gname}.${type}>` : '');
},
highCase: (value) => value.charAt(0).toUpperCase() + value.slice(1),
enum: (name, value) => {
name = name.charAt(0).toUpperCase() + name.slice(1);
Expand Down Expand Up @@ -40,6 +43,9 @@ const format = {
if (propname === 'options' && name === 'linterhub.config.json') {
type = 'EngineOptions';
}
if (propname === 'result') {
type = 'EngineOutputSchema';
}
if (type === 'int' || type === 'bool') {
type += '?';
}
Expand Down Expand Up @@ -162,7 +168,8 @@ const tree = {
typeName = format.removeExtension(name + 'Schema');
}
tree.doc.push(format.documentation(node.description, true));
tree.doc.push(format.class(typeName));
let elemType = node.type == 'array' ? format.type(node.items.$ref) : false;
tree.doc.push(format.class(typeName, elemType));
tree.doc.push(format.open());
if (node.properties) {
Object.keys(node.properties).forEach((name) => {
Expand Down
5 changes: 5 additions & 0 deletions script/js/generate.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"cs": "src/core/Schema/EngineSchema.cs",
"md": "docs/hub/.schema/engine.md"
},
{
"schema": "src/hub/.schema/linterhub.output.json",
"cs": "src/core/Schema/LinterhubOutputSchema.cs",
"md": "docs/hub/.schema/linterhub.output.md"
},
{
"schema": "src/hub/.schema/args.json",
"md": "docs/hub/.schema/args.md"
Expand Down
56 changes: 28 additions & 28 deletions src/cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,119 +2,119 @@
"profiles": {
"cli": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/marp --folder=coffee/classes --linter=coffeelint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/angular/aio/content/examples --folder=toh-pt5/src/app --engine=colorguard"
},
"catalog": {
"commandName": "Project",
"commandLineArgs": "--mode=catalog"
},
"coffeelint-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/marp --file=coffee/classes/mds_main_menu.coffee --linter=coffeelint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/marp --file=coffee/classes/mds_main_menu.coffee --engine=coffeelint"
},
"coffeelint-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/marp --folder=coffee/classes --linter=coffeelint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/marp --folder=coffee/classes --engine=coffeelint"
},
"coffeelint-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/marp --linter=coffeelint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/marp --engine=coffeelint"
},
"csslint-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery-ui/themes/base --file=all.css --linter=csslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery-ui/themes/base --file=all.css --engine=csslint"
},
"csslint-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/Font-Awesome --folder=css --linter=csslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/Font-Awesome --folder=css --engine=csslint"
},
"csslint-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/Font-Awesome --linter=csslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/Font-Awesome --engine=csslint"
},
"eslint-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=include/styleguide.js --linter=eslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=include/styleguide.js --engine=eslint"
},
"eslint-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --folder=include --linter=eslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --folder=include --engine=eslint"
},
"eslint-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --linter=eslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --engine=eslint"
},
"htmlhint-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=xmlstyle.html --linter=htmlhint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=xmlstyle.html --engine=htmlhint"
},
"htmlhint-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery --folder=test/data/core --linter=htmlhint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery --folder=test/data/core --engine=htmlhint"
},
"htmlhint-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery/test/data --linter=htmlhint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery/test/data --engine=htmlhint"
},
"jshint-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=include/styleguide.js --linter=jshint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=include/styleguide.js --engine=jshint"
},
"jshint-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --folder=include --linter=jshint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --folder=include --engine=jshint"
},
"jshint-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --linter=jshint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --engine=jshint"
},
"jslint-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=include/styleguide.js --linter=jslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=include/styleguide.js --engine=jslint"
},
"jslint-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery --folder=src/core/var --linter=jslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery --folder=src/core/var --engine=jslint"
},
"jslint-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery/src/core/var --linter=jslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/jquery/src/core/var --engine=jslint"
},
"standard-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=include/styleguide.js --linter=standard"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --file=include/styleguide.js --engine=standard"
},
"standard-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --folder=include --linter=standard"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --folder=include --engine=standard"
},
"standard-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --linter=standard"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/styleguide --engine=standard"
},
"stylelint-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/Font-Awesome --folder=less --file=core.less --linter=stylelint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/Font-Awesome --folder=less --file=core.less --engine=stylelint"
},
"stylelint-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/bulma --folder=sass/base --linter=stylelint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/bulma --folder=sass/base --engine=stylelint"
},
"stylelint-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/bulma/sass/grid --linter=stylelint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/bulma/sass/grid --engine=stylelint"
},
"tslint-file": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/angular --folder=integration/hello_world__closure/src --file=main.ts --linter=tslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/angular --folder=integration/hello_world__closure/src --file=main.ts --engine=tslint"
},
"tslint-folder": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/angular --folder=integration/hello_world__closure/src --linter=tslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/angular --folder=integration/hello_world__closure/src --engine=tslint"
},
"tslint-project": {
"commandName": "Project",
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/angular/integration/hello_world__closure --linter=tslint"
"commandLineArgs": "--mode=Analyze --project=../../test/linterhub-tests/angular/integration/hello_world__closure --engine=tslint"
}
}
}
114 changes: 75 additions & 39 deletions src/core/Runtime/EngineRunner.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace Linterhub.Core.Runtime
{
using Exceptions;
using Extensions;
using Schema;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Result = Schema.LinterhubOutputSchema.ResultType;

public class EngineRunner
{
Expand All @@ -16,14 +18,14 @@ public EngineRunner(EngineWrapper wrapper)
engineRunner = wrapper;
}

public List<EngineOutputSchema.ResultType> RunAnalyze(
public LinterhubOutputSchema RunAnalyze(
List<EngineWrapper.Context> contexts,
string project,
string directory,
string file,
LinterhubConfigSchema config = null)
{
var results = new List<EngineOutputSchema.ResultType>();
var output = new LinterhubOutputSchema();
var n_contexts = new List<EngineWrapper.Context>();

string stdin = "";
Expand Down Expand Up @@ -75,63 +77,97 @@ public EngineRunner(EngineWrapper wrapper)

Parallel.ForEach(n_contexts, context =>
{
var res = engineRunner.RunAnalysis(context, stdin);
var current = res.DeserializeAsJson<EngineOutputSchema.ResultType[]>();
lock (results)
var error = new LinterhubOutputSchema.ErrorType()
{
Code = 0
};
EngineOutputSchema parsedOutput = null;
try
{
var res = engineRunner.RunAnalysis(context, stdin);
parsedOutput = res.DeserializeAsJson<EngineOutputSchema>();
}
catch (EngineException e)
{
error.Code = (int)e.exitCode;
error.Title = e.Message;
}
lock (output)
{
foreach (var output in current)
var result = new EngineOutputSchema();
if (error.Code == 0)
{
if (!string.IsNullOrEmpty(directory) && output.Path != string.Empty)
foreach (var current in parsedOutput)
{
var directoryPrefix = Path.GetFullPath(directory).Replace(Path.GetFullPath(project), string.Empty)
.TrimStart('/')
.TrimStart('\\')
.Replace("/", "\\");
if (!output.Path.Contains(directoryPrefix))
if (!string.IsNullOrEmpty(directory) && current.Path != string.Empty)
{
output.Path = Path.Combine(Path.GetFullPath(directory), output.Path);
var directoryPrefix = Path.GetFullPath(directory).Replace(Path.GetFullPath(project), string.Empty)
.TrimStart('/')
.TrimStart('\\')
.Replace("/", "\\");
if (!current.Path.Contains(directoryPrefix))
{
current.Path = Path.Combine(Path.GetFullPath(directory), current.Path);
}
}
}
output.Path = output
.Path
.Replace(project, string.Empty)
.Replace(Path.GetFullPath(project), string.Empty)
.TrimStart('/')
.TrimStart('\\')
.Replace("/", "\\");
current.Path = current
.Path
.Replace(project, string.Empty)
.Replace(Path.GetFullPath(project), string.Empty)
.TrimStart('/')
.TrimStart('\\')
.Replace("/", "\\");
}
result.AddRange(parsedOutput.Where(x => x.Path != string.Empty));
}
var req = results.Where(x => x.Path == output.Path);
if (req.Count() > 0)
if (result.Count != 0) {
var exists = output.Find(x => x.Engine == context.Specification.Schema.Name);
if (exists != null)
{
req.First().Messages.AddRange(output.Messages);
req.First().Messages = req.First().Messages.OrderBy(x => x.Line).ThenBy(x => x.Column).ThenBy(x => x.RuleId).ToList();
if (exists.Error == null && error.Code == 0)
{
exists.Result.AddRange(result);
}
else if (error.Code != 0)
{
exists.Error = error;
}
}
else if (output.Path != string.Empty)
else
{
results.Add(output);
output.Add(new Result()
{
Result = result,
Engine = context.Specification.Schema.Name,
Error = error.Code == 0 ? null : error
});
}
}
}
});

if(config != null)
{
results = results.Select(x =>
{
x.Messages = x.Messages.Where(m =>
{
return !(config.Ignore.Find(r => x.Path.Contains(r.Mask)) != null || config.Ignore.Find(r => x.Path.Contains(r.Mask) && m.RuleId == r.RuleId) != null ||
config.Ignore.Find(r => x.Path.Contains(r.Mask) && m.Line == r.Line) != null);
}).ToList();
return x;
}).ToList();
output.ForEach(x => {
x.Result.ForEach(y => {
y.Messages = y.Messages.Where(m =>
{
return !(config.Ignore.Find(r => y.Path.Contains(r.Mask)) != null || config.Ignore.Find(r => y.Path.Contains(r.Mask) && m.RuleId == r.RuleId) != null ||
config.Ignore.Find(r => y.Path.Contains(r.Mask) && m.Line == r.Line) != null);
}).OrderBy(z => z.Line).ThenBy(z => z.Column).ThenBy(z => z.RuleId).ToList();
});
x.Result.Sort((a,b) => a.Path.CompareTo(b.Path));
});
output.Sort((a,b) => a.Engine.CompareTo(b.Engine));
}

return results.OrderBy((x) => x.Path).ToList();
return output;

}
}
Expand Down
Loading

0 comments on commit 912c305

Please sign in to comment.