Checking if the two lines are mattching the unwanted pattern. Parameters ---------- first_line : str First line to check. second_line : str Second line to check. Returns ------- bool True if the tw
(first_line: str, second_line: str)
| 208 | """ |
| 209 | |
| 210 | def has_wrong_whitespace(first_line: str, second_line: str) -> bool: |
| 211 | """ |
| 212 | Checking if the two lines are mattching the unwanted pattern. |
| 213 | |
| 214 | Parameters |
| 215 | ---------- |
| 216 | first_line : str |
| 217 | First line to check. |
| 218 | second_line : str |
| 219 | Second line to check. |
| 220 | |
| 221 | Returns |
| 222 | ------- |
| 223 | bool |
| 224 | True if the two received string match, an unwanted pattern. |
| 225 | |
| 226 | Notes |
| 227 | ----- |
| 228 | The unwanted pattern that we are trying to catch is if the spaces in |
| 229 | a string that is concatenated over multiple lines are placed at the |
| 230 | end of each string, unless this string is ending with a |
| 231 | newline character (\n). |
| 232 | |
| 233 | For example, this is bad: |
| 234 | |
| 235 | >>> rule = "We want the space at the end of the line, not at the beginning" |
| 236 | |
| 237 | And what we want is: |
| 238 | |
| 239 | >>> rule = "We want the space at the end of the line, not at the beginning" |
| 240 | |
| 241 | And if the string is ending with a new line character (\n) we |
| 242 | do not want any trailing whitespaces after it. |
| 243 | |
| 244 | For example, this is bad: |
| 245 | |
| 246 | >>> rule = ( |
| 247 | ... "We want the space at the begging of " |
| 248 | ... "the line if the previous line is ending with a \n " |
| 249 | ... "not at the end, like always" |
| 250 | ... ) |
| 251 | |
| 252 | And what we do want is: |
| 253 | |
| 254 | >>> rule = ( |
| 255 | ... "We want the space at the begging of " |
| 256 | ... "the line if the previous line is ending with a \n" |
| 257 | ... " not at the end, like always" |
| 258 | ... ) |
| 259 | """ |
| 260 | if first_line.endswith(r"\n"): |
| 261 | return False |
| 262 | elif first_line.startswith(" ") or second_line.startswith(" "): |
| 263 | return False |
| 264 | elif first_line.endswith(" ") or second_line.endswith(" "): |
| 265 | return False |
| 266 | elif (not first_line.endswith(" ")) and second_line.startswith(" "): |
| 267 | return True |
no test coverage detected