tests.toml (2967B)
1 [ratchet.regex.exceptions] 2 regex = "except:" 3 valid = [ 4 """try: 5 x = 1 6 except ValueError: 7 pass""", 8 """try: 9 do_something() 10 except (IOError, ValueError): 11 handle()""" 12 ] 13 invalid = [ 14 """ 15 try: 16 pass 17 except: 18 pass""", 19 """try: 20 dangerous() 21 except: 22 recover()""" 23 ] 24 description = "Bare except clauses catch all exceptions indiscriminately. This can hide bugs and important exceptions. To mitigate this, explicitly state the exception types that will be handled in the except clause." 25 26 27 [ratchet.regex.lightning] 28 regex = "import pytorch_lightning|from pytorch_lightning" 29 valid = ["import torch", "from my_project import Trainer"] 30 invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] 31 description = "The standard PyTorch library should be used in lieu of the PyTorch Lightning package." 32 33 34 [ratchet.regex.no_wildcard_imports] 35 regex = "from\\s+[^\\s]+\\s+import\\s+\\*" 36 valid = [ 37 "from module import name1, name2", 38 "import module", 39 "from package.subpackage import ClassA" 40 ] 41 invalid = [ 42 "from math import *", 43 "from mypkg.utils import *" 44 ] 45 description = "Wildcard imports make it unclear which names are in scope and can cause conflicts. Always import only the explicit names you need." 46 47 48 [ratchet.regex.tabs] 49 regex = "\\t" 50 valid = [ 51 """def foo(): 52 return 42""", 53 "print('no tab here')" 54 ] 55 invalid = [ 56 """\tprint('starts with tab')""", 57 """def bar(): 58 \treturn True""" 59 ] 60 description = "As per the PEP 8 style guide for Python code, spaces are to be used instead of tabs for indentation. To mitigate this issue, run 'black FILENAME' to reformat the file with black, or manually fix the issue and update your editor to replace tabs with space." 61 62 63 [ratchet.regex.trailing_whitespace] 64 regex = "[ \\t]+$" 65 valid = [ 66 "def foo():\n return 42", 67 "x = 1 # comment" 68 ] 69 invalid = [ 70 "def foo(): \n return 42\t" 71 ] 72 description = "Trailing whitespace is invisible but can cause noise in diffs and editors." 73 74 75 [ratchet.regex.ensure_trailing_newline] 76 regex = "\\Z(?<!\\n)\\Z" 77 valid = [ 78 "# some code\n\n" 79 ] 80 invalid = [ 81 "# code without trailing newline" 82 ] 83 description = "Text files should end with a newline character to satisfy POSIX tools and avoid diff noise." 84 85 86 [ratchet.regex.no_todo_comments] 87 regex = "(?i)#.*\\b(?:TODO|FIXME)\\b" 88 valid = [ 89 "# This is a regular comment without keywords", 90 "print('TODO in string literal is not caught as a comment')", 91 "x = 42 # calculation complete" 92 ] 93 invalid = [ 94 "# TODO: implement this function", 95 " # FIXME handle edge cases", 96 "def foo():\n # todo: remove debug code", 97 "some_var = 'value' # FIXME: adjust value later" 98 ] 99 description = "Ensure no TODO or FIXME comments remain in code." 100 101 102 [ratchet.shell.line_too_long] 103 command = "xargs -n1 awk 'length($0) > 88'" 104 description = "Black sets the max line-width to 88 to help with the readability of code. Ensure all lines have <89 characters. You can run 'black FILENAME' to fix this issue."