Page MenuHomePhabricator

[lint] support optional newlines when linting python's open function

Authored by PiRK on Fri, May 12, 19:20.



This prevents false positives when linting code like this one:

with open(
    os.path.join(os.path.dirname(__file__), "ignore-logs.txt"), "rb"
) as ignoreList:
    self.ignoreList = ignoreList.readlines()
Test Plan

Remove a few encoding="utf-8" in python code and check that the linter still detects them, with or without newlines.

arc lint --everything

Diff Detail

rABC Bitcoin ABC
Lint Not Applicable
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Fri, May 12, 19:20

make the regex more robust:

  • support any number of spaces before "r" using \s+ (this also matches newlines)
  • use the s (dotall) modifier: this makes .* potentially match newlines

Run arc lint --everything to confirm it works on existing code, and check various line splittings for an open(...) call (ensure no false positives and no false negatives)

This revision is now accepted and ready to land.Fri, May 12, 19:50