Skip to content

Commit

Permalink
[#24671] YSQL: add postgres linter
Browse files Browse the repository at this point in the history
Summary:
Add a basic linter for postgres code using [arc lint
script-and-regex][1].  Implement the script using a bash script that
runs some grep searches on the given file.  It is not powerful enough to
check for certain things such as whether indentation is aligned properly
with respect to other lines, but it is still better to have some basic
enforcement over nothing.

[1]: https://secure.phabricator.com/book/phabricator/article/arcanist_lint_script_and_regex/
Jira: DB-13743

Test Plan:
manually check arc lint on a few postgres files

Close: #24671

Reviewers: mihnea, tfoucher

Reviewed By: tfoucher

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D36535
  • Loading branch information
jaki committed Oct 28, 2024
1 parent 9c0f84e commit 399e1e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
22 changes: 20 additions & 2 deletions .arclint
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"([.]sql$)",
"([.]txt$)",
"(^src/odyssey/.*$)",
"(^src/postgres/.*$)",
"(^src/yb/integration-tests/upgrade-tests/builds.xml$)",
"(^[.]gitmodules$)",
"(^managed/src/main/resources/alert/alert_templates[.]yml$)",
Expand Down Expand Up @@ -101,19 +100,25 @@
"(^docs/.*[.]md$)",
"(^[.]fossa[.]yml$)",
"(^managed/.*[.]conf)",
"(^src/postgres/)",
"(^[.]gitignore$)"
]
},
"pycodestyle": {
"type": "pep8",
"include": "([.]py$)",
"exclude": "(^thirdparty/|^[.]ycm_extra_conf[.]py$)",
"exclude": [
"(^[.]ycm_extra_conf[.]py$)",
"(^src/postgres/)",
"(^thirdparty/)"
],
"bin": "pycodestyle",
"flags": ["--max-line-length=100"]
},
"googlecpplint": {
"type": "googlecpplint",
"exclude": [
"(^src/postgres/)",
"(^src/yb/yql/cql/ql/kwlist[.]h$)",
"(^src/yb/gutil/linux_syscall_support[.]h$)",
"(^src/yb/gutil/cycleclock-inl[.]h$)",
Expand All @@ -140,6 +145,19 @@
"(^build/c[+][+]11$)": "disabled",
"(.*)": "error"
}
},
"postgres": {
"type": "script-and-regex",
"exclude": [
"(^src/yb/)"
],
"include": [
"([.]c$)",
"([.]h$)"
],
"script-and-regex.script": "src/postgres/ybsimplelint.sh",
"script-and-regex.regex":
"/^(?P<severity>\\w+):(?P<message>\\w+):(?P<line>\\d+):(?P<original>.*)/m"
}
}
}
13 changes: 13 additions & 0 deletions src/postgres/ybsimplelint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Simple linter for postgres code.
grep -nE '\s+$' "$1" | sed 's/^/error:trailing_whitespace:/'
grep -nvE '^( * {0,3}\S|$)' "$1" | sed 's/^/error:leading_whitespace:/'
grep -nE '(\)|else|else if)\s+{$' "$1" | sed 's/^/warning:likely_bad_brace:/'

grep -nE ',\s*errmsg(_plural)?\(' "$1" | sed 's/^/error:missing_linebreak_before_errmsg:/'
grep -nE ',\s*errdetail(_plural)?\(' "$1" | sed 's/^/error:missing_linebreak_before_errdetail:/'
grep -nE ',\s*errhint\(' "$1" | sed 's/^/error:missing_linebreak_before_errhint:/'

grep -nE 'errmsg(_plural)?\("[A-Z][a-z]' "$1" | sed 's/^/warning:likely_bad_capitalization_in_errmsg:/'
grep -nE 'errdetail(_plural)?\("[a-z]' "$1" | sed 's/^/warning:likely_bad_lowercase_in_errdetail:/'
grep -nE 'errhint\("[a-z]' "$1" | sed 's/^/warning:likely_bad_lowercase_in_errhint:/'

0 comments on commit 399e1e5

Please sign in to comment.