diff --git a/tools/lib/provision.py b/tools/lib/provision.py index fb475b1a98..deb1af8e01 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -385,6 +385,9 @@ def main(options): # Install shellcheck. run_as_root(["tools/setup/install-shellcheck"]) + # Install sgrep. + run_as_root(["tools/setup/install-sgrep"]) + setup_venvs.main() run_as_root(["cp", REPO_STOPWORDS_PATH, TSEARCH_STOPWORDS_PATH]) diff --git a/tools/lint b/tools/lint index 09404fe416..02ac0bb594 100755 --- a/tools/lint +++ b/tools/lint @@ -92,6 +92,11 @@ def run(): description="Checks commit messages for common formatting errors." "(config: .gitlint)") + sgrep_command = ["sgrep-lint", "--config=./tools/sgrep.yml", "--error"] + linter_config.external_linter('sgrep-py', [*sgrep_command, "--lang=python"], ['py'], + description="Syntactic Grep (sgrep) Code Search Tool " + "(config: ./tools/sgrep.yml)") + @linter_config.lint def custom_py(): # type: () -> int diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 5ad8755939..4307eee9c2 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -415,9 +415,6 @@ python_rules = RuleList( 'description': "Don't use datetime in backend code.\n" "See https://zulip.readthedocs.io/en/latest/contributing/code-style.html#naive-datetime-objects", }, - {'pattern': r'render_to_response\(', - 'description': "Use render() instead of render_to_response().", - }, {'pattern': 'from os.path', 'description': "Don't use from when importing from the standard library", }, diff --git a/tools/setup/install-sgrep b/tools/setup/install-sgrep new file mode 100755 index 0000000000..293f5b84d6 --- /dev/null +++ b/tools/setup/install-sgrep @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -e + +version=0.4.9b5 +tarball=sgrep-$version-ubuntu-16.04.tgz +sha256=9e57323fd0eb9133b7ff301a6be8361c073c3bfe6e6959ca1b622e5abc176e03 +tarball_url=https://github.com/returntocorp/sgrep/releases/download/v$version/$tarball + +if ! out="$(sgrep-lint --version 2>/dev/null)" || [[ "$out" != "$version" ]] +then + tmpdir="$(mktemp -d)" + trap 'rm -r "$tmpdir"' EXIT + cd "$tmpdir" + wget -nv "$tarball_url" + sha256sum -c <<< "$sha256 $tarball" + tar -xzf "$tarball" -C /usr/local/lib/ + ln -sf /usr/local/lib/sgrep-lint-files/sgrep-lint /usr/local/bin/sgrep-lint + ln -sf /usr/local/lib/sgrep-lint-files/sgrep /usr/local/bin/sgrep +fi diff --git a/tools/sgrep.yml b/tools/sgrep.yml new file mode 100644 index 0000000000..e99823e67d --- /dev/null +++ b/tools/sgrep.yml @@ -0,0 +1,18 @@ +# See https://github.com/returntocorp/sgrep/blob/develop/docs/config.md for sgrep rule format + +rules: + - id: deprecated-render-usage + pattern: django.shortcuts.render_to_response(...) + message: Use render() (from django.shortcuts) instead of render_to_response() + languages: [python] + severity: ERROR + - id: useless-if-body + patterns: + - pattern: | + if $X: + $S + else: + $S + message: "useless if statment; both blocks have the same body" + languages: [python] + severity: ERROR diff --git a/version.py b/version.py index 4f642515ec..f610d0011d 100644 --- a/version.py +++ b/version.py @@ -34,4 +34,4 @@ DESKTOP_WARNING_VERSION = "5.0.0" # historical commits sharing the same major version, in which case a # minor version bump suffices. -PROVISION_VERSION = '75.5' +PROVISION_VERSION = '75.6'