Skip to content

Commit

Permalink
Have the ka-lint on $PATH run webapp's ka-lint when appropriate!
Browse files Browse the repository at this point in the history
Summary:
This is the final step of hooking up webapp's testing/ka-lint binary
to replace khan-linter for linting files within webapp.

The driver script that tools and people run manually, `ka-lint`, is
now a shell script that dispatches to either khan-linter's runlint.py
or webapp's testing/ka-lint, depending on where it's called from.

Issue: https://khanacademy.atlassian.net/browse/INFRA-4781

Test Plan:
I ran
   touch /tmp/README
   ka-lint /tmp/README
from both /tmp and from webapp-root.  I got different output -- the
second complained that you can only lint webapp files from within
webapp -- showing that it was dispatching correctly.

Reviewers: benkraft, davidbraley

Reviewed By: benkraft, davidbraley

Subscribers: kevinb

Differential Revision: https://phabricator.khanacademy.org/D63551
  • Loading branch information
csilvers committed Jun 4, 2020
1 parent e750413 commit bf190b8
Showing 1 changed file with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion bin/ka-lint

This file was deleted.

28 changes: 28 additions & 0 deletions bin/ka-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# A script that calls the proper runlint.py for the repo you are
# currently in.
#
# For repos, such as webapp, that define their own ka-lint --
# either at the top level or in <top-level>/testing -- we run
# their ka-lint. Otherwise we run runlint.py in khan-linter.
#
# Note that if you are in webapp-root, say, and run
# ka-lint /tmp/whatever
# we will still use webapp's linter even though you are linting a file
# outside webapp. There's no great way to do otherwise -- what do we do
# for
# ka-lint webapp_file.py /tmp/whatever
# ? Separate into separate ka-lint calls? It's a mess. And I
# don't expect people to do this outside-repo linting anyway, so I'm not
# going to worry about it for now.

repo_root=$(git rev-parse --show-toplevel 2>/dev/null)

if [ -n "$repo_root" -a -e "$repo_root/testing/ka-lint" ]; then
exec "$repo_root/testing/ka-lint" "$@"
elif [ -n "$repo_root" -a -e "$repo_root/ka-lint" ]; then
exec "$repo_root/ka-lint" "$@"
else
exec "$(dirname "${BASH_SOURCE[0]}")/../runlint.py" "$@"
fi

0 comments on commit bf190b8

Please sign in to comment.