mirror of
				https://github.com/koalaman/shellcheck.git
				synced 2025-11-04 09:26:10 +08:00 
			
		
		
		
	Added check for [[ foo == $bar ]]
This commit is contained in:
		@@ -38,6 +38,7 @@ basicChecks = [
 | 
			
		||||
    ,checkForDecimals
 | 
			
		||||
    ,checkDivBeforeMult
 | 
			
		||||
    ,checkArithmeticDeref
 | 
			
		||||
    ,checkComparisonAgainstGlob
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
modifyMap = modify
 | 
			
		||||
@@ -260,6 +261,13 @@ checkArithmeticDeref (TA_Expansion _ (T_DollarBraced id str)) | not $ any (`elem
 | 
			
		||||
    addNoteFor id $ Note WarningC $ "Don't use $ on variables in (( )) unless you want to dereference twice"
 | 
			
		||||
checkArithmeticDeref _ = return ()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
prop_checkComparisonAgainstGlob = verify checkComparisonAgainstGlob "[[ $cow == $bar ]]"
 | 
			
		||||
prop_checkComparisonAgainstGlob2 = verifyNot checkComparisonAgainstGlob "[[ $cow == \"$bar\" ]]"
 | 
			
		||||
checkComparisonAgainstGlob (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _])) | op == "=" || op == "==" = 
 | 
			
		||||
    addNoteFor id $ Note WarningC $ "Quote the rhs of = in [[ ]] to prevent glob interpretation"
 | 
			
		||||
checkComparisonAgainstGlob _ = return ()
 | 
			
		||||
 | 
			
		||||
allModifiedVariables t = snd $ runState (doAnalysis (\x -> modify $ (++) (getModifiedVariables x)) t) []
 | 
			
		||||
 | 
			
		||||
--- Subshell detection
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user