[Tutor] Quick Pythonic Style Tips

Cameron Simpson cs at zip.com.au
Sun Jul 23 19:22:02 EDT 2017

On 23Jul2017 19:02, Abdur-Rahmaan Janhangeer <arj.python at gmail.com> wrote:
>ah pylint yes, great checker ! *some guys thought of inventing it*

Yes, very handy. Greate for checking for simple logic errors too (variable used 
but never bound, missing imports, etc).

Just for folks' interest, I have a shell script called "lint" which I use which 
encapsulates my personal lint practices. Great for a final check before 
committing code.  I append it for anyone else to use or adapt.

Interactively I've got a personal shell function called "lint" which, if no 
files are specificly named, runs that script against whatever files are 
currently modified in my working code repo.  So one can just say "lint" at the 
shell prompt to get a report on one's work in progress.

Script appended below.

Cameron Simpson <cs at zip.com.au>

# Lint the named files.
#   - Cameron Simpson <cs at zip.com.au> 22apr2017

set -ue

[ -t 2 ] && trace=set-x

usage="Usage: $cmd filenames..."

[ $# -gt 0 ] || { echo "$cmd: missing filenames" >&2; echo "$usage" >&2; exit 2; }


for lintfile
  case "$lintfile" in
      $trace json-pprint <"$lintfile" 2>&1 >/dev/null || xit=1
      $trace go tool vet -all -shadowstrict "$lintfile" || xit=1
      { $trace php -l "$lintfile" \
        && $trace phpcs --standard=PSR2 --report=emacs "$lintfile"
      } || xit=1
      { $trace python3 -m py_compile "$lintfile" \
        && $trace pyflakes-2.7 "$lintfile" \
        && $trace pep8 --ignore=E111,E114,E126,E201,E202,E265,E266,E301,E302,E501,E731,W503 "$lintfile" \
        && $trace pylint "$lintfile"
      } || xit=1
    *)echo "$cmd: no lint for $lintfile"

exit $xit

More information about the Tutor mailing list