mirror of
				https://github.com/koalaman/shellcheck.git
				synced 2025-10-31 14:39:20 +08:00 
			
		
		
		
	Realign virtual tabs when applying fix
Fix an off-by-one error, in the case that is commented `should never happen`. It happens when the end of a range is the at the end of a line. In that case we should update the real column count (probably just by +1) instead of returning it. I modified makeNonVirtual to use a helper, realign, that works on Ranged. That way we can share the code to realign a PositionedComment and also a Replacement. Fixes #1420
This commit is contained in:
		| @@ -16,20 +16,38 @@ class Ranged a where | ||||
|             yEnd = end y | ||||
|             xStart = start x | ||||
|             xEnd = end x | ||||
|     -- Set a new start and end position on a Ranged | ||||
|     setRange :: (Position, Position) -> a -> a | ||||
|  | ||||
| instance Ranged PositionedComment where | ||||
|     start = pcStartPos | ||||
|     end = pcEndPos | ||||
|     setRange (s, e) pc = pc { | ||||
|         pcStartPos = s, | ||||
|         pcEndPos = e | ||||
|     } | ||||
|  | ||||
| instance Ranged Replacement where | ||||
|     start = repStartPos | ||||
|     end   = repEndPos | ||||
|     setRange (s, e) r = r { | ||||
|         repStartPos = s, | ||||
|         repEndPos = e | ||||
|     } | ||||
|  | ||||
| instance Ranged a => Ranged [a] where | ||||
|     start [] = newPosition | ||||
|     start xs = (minimum . map start) xs | ||||
|     end []   = newPosition | ||||
|     end xs   = (maximum . map end) xs | ||||
|     setRange (s, e) rs = map (setRange (s, e)) rs | ||||
|  | ||||
| instance Ranged Fix where | ||||
|     start = start . fixReplacements | ||||
|     end   = end . fixReplacements | ||||
|     setRange (s, e) f = f { | ||||
|         fixReplacements = setRange (s, e) (fixReplacements f) | ||||
|     } | ||||
|  | ||||
| -- The Monoid instance for Fix merges replacements that do not overlap. | ||||
| instance Monoid Fix where | ||||
|   | ||||
		Reference in New Issue
	
	Block a user