mirror of
				https://github.com/mgechev/revive.git
				synced 2025-10-30 23:37:49 +02:00 
			
		
		
		
	| @@ -464,14 +464,15 @@ List of all available rules. The rules ported from `golint` are left unchanged a | ||||
| | [`function-length`](./RULES_DESCRIPTIONS.md#function-length)          |  n/a   |  Warns on functions exceeding the statements or lines max |    no    |  no   | | ||||
| | [`nested-structs`](./RULES_DESCRIPTIONS.md#nested-structs)          |  n/a   |  Warns on structs within structs |    no    |  no   | | ||||
| | [`useless-break`](./RULES_DESCRIPTIONS.md#useless-break)          |  n/a   |  Warns on useless `break` statements in case clauses |    no    |  no   | | ||||
| | [`banned-characters`](./RULES_DESCRIPTIONS.md#banned-characters)          |  n/a   |  Checks banned characters in identifiers |    no    |  no   | | ||||
|  | ||||
| ## Configurable rules | ||||
|  | ||||
| Here you can find how you can configure some of the existing rules: | ||||
| Here you can find how you can configure some existing rules: | ||||
|  | ||||
| ### `var-naming` | ||||
|  | ||||
| This rule accepts two slices of strings, a whitelist and a blacklist of initialisms. By default the rule behaves exactly as the alternative in `golint` but optionally, you can relax it (see [golint/lint/issues/89](https://github.com/golang/lint/issues/89)) | ||||
| This rule accepts two slices of strings, a whitelist and a blacklist of initialisms. By default, the rule behaves exactly as the alternative in `golint` but optionally, you can relax it (see [golint/lint/issues/89](https://github.com/golang/lint/issues/89)) | ||||
|  | ||||
| ```toml | ||||
| [rule.var-naming] | ||||
|   | ||||
| @@ -8,6 +8,7 @@ List of all available rules. | ||||
|   - [argument-limit](#argument-limit) | ||||
|   - [atomic](#atomic) | ||||
|   - [bare-return](#bare-return) | ||||
|   - [banned-characters](#banned-characters) | ||||
|   - [blank-imports](#blank-imports) | ||||
|   - [bool-literal-in-expr](#bool-literal-in-expr) | ||||
|   - [call-to-gc](#call-to-gc) | ||||
| @@ -115,6 +116,19 @@ _Description_: Warns on bare (a.k.a. naked) returns | ||||
|  | ||||
| _Configuration_: N/A | ||||
|  | ||||
| ## banned-characters | ||||
|  | ||||
| _Description_: Checks given banned characters in identifiers(func, var, const). Comments are not checked. | ||||
|  | ||||
| _Configuration_: This rule accepts a slice of strings, the characters to ban. | ||||
|  | ||||
| Example: | ||||
|  | ||||
| ```toml | ||||
| [rule.banned-characters] | ||||
|   arguments =["Ω","Σ","σ"] | ||||
| ``` | ||||
|  | ||||
| ## blank-imports | ||||
|  | ||||
| _Description_: Blank import should be only in a main or test package, or have a comment justifying it. | ||||
|   | ||||
| @@ -82,6 +82,7 @@ var allRules = append([]lint.Rule{ | ||||
| 	&rule.IfReturnRule{}, | ||||
| 	&rule.UselessBreak{}, | ||||
| 	&rule.TimeEqualRule{}, | ||||
| 	&rule.BannedCharsRule{}, | ||||
| }, defaultRules...) | ||||
|  | ||||
| var allFormatters = []lint.Formatter{ | ||||
| @@ -111,7 +112,7 @@ func GetLintingRules(config *lint.Config) ([]lint.Rule, error) { | ||||
| 		rulesMap[r.Name()] = r | ||||
| 	} | ||||
|  | ||||
| 	lintingRules := []lint.Rule{} | ||||
| 	var lintingRules []lint.Rule | ||||
| 	for name, ruleConfig := range config.Rules { | ||||
| 		rule, ok := rulesMap[name] | ||||
| 		if !ok { | ||||
|   | ||||
							
								
								
									
										46
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								go.sum
									
									
									
									
									
								
							| @@ -1,35 +1,20 @@ | ||||
| github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= | ||||
| github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||||
| github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= | ||||
| github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= | ||||
| github.com/chavacava/garif v0.0.0-20210405163807-87a70f3d418b h1:StHNkfM8nXnNQnk5/0uYYhIqvvENd14hoHPnZsakTNo= | ||||
| github.com/chavacava/garif v0.0.0-20210405163807-87a70f3d418b/go.mod h1:Qjyv4H3//PWVzTeCezG2b9IRn6myJxJSr4TD/xo6ojU= | ||||
| github.com/chavacava/garif v0.0.0-20210405164556-e8a0a408d6af h1:spmv8nSH9h5oCQf40jt/ufBCt9j0/58u4G+rkeMqXGI= | ||||
| github.com/chavacava/garif v0.0.0-20210405164556-e8a0a408d6af/go.mod h1:Qjyv4H3//PWVzTeCezG2b9IRn6myJxJSr4TD/xo6ojU= | ||||
| github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= | ||||
| github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= | ||||
| github.com/fatih/color v1.11.0 h1:l4iX0RqNnx/pU7rY2DB/I+znuYY0K3x6Ywac6EIr0PA= | ||||
| github.com/fatih/color v1.11.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= | ||||
| github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc= | ||||
| github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= | ||||
| github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= | ||||
| github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= | ||||
| github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= | ||||
| github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= | ||||
| github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= | ||||
| github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= | ||||
| github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= | ||||
| github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= | ||||
| github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= | ||||
| github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= | ||||
| github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= | ||||
| github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= | ||||
| github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= | ||||
| github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= | ||||
| github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81 h1:QASJXOGm2RZ5Ardbc86qNFvby9AqkLDibfChMtAg5QM= | ||||
| github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg= | ||||
| github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 h1:zpIH83+oKzcpryru8ceC6BxnoG8TBrhgAvRg8obzup0= | ||||
| github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg= | ||||
| github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= | ||||
| @@ -43,59 +28,30 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN | ||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||
| github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||||
| github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||
| github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | ||||
| github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= | ||||
| github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= | ||||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||||
| golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||||
| golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= | ||||
| golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= | ||||
| golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= | ||||
| golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= | ||||
| golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||||
| golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||||
| golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= | ||||
| golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= | ||||
| golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||||
| golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= | ||||
| golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= | ||||
| golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= | ||||
| golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= | ||||
| golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||
| golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||
| golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= | ||||
| golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= | ||||
| golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= | ||||
| golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= | ||||
| golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA= | ||||
| golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= | ||||
| golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= | ||||
| golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= | ||||
| golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= | ||||
| golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= | ||||
| golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= | ||||
| golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= | ||||
| golang.org/x/tools v0.1.6 h1:SIasE1FVIQOWz2GEAHFOmoW7xchJcqlucjSULTL0Ag4= | ||||
| golang.org/x/tools v0.1.6/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= | ||||
| golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= | ||||
| golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= | ||||
| golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
|   | ||||
| @@ -11,7 +11,7 @@ type DisabledInterval struct { | ||||
| 	RuleName string | ||||
| } | ||||
|  | ||||
| // Rule defines an abstract rule interaface | ||||
| // Rule defines an abstract rule interface | ||||
| type Rule interface { | ||||
| 	Name() string | ||||
| 	Apply(*File, Arguments) []Failure | ||||
|   | ||||
							
								
								
									
										78
									
								
								rule/banned-characters.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								rule/banned-characters.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,78 @@ | ||||
| package rule | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"go/ast" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/mgechev/revive/lint" | ||||
| ) | ||||
|  | ||||
| // BannedCharsRule checks if a file contains banned characters. | ||||
| type BannedCharsRule struct{} | ||||
|  | ||||
| const bannedCharsRuleName = "banned-characters" | ||||
|  | ||||
| // Apply applied the rule to the given file. | ||||
| func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { | ||||
| 	var failures []lint.Failure | ||||
|  | ||||
| 	checkNumberOfArguments(1, arguments, bannedCharsRuleName) | ||||
| 	bannedCharList := r.getBannedCharsList(arguments) | ||||
|  | ||||
| 	onFailure := func(failure lint.Failure) { | ||||
| 		failures = append(failures, failure) | ||||
| 	} | ||||
|  | ||||
| 	w := lintBannedCharsRule{ | ||||
| 		bannedChars: bannedCharList, | ||||
| 		onFailure:   onFailure, | ||||
| 	} | ||||
| 	ast.Walk(w, file.AST) | ||||
| 	return failures | ||||
| } | ||||
|  | ||||
| // Name returns the rule name | ||||
| func (r *BannedCharsRule) Name() string { | ||||
| 	return bannedCharsRuleName | ||||
| } | ||||
|  | ||||
| // getBannedCharsList converts arguments into the banned characters list | ||||
| func (r *BannedCharsRule) getBannedCharsList(args lint.Arguments) []string { | ||||
| 	var bannedChars []string | ||||
| 	for _, char := range args { | ||||
| 		charStr, ok := char.(string) | ||||
| 		if !ok { | ||||
| 			panic(fmt.Sprintf("Invalid argument for the %s rule: expecting a string, got %T", r.Name(), char)) | ||||
| 		} | ||||
| 		bannedChars = append(bannedChars, charStr) | ||||
| 	} | ||||
|  | ||||
| 	return bannedChars | ||||
| } | ||||
|  | ||||
| type lintBannedCharsRule struct { | ||||
| 	bannedChars []string | ||||
| 	onFailure   func(lint.Failure) | ||||
| } | ||||
|  | ||||
| // Visit checks for each node if an identifier contains banned characters | ||||
| func (w lintBannedCharsRule) Visit(node ast.Node) ast.Visitor { | ||||
| 	n, ok := node.(*ast.Ident) | ||||
| 	if !ok { | ||||
| 		return w | ||||
| 	} | ||||
| 	for _, c := range w.bannedChars { | ||||
| 		ok := strings.Contains(n.Name, c) | ||||
| 		if ok { | ||||
| 			w.onFailure(lint.Failure{ | ||||
| 				Confidence: 1, | ||||
| 				Failure:    fmt.Sprintf("banned character found: %s", c), | ||||
| 				RuleName:   bannedCharsRuleName, | ||||
| 				Node:       n, | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return w | ||||
| } | ||||
| @@ -61,7 +61,7 @@ func (w bareReturnFinder) Visit(node ast.Node) ast.Visitor { | ||||
| 	_, ok := node.(*ast.FuncLit) | ||||
| 	if ok { | ||||
| 		// skip analysing function literals | ||||
| 		// they will analyzed by the lintBareReturnRule.Visit method | ||||
| 		// they will be analysed by the lintBareReturnRule.Visit method | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -54,7 +54,7 @@ func (w *lintStringInt) Visit(node ast.Node) ast.Visitor { | ||||
| 	w.onFailure(lint.Failure{ | ||||
| 		Confidence: 1, | ||||
| 		Node:       ce, | ||||
| 		Failure:    "dubious convertion of an integer into a string, use strconv.Itoa", | ||||
| 		Failure:    "dubious conversion of an integer into a string, use strconv.Itoa", | ||||
| 	}) | ||||
|  | ||||
| 	return w | ||||
|   | ||||
| @@ -184,7 +184,7 @@ func (w *lintNames) Visit(n ast.Node) ast.Visitor { | ||||
| 		} | ||||
| 	case *ast.InterfaceType: | ||||
| 		// Do not check interface method names. | ||||
| 		// They are often constrainted by the method names of concrete types. | ||||
| 		// They are often constrained by the method names of concrete types. | ||||
| 		for _, x := range v.Methods.List { | ||||
| 			ft, ok := x.Type.(*ast.FuncType) | ||||
| 			if !ok { // might be an embedded interface name | ||||
|   | ||||
							
								
								
									
										17
									
								
								test/banned-characters_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								test/banned-characters_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| package test | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/mgechev/revive/lint" | ||||
| 	"github.com/mgechev/revive/rule" | ||||
| ) | ||||
|  | ||||
| // Test banned characters in a const, var and func names. | ||||
| // One banned character is in the comment and should not be checked. | ||||
| // One banned character from the list is not present in the fixture file. | ||||
| func TestBannedCharacters(t *testing.T) { | ||||
| 	testRule(t, "banned-characters", &rule.BannedCharsRule{}, &lint.RuleConfig{ | ||||
| 		Arguments: []interface{}{"Ω", "Σ", "σ", "1"}, | ||||
| 	}) | ||||
| } | ||||
| @@ -125,7 +125,7 @@ func assertFailures(t *testing.T, baseDir string, fi os.FileInfo, src []byte, ru | ||||
|  | ||||
| type instruction struct { | ||||
| 	Line        int    // the line number this applies to | ||||
| 	Match       string // what pattern to match | ||||
| 	Match       string // which pattern to match | ||||
| 	Replacement string // what the suggested replacement line should be | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										9
									
								
								testdata/banned-characters.go
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								testdata/banned-characters.go
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| package fixtures | ||||
|  | ||||
| const Ω = "Omega" // MATCH:3 /banned character found: Ω/ | ||||
|  | ||||
| // func contains banned characters Ω // authorized banned chars in comment | ||||
| func funcΣ() error { // MATCH:6 /banned character found: Σ/ | ||||
| 	var charσhid string // MATCH:7 /banned character found: σ/ | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										12
									
								
								testdata/string-of-int.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								testdata/string-of-int.go
									
									
									
									
										vendored
									
									
								
							| @@ -19,12 +19,12 @@ func StringTest() { | ||||
| 		o struct{ x int } | ||||
| 	) | ||||
| 	const p = 0 | ||||
| 	_ = string(i) // MATCH /dubious convertion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = string(i) // MATCH /dubious conversion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = string(j) | ||||
| 	_ = string(k) | ||||
| 	_ = string(p)    // MATCH /dubious convertion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = A(l)         // MATCH /dubious convertion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = B(m)         // MATCH /dubious convertion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = string(n[1]) // MATCH /dubious convertion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = string(o.x)  // MATCH /dubious convertion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = string(p)    // MATCH /dubious conversion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = A(l)         // MATCH /dubious conversion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = B(m)         // MATCH /dubious conversion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = string(n[1]) // MATCH /dubious conversion of an integer into a string, use strconv.Itoa/ | ||||
| 	_ = string(o.x)  // MATCH /dubious conversion of an integer into a string, use strconv.Itoa/ | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user