mirror of
				https://github.com/koalaman/shellcheck.git
				synced 2025-10-31 22:52:50 +08:00 
			
		
		
		
	Account for BusyBox support of [[ ]] (fixes #2967)
This commit is contained in:
		
				
					committed by
					
						 Friendfishermans
						Friendfishermans
					
				
			
			
				
	
			
			
			
						parent
						
							a13cb85f49
						
					
				
				
					commit
					844cfc2797
				
			
							
								
								
									
										8
									
								
								.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										8
									
								
								.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | # Default ignored files | ||||||
|  | /shelf/ | ||||||
|  | /workspace.xml | ||||||
|  | # Editor-based HTTP Client requests | ||||||
|  | /httpRequests/ | ||||||
|  | # Datasource local storage ignored files | ||||||
|  | /dataSources/ | ||||||
|  | /dataSources.local.xml | ||||||
							
								
								
									
										6
									
								
								.idea/inspectionProfiles/Project_Default.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										6
									
								
								.idea/inspectionProfiles/Project_Default.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | <component name="InspectionProjectProfileManager"> | ||||||
|  |   <profile version="1.0"> | ||||||
|  |     <option name="myName" value="Project Default" /> | ||||||
|  |     <inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true" /> | ||||||
|  |   </profile> | ||||||
|  | </component> | ||||||
							
								
								
									
										6
									
								
								.idea/inspectionProfiles/profiles_settings.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										6
									
								
								.idea/inspectionProfiles/profiles_settings.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | <component name="InspectionProjectProfileManager"> | ||||||
|  |   <settings> | ||||||
|  |     <option name="USE_PROJECT_PROFILE" value="false" /> | ||||||
|  |     <version value="1.0" /> | ||||||
|  |   </settings> | ||||||
|  | </component> | ||||||
							
								
								
									
										4
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										4
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" /> | ||||||
|  | </project> | ||||||
							
								
								
									
										8
									
								
								.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										8
									
								
								.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="ProjectModuleManager"> | ||||||
|  |     <modules> | ||||||
|  |       <module fileurl="file://$PROJECT_DIR$/.idea/shellcheck.iml" filepath="$PROJECT_DIR$/.idea/shellcheck.iml" /> | ||||||
|  |     </modules> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
							
								
								
									
										8
									
								
								.idea/shellcheck.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										8
									
								
								.idea/shellcheck.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <module type="PYTHON_MODULE" version="4"> | ||||||
|  |   <component name="NewModuleRootManager"> | ||||||
|  |     <content url="file://$MODULE_DIR$" /> | ||||||
|  |     <orderEntry type="inheritedJdk" /> | ||||||
|  |     <orderEntry type="sourceFolder" forTests="false" /> | ||||||
|  |   </component> | ||||||
|  | </module> | ||||||
							
								
								
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="VcsDirectoryMappings"> | ||||||
|  |     <mapping directory="" vcs="Git" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
| @@ -2,10 +2,12 @@ | |||||||
| ### Added | ### Added | ||||||
| - SC2327/SC2328: Warn about capturing the output of redirected commands. | - SC2327/SC2328: Warn about capturing the output of redirected commands. | ||||||
| - SC2329: Warn when (non-escaping) functions are never invoked. | - SC2329: Warn when (non-escaping) functions are never invoked. | ||||||
|  | - SC2330: Warn about unsupported glob matches with [[ .. ]] in BusyBox. | ||||||
| ### Changed | ### Changed | ||||||
| - SC2015 about `A && B || C` no longer triggers when B is a test command. | - SC2015 about `A && B || C` no longer triggers when B is a test command. | ||||||
| ### Fixed | ### Fixed | ||||||
| - SC2317 about unreachable commands is now less spammy for nested ones. | - SC2317 about unreachable commands is now less spammy for nested ones. | ||||||
|  | - SC2292, optional suggestion for [[ ]], now triggers for Busybox. | ||||||
|  |  | ||||||
|  |  | ||||||
| ## v0.10.0 - 2024-03-07 | ## v0.10.0 - 2024-03-07 | ||||||
|   | |||||||
| @@ -1525,6 +1525,7 @@ prop_checkComparisonAgainstGlob3 = verify checkComparisonAgainstGlob "[ $cow = * | |||||||
| prop_checkComparisonAgainstGlob4 = verifyNot checkComparisonAgainstGlob "[ $cow = foo ]" | prop_checkComparisonAgainstGlob4 = verifyNot checkComparisonAgainstGlob "[ $cow = foo ]" | ||||||
| prop_checkComparisonAgainstGlob5 = verify checkComparisonAgainstGlob "[[ $cow != $bar ]]" | prop_checkComparisonAgainstGlob5 = verify checkComparisonAgainstGlob "[[ $cow != $bar ]]" | ||||||
| prop_checkComparisonAgainstGlob6 = verify checkComparisonAgainstGlob "[ $f != /* ]" | prop_checkComparisonAgainstGlob6 = verify checkComparisonAgainstGlob "[ $f != /* ]" | ||||||
|  | prop_checkComparisonAgainstGlob7 = verify checkComparisonAgainstGlob "#!/bin/busybox sh\n[[ $f == *foo* ]]" | ||||||
| checkComparisonAgainstGlob _ (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _ _])) | checkComparisonAgainstGlob _ (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _ _])) | ||||||
|     | op `elem` ["=", "==", "!="] = |     | op `elem` ["=", "==", "!="] = | ||||||
|         warn id 2053 $ "Quote the right-hand side of " ++ op ++ " in [[ ]] to prevent glob matching." |         warn id 2053 $ "Quote the right-hand side of " ++ op ++ " in [[ ]] to prevent glob matching." | ||||||
| @@ -1532,10 +1533,14 @@ checkComparisonAgainstGlob params (TC_Binary _ SingleBracket op _ word) | |||||||
|         | op `elem` ["=", "==", "!="] && isGlob word = |         | op `elem` ["=", "==", "!="] && isGlob word = | ||||||
|     err (getId word) 2081 msg |     err (getId word) 2081 msg | ||||||
|   where |   where | ||||||
|     msg = if isBashLike params |     msg = if (shellType params) `elem` [Bash, Ksh]  -- Busybox does not support glob matching | ||||||
|             then "[ .. ] can't match globs. Use [[ .. ]] or case statement." |             then "[ .. ] can't match globs. Use [[ .. ]] or case statement." | ||||||
|             else "[ .. ] can't match globs. Use a case statement." |             else "[ .. ] can't match globs. Use a case statement." | ||||||
|  |  | ||||||
|  | checkComparisonAgainstGlob params (TC_Binary _ DoubleBracket op _ word) | ||||||
|  |         | shellType params == BusyboxSh && op `elem` ["=", "==", "!="] && isGlob word = | ||||||
|  |     err (getId word) 2330 "BusyBox [[ .. ]] does not support glob matching. Use a case statement." | ||||||
|  |  | ||||||
| checkComparisonAgainstGlob _ _ = return () | checkComparisonAgainstGlob _ _ = return () | ||||||
|  |  | ||||||
| prop_checkCaseAgainstGlob1 = verify checkCaseAgainstGlob "case foo in lol$n) foo;; esac" | prop_checkCaseAgainstGlob1 = verify checkCaseAgainstGlob "case foo in lol$n) foo;; esac" | ||||||
| @@ -4534,13 +4539,13 @@ prop_checkRequireDoubleBracket2 = verifyTree checkRequireDoubleBracket "[ foo -o | |||||||
| prop_checkRequireDoubleBracket3 = verifyNotTree checkRequireDoubleBracket "#!/bin/sh\n[ -x foo ]" | prop_checkRequireDoubleBracket3 = verifyNotTree checkRequireDoubleBracket "#!/bin/sh\n[ -x foo ]" | ||||||
| prop_checkRequireDoubleBracket4 = verifyNotTree checkRequireDoubleBracket "[[ -x foo ]]" | prop_checkRequireDoubleBracket4 = verifyNotTree checkRequireDoubleBracket "[[ -x foo ]]" | ||||||
| checkRequireDoubleBracket params = | checkRequireDoubleBracket params = | ||||||
|     if isBashLike params |     if (shellType params) `elem` [Bash, Ksh, BusyboxSh] | ||||||
|     then nodeChecksToTreeCheck [check] params |     then nodeChecksToTreeCheck [check] params | ||||||
|     else const [] |     else const [] | ||||||
|   where |   where | ||||||
|     check _ t = case t of |     check _ t = case t of | ||||||
|         T_Condition id SingleBracket _ -> |         T_Condition id SingleBracket _ -> | ||||||
|             styleWithFix id 2292 "Prefer [[ ]] over [ ] for tests in Bash/Ksh." (fixFor t) |             styleWithFix id 2292 "Prefer [[ ]] over [ ] for tests in Bash/Ksh/Busybox." (fixFor t) | ||||||
|         _ -> return () |         _ -> return () | ||||||
|  |  | ||||||
|     fixFor t = fixWith $ |     fixFor t = fixWith $ | ||||||
|   | |||||||
| @@ -902,16 +902,6 @@ supportsArrays Bash = True | |||||||
| supportsArrays Ksh = True | supportsArrays Ksh = True | ||||||
| supportsArrays _ = False | supportsArrays _ = False | ||||||
|  |  | ||||||
| -- Returns true if the shell is Bash or Ksh (sorry for the name, Ksh) |  | ||||||
| isBashLike :: Parameters -> Bool |  | ||||||
| isBashLike params = |  | ||||||
|     case shellType params of |  | ||||||
|         Bash -> True |  | ||||||
|         Ksh -> True |  | ||||||
|         Dash -> False |  | ||||||
|         BusyboxSh -> False |  | ||||||
|         Sh -> False |  | ||||||
|  |  | ||||||
| isTrueAssignmentSource c = | isTrueAssignmentSource c = | ||||||
|     case c of |     case c of | ||||||
|         DataString SourceChecked -> False |         DataString SourceChecked -> False | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user