mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-08 02:59:55 +08:00
SC2183 grammer fix: 'variable' instead of 'variables' if only one variable
This commit is contained in:
@@ -675,6 +675,7 @@ checkPrintfVar = CommandCheck (Exactly "printf") (f . arguments) where
|
|||||||
let formats = getPrintfFormats string
|
let formats = getPrintfFormats string
|
||||||
let formatCount = length formats
|
let formatCount = length formats
|
||||||
let argCount = length more
|
let argCount = length more
|
||||||
|
let pluraliseIfMany word n = if n > 1 then word ++ "s" else word
|
||||||
|
|
||||||
return $ if
|
return $ if
|
||||||
| argCount == 0 && formatCount == 0 ->
|
| argCount == 0 && formatCount == 0 ->
|
||||||
@@ -690,7 +691,8 @@ checkPrintfVar = CommandCheck (Exactly "printf") (f . arguments) where
|
|||||||
return () -- Great: a suitable number of arguments
|
return () -- Great: a suitable number of arguments
|
||||||
| otherwise ->
|
| otherwise ->
|
||||||
warn (getId format) 2183 $
|
warn (getId format) 2183 $
|
||||||
"This format string has " ++ show formatCount ++ " variables, but is passed " ++ show argCount ++ " arguments."
|
"This format string has " ++ show formatCount ++ " " ++ (pluraliseIfMany "variable" formatCount) ++
|
||||||
|
", but is passed " ++ show argCount ++ " arguments."
|
||||||
|
|
||||||
unless ('%' `elem` concat (oversimplify format) || isLiteral format) $
|
unless ('%' `elem` concat (oversimplify format) || isLiteral format) $
|
||||||
info (getId format) 2059
|
info (getId format) 2059
|
||||||
|
Reference in New Issue
Block a user