Page MenuHomePhabricator

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

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

Details

Summary

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

Repository
rABC Bitcoin ABC
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 23705
Build 47024: Build Diff
Build 47023: arc lint + arc unit

Event Timeline

PiRK requested review of this revision.May 12 2023, 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.May 12 2023, 19:50