Skip to content

Commit

Permalink
Add support for the --stdin/etc flags, to match webapp's ka-lint.
Browse files Browse the repository at this point in the history
Summary:
As part of the move of ka-lint from khan-linter to webapp, I'd like to
make the two drop-in replace-able with each other.  That means they
need to support the same flags -- or, at least, that this old version
supports all the flags that the new version does.

This commit adds that.  I add `--stdin` for real, and I add `--fix`
and `--fast` as noops.

Test Plan:
In webapp, I ran
   ka-lint -v main.py
   ka-lint -v --fast --fix main.py
   echo main.py | ka-lint -v --stdin
and they all succeeded with success, having linted one file.

I then ran
   ka-lint -v
   ka-lint -v --stdin </dev/null
and they both exited without doing any work.

Reviewers: benkraft, davidbraley

Reviewed By: benkraft, davidbraley

Subscribers: kevinb

Differential Revision: https://phabricator.khanacademy.org/D63417
  • Loading branch information
csilvers committed May 26, 2020
1 parent 1e05bc3 commit b1cf8a2
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions runlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ def main(files_and_directories,
% (num_new_errors, elapsed))
except Exception:
_get_logger().error(u"ERROR linting %r with %s:\n%s" % (
files, type(lint_processor), traceback.format_exc()))
files, type(lint_processor),
traceback.format_exc().decode('utf-8')))
num_framework_errors += 1
continue

Expand Down Expand Up @@ -877,11 +878,29 @@ def main(files_and_directories,
default=False,
help=('Propose patches that arc can apply to fix lint'
'errors. Only useful when used with phabricator.'))
parser.add_option('--stdin', action='store_true', default=False,
help=('Read list of files from stdin rather than '
'the commandline. We do not auto-pull in '
'this case.'))
parser.add_option('--fast', action='store_true', default=False,
help=("Ignored; for compatibility with webapp's "
"ka-lint"))
parser.add_option('--fix', action='store_true', default=False,
help=("Ignored; for compatibility with webapp's "
"ka-lint"))
parser.add_option('--verbose', '-v', action='store_true', default=False,
help='Print information about what is happening.')

options, args = parser.parse_args()
if not args:

if options.stdin:
filenames = sys.stdin.read().splitlines()
# We can't auto-pull because we'd lose stdin when we re-exec'ed.
options.no_auto_pull = True
else:
filenames = args

if not filenames:
# We used to lint the whole directory-tree when args was null,
# but we want to be able to run
# git ls-files ... | xargs runlint.py
Expand All @@ -903,7 +922,7 @@ def main(files_and_directories,

# normal operation
(num_lint_errors, num_framework_errors) = main(
args,
filenames,
options.blacklist, options.blacklist_filename,
options.extra_linter, options.lang, options.verbose,
options.propose_arc_fixes)
Expand Down

0 comments on commit b1cf8a2

Please sign in to comment.