Skip to content

Instantly share code, notes, and snippets.

@jan4984
Created March 23, 2020 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan4984/ce6c09436a4d0be7a8573705f6f6e65b to your computer and use it in GitHub Desktop.
Save jan4984/ce6c09436a4d0be7a8573705f6f6e65b to your computer and use it in GitHub Desktop.
golangci-lint presention
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>golangci-lint Lint Visualization</title>
<link href="https://unpkg.com/vue-json-tree@0.3.3/dist/json-tree.css" rel="stylesheet">
<script src="https://unpkg.com/vue@2.4.2/dist/vue.js"></script>
<script src="https://unpkg.com/vue-json-tree@0.3.3/dist/json-tree.js"></script>
</head>
<section>
<p style="background: gray">
<q>golangci-lint run --tests=false --skip-dirs goscripts --enable bodyclose --enable gosec --enable dupl --enable scopelint --enable gocritic --out-format=json</q>
</p>
<p>
<input type="file" accept="application/json"/>
<label>select lint output json file</label>
</p>
<p>
<button id="btn-linter">By Linter</button>
<button id="btn-source">By Source</button>
</p>
</section>
<section id="app">
<div></div>
</section>
</body>
<script>
let issues;
document.querySelector('#btn-linter').addEventListener('click', ()=>present(issues.byLinter));
document.querySelector('#btn-source').addEventListener('click', ()=>present(issues.bySource));
function present(data){
new Vue({
template: '<json-tree :data="sample" :level="1"></json-tree>',
el: document.querySelector('#app').children[0],
data: {
sample: data
}
});
}
function run(e){
const f = e.target.files[0];
const reader = new FileReader();
reader.onloadend = ()=> {
issues = JSON.parse(reader.result).Issues;
const g = {byLinter:{}, bySource:{}};
issues.forEach(i=>{
{
let normalText = i.Text.replace(/`.*`/g, 'xxx');
const idx = normalText.indexOf(':');
if(idx > 0) {
normalText = normalText.substr(0, idx)
}else{
const lineRange = normalText.match(/\d+-\d+/);
if(lineRange && lineRange.length > 0){
const se = lineRange[0].split('-');
const lineCount = se[1] - se[0];
normalText = normalText.replace(/\d+-\d+/g, lineCount.toString());
}
}
const gg = g.byLinter[normalText] || [];
gg.push(i);
g.byLinter[normalText] = gg;
}
{
const gg = g.bySource[i.Pos.Filename] || [];
gg.push(i);
g.bySource[i.Pos.Filename] = gg;
}
});
issues = g;
};
reader.readAsText(f);
}
document.querySelector('input').addEventListener('change', run);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment