Add tab-width option to lll linter
This commit is contained in:
parent
6ccd0c5e53
commit
e17b9543e7
@ -107,8 +107,11 @@ linters-settings:
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
locale: US
|
||||
lll:
|
||||
# max line length, lines longer will be reported. Default is 120. '\t' is counted as 1 character.
|
||||
# max line length, lines longer will be reported. Default is 120.
|
||||
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||
line-length: 120
|
||||
# tab width in spaces. Default to 1.
|
||||
tab-width: 1
|
||||
unused:
|
||||
# treat code as a program (not a library) and report unused exported identifiers; default is false.
|
||||
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
|
||||
|
@ -520,8 +520,11 @@ linters-settings:
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
locale: US
|
||||
lll:
|
||||
# max line length, lines longer will be reported. Default is 120. '\t' is counted as 1 character.
|
||||
# max line length, lines longer will be reported. Default is 120.
|
||||
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||
line-length: 120
|
||||
# tab width in spaces. Default to 1.
|
||||
tab-width: 1
|
||||
unused:
|
||||
# treat code as a program (not a library) and report unused exported identifiers; default is false.
|
||||
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
|
||||
|
@ -124,6 +124,10 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config) {
|
||||
"Depguard: check list against standard lib")
|
||||
hideFlag("depguard.include-go-root")
|
||||
|
||||
fs.IntVar(&lsc.Lll.TabWidth, "lll.tab-width", 1,
|
||||
"Lll: tab width in spaces")
|
||||
hideFlag("lll.tab-width")
|
||||
|
||||
// Linters config
|
||||
lc := &cfg.Linters
|
||||
fs.StringSliceVarP(&lc.Enable, "enable", "E", nil, wh("Enable specific linter"))
|
||||
|
@ -168,6 +168,7 @@ type LintersSettings struct {
|
||||
|
||||
type LllSettings struct {
|
||||
LineLength int `mapstructure:"line-length"`
|
||||
TabWidth int `mapstructure:"tab-width"`
|
||||
}
|
||||
|
||||
type UnparamSettings struct {
|
||||
@ -188,6 +189,7 @@ type PreallocSettings struct {
|
||||
var defaultLintersSettings = LintersSettings{
|
||||
Lll: LllSettings{
|
||||
LineLength: 120,
|
||||
TabWidth: 1,
|
||||
},
|
||||
Unparam: UnparamSettings{
|
||||
Algo: "cha",
|
||||
|
@ -23,7 +23,7 @@ func (Lll) Desc() string {
|
||||
return "Reports long lines"
|
||||
}
|
||||
|
||||
func (lint Lll) getIssuesForFile(filename string, maxLineLen int) ([]result.Issue, error) {
|
||||
func (lint Lll) getIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]result.Issue, error) {
|
||||
var res []result.Issue
|
||||
|
||||
f, err := os.Open(filename)
|
||||
@ -36,7 +36,7 @@ func (lint Lll) getIssuesForFile(filename string, maxLineLen int) ([]result.Issu
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
line = strings.Replace(line, "\t", " ", -1)
|
||||
line = strings.Replace(line, "\t", tabSpaces, -1)
|
||||
lineLen := utf8.RuneCountInString(line)
|
||||
if lineLen > maxLineLen {
|
||||
res = append(res, result.Issue{
|
||||
@ -61,8 +61,9 @@ func (lint Lll) getIssuesForFile(filename string, maxLineLen int) ([]result.Issu
|
||||
|
||||
func (lint Lll) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
|
||||
var res []result.Issue
|
||||
spaces := strings.Repeat(" ", lintCtx.Settings().Lll.TabWidth)
|
||||
for _, f := range lintCtx.PkgProgram.Files(lintCtx.Cfg.Run.AnalyzeTests) {
|
||||
issues, err := lint.getIssuesForFile(f, lintCtx.Settings().Lll.LineLength)
|
||||
issues, err := lint.getIssuesForFile(f, lintCtx.Settings().Lll.LineLength, spaces)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
4
test/testdata/lll.go
vendored
4
test/testdata/lll.go
vendored
@ -1,6 +1,6 @@
|
||||
// args: -Elll
|
||||
// args: -Elll --lll.tab-width 4
|
||||
package testdata
|
||||
|
||||
func Lll() {
|
||||
// In my experience, long lines are the lines with comments, not the code. So this is a long comment // ERROR "line is 135 characters"
|
||||
// In my experience, long lines are the lines with comments, not the code. So this is a long comment // ERROR "line is 138 characters"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user