Skip to content
Permalink
Browse files

Format: 新增 revive 代码检查工具

  • Loading branch information...
chenjiandongx committed Jan 4, 2019
1 parent 9e2d446 commit 0e33238b843f12febaea622d403455a9bd87d7aa
Showing with 71 additions and 63 deletions.
  1. +24 −0 .revive.toml
  2. +5 −2 bar.go
  3. +7 −7 base.go
  4. +1 −1 effectscatter.go
  5. +8 −8 engine.go
  6. +2 −5 funnel.go
  7. +5 −9 geo.go
  8. +1 −1 kline.go
  9. +1 −1 line.go
  10. +3 −6 map.go
  11. +4 −7 page.go
  12. +2 −5 pie.go
  13. +1 −4 rectangular.go
  14. +1 −1 scatter.go
  15. +6 −6 templates.go
@@ -0,0 +1,24 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 0
warningCode = 0

[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
7 bar.go
@@ -19,7 +19,7 @@ type BarChartOpts struct {
}

// 工厂函数,生成 `Bar` 实例
func NewBar(routers ...HttpRouter) *Bar {
func NewBar(routers ...HTTPRouter) *Bar {
barChart := new(Bar)
barChart.HasXYAxis = true
barChart.initBaseOpts(routers...)
@@ -81,7 +81,10 @@ func (c *Bar) Render(w ...io.Writer) error {
}
res := replaceRender(b)
for i := 0; i < len(w); i++ {
w[i].Write(res)
_, err := w[i].Write(res)
if err != nil {
return err
}
}
return nil
}
14 base.go
@@ -92,14 +92,14 @@ func (opt *InitOpts) validateInitOpt() {
}

// Http 路由
type HttpRouter struct {
Url string // 路由 URL
type HTTPRouter struct {
URL string // 路由 URL
Text string // 路由显示文字
}

type HttpRouters []HttpRouter
type HTTPRouters []HTTPRouter

func (hr HttpRouters) Len() int {
func (hr HTTPRouters) Len() int {
return len(hr)
}

@@ -116,7 +116,7 @@ type BaseOpts struct {
AssetsOpts // 静态资源配置项
ColorList []string // 全局颜色列表
appendColor []string // 追加全局颜色列表
HttpRouters // 路由列表
HTTPRouters // 路由列表
DataZoomOptsList // 区域缩放组件配置项列表
VisualMapOptsList // 视觉映射组件配置项列表
GeoOpts // 地理坐标系组件配置项
@@ -143,9 +143,9 @@ func (opt *BaseOpts) initSeriesColors() {
}

// 初始化 BaseOpts
func (opt *BaseOpts) initBaseOpts(routers ...HttpRouter) {
func (opt *BaseOpts) initBaseOpts(routers ...HTTPRouter) {
for i := 0; i < len(routers); i++ {
opt.HttpRouters = append(opt.HttpRouters, routers[i])
opt.HTTPRouters = append(opt.HTTPRouters, routers[i])
}
opt.initSeriesColors()
}
@@ -24,7 +24,7 @@ type RippleEffectOpts struct {
}

//工厂函数,生成 `Scatter` 实例
func NewEffectScatter(routers ...HttpRouter) *EffectScatter {
func NewEffectScatter(routers ...HTTPRouter) *EffectScatter {
esChart := new(EffectScatter)
esChart.HasXYAxis = true
esChart.initBaseOpts(routers...)
@@ -16,7 +16,7 @@ const (
letterIdxBits = 6 // 6 bits to represent a letter index
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
chartIdSize = 12
chartIDSize = 12
)

// 渲染图表
@@ -29,10 +29,7 @@ func renderChart(chart interface{}, w io.Writer, name string) error {
}
tpl := template.Must(template.New("").Parse(contents[0]))
mustTpl(tpl, contents[1:]...)
if err := tpl.ExecuteTemplate(w, name, chart); err != nil {
return err
}
return nil
return tpl.ExecuteTemplate(w, name, chart)
}

func mustTpl(tpl *template.Template, html ...string) {
@@ -48,7 +45,10 @@ func renderToWriter(chart interface{}, renderName string, w ...io.Writer) error
}
res := replaceRender(b)
for i := 0; i < len(w); i++ {
w[i].Write(res)
_, err := w[i].Write(res)
if err != nil {
return err
}
}
return nil
}
@@ -58,8 +58,8 @@ var seed = rand.NewSource(time.Now().UnixNano())

// 生成唯一且随机的图表 ID
func genChartID() string {
b := make([]byte, chartIdSize)
for i, cache, remain := chartIdSize-1, seed.Int63(), letterIdxMax; i >= 0; {
b := make([]byte, chartIDSize)
for i, cache, remain := chartIDSize-1, seed.Int63(), letterIdxMax; i >= 0; {
if remain == 0 {
cache, remain = seed.Int63(), letterIdxMax
}
@@ -10,7 +10,7 @@ type Funnel struct {
}

// 工厂函数,生成 `Funnel` 实例
func NewFunnel(routers ...HttpRouter) *Funnel {
func NewFunnel(routers ...HTTPRouter) *Funnel {
funnelChart := new(Funnel)
funnelChart.HasXYAxis = false
funnelChart.initBaseOpts(routers...)
@@ -43,8 +43,5 @@ func (c *Funnel) validateOpts() {
func (c *Funnel) Render(w ...io.Writer) error {
c.insertSeriesColors(c.appendColor)
c.validateOpts()
if err := renderToWriter(c, "chart", w...); err != nil {
return err
}
return nil
return renderToWriter(c, "chart", w...)
}
14 geo.go
@@ -9,13 +9,13 @@ type Geo struct {
Series
}

//工厂函数,生成 `Geo` 实例
func NewGeo(mapType string, routers ...HttpRouter) *Geo {
// 工厂函数,生成 `Geo` 实例
func NewGeo(mapType string, routers ...HTTPRouter) *Geo {
geoChart := new(Geo)
geoChart.HasXYAxis = false
geoChart.initBaseOpts(routers...)
geoChart.initAssetsOpts()
geoChart.JSAssets = append(geoChart.JSAssets, "maps/"+MapFilenames[mapType]+".js")
geoChart.appendJsAssets("maps/" + MapFilenames[mapType] + ".js")
geoChart.GeoOpts.Map = mapType
return geoChart
}
@@ -33,9 +33,8 @@ func (c *Geo) Add(name, geoType string, data map[string]float32, options ...inte
}

func (c *Geo) extendValue(region string, v float32) []float32 {
res := make([]float32, 0)
tv := Coordinates[region]
res = append(tv[:], v)
res := append(tv[:], v)
return res
}

@@ -59,8 +58,5 @@ func (c *Geo) validateOpts() {
func (c *Geo) Render(w ...io.Writer) error {
c.insertSeriesColors(c.appendColor)
c.validateOpts()
if err := renderToWriter(c, "chart", w...); err != nil {
return err
}
return nil
return renderToWriter(c, "chart", w...)
}
@@ -5,7 +5,7 @@ type Kline struct {
}

//工厂函数,生成 `Kline` 实例
func NewKLine(routers ...HttpRouter) *Kline {
func NewKLine(routers ...HTTPRouter) *Kline {
klineChart := new(Kline)
klineChart.HasXYAxis = true
klineChart.initBaseOpts(routers...)
@@ -5,7 +5,7 @@ type Line struct {
}

//工厂函数,生成 `Line` 实例
func NewLine(routers ...HttpRouter) *Line {
func NewLine(routers ...HTTPRouter) *Line {
lineChart := new(Line)
lineChart.HasXYAxis = true
lineChart.initBaseOpts(routers...)
9 map.go
@@ -12,13 +12,13 @@ type Map struct {
}

// 工厂函数,生成 `Map` 实例
func NewMap(mapType string, routers ...HttpRouter) *Map {
func NewMap(mapType string, routers ...HTTPRouter) *Map {
mapChart := new(Map)
mapChart.mapType = mapType
mapChart.HasXYAxis = false
mapChart.initBaseOpts(routers...)
mapChart.initAssetsOpts()
mapChart.JSAssets = append(mapChart.JSAssets, "maps/"+MapFilenames[mapType]+".js")
mapChart.appendJsAssets("maps/" + MapFilenames[mapType] + ".js")
return mapChart
}

@@ -58,8 +58,5 @@ func (c *Map) validateOpts() {
func (c *Map) Render(w ...io.Writer) error {
c.insertSeriesColors(c.appendColor)
c.validateOpts()
if err := renderToWriter(c, "chart", w...); err != nil {
return err
}
return nil
return renderToWriter(c, "chart", w...)
}
11 page.go
@@ -16,14 +16,14 @@ type Page struct {
AssetsOpts
Charts []interface{}

HttpRouters
HTTPRouters
}

//工厂函数,生成 `Bar` 实例
func NewPage(routers ...HttpRouter) *Page {
func NewPage(routers ...HTTPRouter) *Page {
page := new(Page)
for i := 0; i < len(routers); i++ {
page.HttpRouters = append(page.HttpRouters, routers[i])
page.HTTPRouters = append(page.HTTPRouters, routers[i])
}
return page
}
@@ -64,8 +64,5 @@ func (page *Page) extractCSSAssets(cssList []string) {

func (page *Page) Render(w ...io.Writer) error {
page.InitOpts.setDefault()
if err := renderToWriter(page, "page", w...); err != nil {
return err
}
return nil
return renderToWriter(page, "page", w...)
}
7 pie.go
@@ -10,7 +10,7 @@ type Pie struct {
}

//工厂函数,生成 `Pie` 实例
func NewPie(routers ...HttpRouter) *Pie {
func NewPie(routers ...HTTPRouter) *Pie {
pieChart := new(Pie)
pieChart.HasXYAxis = false
pieChart.initBaseOpts(routers...)
@@ -43,8 +43,5 @@ func (c *Pie) validateOpts() {
func (c *Pie) Render(w ...io.Writer) error {
c.insertSeriesColors(c.appendColor)
c.validateOpts()
if err := renderToWriter(c, "chart", w...); err != nil {
return err
}
return nil
return renderToWriter(c, "chart", w...)
}
@@ -60,8 +60,5 @@ func (rc *RectChart) validateOpts() {
func (rc *RectChart) Render(w ...io.Writer) error {
rc.XAxisOpts.Data = rc.xAxisData
rc.validateOpts()
if err := renderToWriter(rc, "chart", w...); err != nil {
return err
}
return nil
return renderToWriter(rc, "chart", w...)
}
@@ -5,7 +5,7 @@ type Scatter struct {
}

// 工厂函数,生成 `Scatter` 实例
func NewScatter(routers ...HttpRouter) *Scatter {
func NewScatter(routers ...HTTPRouter) *Scatter {
scatterChart := new(Scatter)
scatterChart.HasXYAxis = true
scatterChart.initBaseOpts(routers...)
@@ -18,10 +18,10 @@ var headerTpl = `
var routerTpl = `
{{- define "routers" }}
<div class="select" style="margin-left: 10px; margin-top:10px">
{{- if gt .HttpRouters.Len 0}}
{{- if gt .HTTPRouters.Len 0}}
<select onchange="window.location.href=this.options[this.selectedIndex].value">
{{- range .HttpRouters }}
<option value="{{ .Url }}">{{ .Text }}</option>
{{- range .HTTPRouters }}
<option value="{{ .URL }}">{{ .Text }}</option>
{{- end }}
</select>
{{- end -}}
@@ -37,8 +37,8 @@ var baseTpl = `
style="width:{{ .InitOpts.Width }};height:{{ .InitOpts.Height }};"></div>
</div>
<script type="text/javascript">
let myChart__x__{{ .ChartID }}__x__ = echarts.init(document.getElementById('{{ .ChartID }}'), "{{ .Theme }}");
let option__x__{{ .ChartID }}__x__ = {
let myChart___x__{{ .ChartID }}__x__ = echarts.init(document.getElementById('{{ .ChartID }}'), "{{ .Theme }}");
let option___x__{{ .ChartID }}__x__ = {
title: {{ .TitleOpts }},
tooltip: {{ .TooltipOpts }},
legend: {{ .LegendOpts }},
@@ -65,7 +65,7 @@ var baseTpl = `
color: {{ .ColorList }}
{{- end }}
};
myChart__x__{{ .ChartID }}__x__.setOption(option__x__{{ .ChartID }}__x__);
myChart___x__{{ .ChartID }}__x__.setOption(option___x__{{ .ChartID }}__x__);
</script>
{{ end }}`

0 comments on commit 0e33238

Please sign in to comment.
You can’t perform that action at this time.