Warning for hardcoded tmp path

Python pattern

Detected hardcoded temp directory. Consider using tempfile.TemporaryFile instead


Apply with the Grit CLI
grit apply warning_for_hardcoded_tmp_path

Warning for hardcoded tmp path

BEFORE
def test1():
    f = open("/tmp/blah.txt", 'w')
    f.write("hello world")
    f.close()

def test2():
    f = open("/tmp/blah/blahblah/blah.txt", 'r')
    data = f.read()
    f.close()

def test3():
    f = open("./tmp/blah.txt", 'w')
    f.write("hello world")
    f.close()

def test3a():
    f = open("/var/log/something/else/tmp/blah.txt", 'w')
    f.write("hello world")
    f.close()

def test4():
    with open("/tmp/blah.txt", 'r') as fin:
        data = fin.read()

def test5():
    with open("./tmp/blah.txt", 'w') as fout:
        fout.write("hello world")
AFTER
def test1():
    # BAD: hardcoded tmp path 
    f = open("/tmp/blah.txt", 'w')
    f.write("hello world")
    f.close()

def test2():
    # BAD: hardcoded tmp path 
    f = open("/tmp/blah/blahblah/blah.txt", 'r')
    data = f.read()
    f.close()

def test3():
    f = open("./tmp/blah.txt", 'w')
    f.write("hello world")
    f.close()

def test3a():
    f = open("/var/log/something/else/tmp/blah.txt", 'w')
    f.write("hello world")
    f.close()

def test4():
    # BAD: hardcoded tmp path 
    with open("/tmp/blah.txt", 'r') as fin:
        data = fin.read()

def test5():
    with open("./tmp/blah.txt", 'w') as fout:
        fout.write("hello world")