Skip to content

Commit

Permalink
[#25447] YSQL: fix a lint rule related to spacing
Browse files Browse the repository at this point in the history
Summary:
1. Blacklist some paths for the bad_spacing_after_if_else_for_while lint
   rule.
1. Fix all issues with that lint rule.
Jira: DB-14690

Test Plan:
On Almalinux 8:

    [ -z "$(git ls-tree --name-only -rz HEAD -- src/postgres | grep -zE '\.(c|h)$' | xargs -0 arc lint | grep bad_spacing_after_if_else_for_while)" ]

Close: #25447
Jenkins: skip

Reviewers: dmitry

Reviewed By: dmitry

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D40916
  • Loading branch information
jaki committed Dec 27, 2024
1 parent cddedf8 commit 5e804f1
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/postgres/src/backend/commands/functioncmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,7 @@ AlterFunctionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
if (!superuser() && !IsYbDbAdminUser(GetUserId()))
{
/* Must be owner */
if(!has_privs_of_role(GetUserId(), proc->proowner))
if (!has_privs_of_role(GetUserId(), proc->proowner))
{
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION, NameStr(proc->proname));
}
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/commands/ybccmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ YBCCreateTable(CreateStmt *stmt, char *tableName, char relkind, TupleDesc desc,
Oid parentOid = RangeVarGetRelid(rv, NoLock, false);

Relation parentRel = table_open(parentOid, NoLock);
if(!MyDatabaseColocated || MyColocatedDatabaseLegacy)
if (!MyDatabaseColocated || MyColocatedDatabaseLegacy)
{
Assert(!OidIsValid(tablegroupId));
tablegroupId = YbGetTableProperties(parentRel)->tablegroup_oid;
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/executor/nodeYbBatchedNestloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ ExecYbBatchedNestLoop(PlanState *pstate)
case BNL_MATCHING:
Assert(!TupIsNull(econtext->ecxt_innertuple));

if(!LOCAL_JOIN_FN(GetNewOuterTuple, bnlstate, econtext))
if (!LOCAL_JOIN_FN(GetNewOuterTuple, bnlstate, econtext))
{
bnlstate->bnl_currentstatus = BNL_NEWINNER;
continue;
Expand Down Expand Up @@ -588,7 +588,7 @@ GetNewOuterTupleHash(YbBatchedNestLoopState *bnlstate, ExprContext *econtext)
eq,
bnlstate->innerHashFunctions,
bnlstate->innerAttrs);
if(data == NULL)
if (data == NULL)
{
/* Inner plan returned a tuple that doesn't match with anything. */
InstrCountFiltered1(bnlstate, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/src/backend/libpq/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -3613,7 +3613,7 @@ YbCheckJwtAuth(Port *port)
* fail to read the jwks file or the content is invalid.
* Check if jwt_jwks_url is provided then use that otherwise use jwt_jwks_path
*/
if(port->hba->yb_jwt_jwks_url)
if (port->hba->yb_jwt_jwks_url)
jwks = ybReadFromUrl(port->hba->yb_jwt_jwks_url);
else
jwks = ybReadFile(HbaFileName, port->hba->yb_jwt_jwks_path, LOG);
Expand Down Expand Up @@ -3733,11 +3733,11 @@ ybReadFromUrl(const char *url)
YBCFreeStatus(status);
return NULL;
}
if(!url_contents)
if (!url_contents)
return NULL;

len = strlen(url_contents);
if(!pg_verifymbstr(url_contents, len, true))
if (!pg_verifymbstr(url_contents, len, true))
{
ereport(LOG,
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/libpq/hba.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ parse_hba_line(TokenizedAuthLine *tok_line, int elevel)

if (parsedline->auth_method == uaYbJWT)
{
if(!(parsedline->yb_jwt_jwks_url || parsedline->yb_jwt_jwks_path))
if (!(parsedline->yb_jwt_jwks_url || parsedline->yb_jwt_jwks_path))
{
ereport(elevel,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/optimizer/path/indxpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -3177,7 +3177,7 @@ match_opclause_to_indexcol(PlannerInfo *root,
if (is_yb_hash_code_call(leftop) &&
!yb_hash_code_call_matches_indexcol(leftop, index, indexcol))
{
if(!op_in_opfamily(expr_op, INTEGER_LSM_FAM_OID) || !is_opclause(clause))
if (!op_in_opfamily(expr_op, INTEGER_LSM_FAM_OID) || !is_opclause(clause))
return NULL;

iclause = makeNode(IndexClause);
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/src/backend/optimizer/plan/createplan.c
Original file line number Diff line number Diff line change
Expand Up @@ -6623,7 +6623,7 @@ replace_nestloop_params_mutator(Node *node, PlannerInfo *root)
if (IsA(node, RowCompareExpr))
{
RowCompareExpr *rcexpr = (RowCompareExpr *) node;
if(rcexpr->rctype == ROWCOMPARE_EQ)
if (rcexpr->rctype == ROWCOMPARE_EQ)
{
RowCompareExpr *rcexpr_new = copyObject(rcexpr);
ArrayExpr *arrexpr = makeNode(ArrayExpr);
Expand All @@ -6648,8 +6648,8 @@ replace_nestloop_params_mutator(Node *node, PlannerInfo *root)
if (IsA(node, OpExpr))
{
OpExpr *opexpr = (OpExpr*) node;
if(list_length(opexpr->args) >= 2 &&
IsA(lsecond(opexpr->args), YbBatchedExpr))
if (list_length(opexpr->args) >= 2 &&
IsA(lsecond(opexpr->args), YbBatchedExpr))
{
ScalarArrayOpExpr *saop = makeNode(ScalarArrayOpExpr);
saop->opno = opexpr->opno;
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/optimizer/plan/setrefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2399,8 +2399,8 @@ set_join_references(PlannerInfo *root, Join *join, int rtoffset)

YbBNLHashClauseInfo *valid_bnl_hinfos = batchednl->hashClauseInfos;
int num_invalid = 0;
while(num_invalid < batchednl->num_hashClauseInfos &&
!OidIsValid(valid_bnl_hinfos->hashOp))
while (num_invalid < batchednl->num_hashClauseInfos &&
!OidIsValid(valid_bnl_hinfos->hashOp))
{
valid_bnl_hinfos++;
num_invalid++;
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/postmaster/postmaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -4570,7 +4570,7 @@ SetOomScoreAdjForPid(pid_t pid, char *oom_score_adj)
FILE * fPtr;
fPtr = fopen(file_name, "w");

if(fPtr == NULL)
if (fPtr == NULL)
{
int saved_errno = errno;
ereport(LOG,
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/utils/adt/timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ timestamptz_out(PG_FUNCTION_ARGS)
const char *tzn;
char buf[MAXDATELEN + 1];

if(PG_NARGS() == 2)
if (PG_NARGS() == 2)
{
decode_options = (DatumDecodeOptions *)PG_GETARG_POINTER(1);
}
Expand Down
5 changes: 2 additions & 3 deletions src/postgres/src/backend/utils/misc/yb_query_diagnostics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1881,9 +1881,8 @@ DumpToFile(const char *folder_path, const char *file_name, const char *data,
O_RDWR | O_CREAT | O_APPEND)) < 0)
snprintf(description, YB_QD_DESCRIPTION_LEN,
"out of file descriptors: %s; release and retry", strerror(errno));

else if(FileWrite(file, (char *)data, strlen(data), FileSize(file),
WAIT_EVENT_DATA_FILE_WRITE) < 0)
else if (FileWrite(file, (char *)data, strlen(data), FileSize(file),
WAIT_EVENT_DATA_FILE_WRITE) < 0)
snprintf(description, YB_QD_DESCRIPTION_LEN, "Error writing to file; %s",
strerror(errno));

Expand Down
6 changes: 3 additions & 3 deletions src/postgres/src/bin/pg_dump/pg_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -15713,7 +15713,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
"SELECT pg_catalog.binary_upgrade_set_next_tablegroup_oid('%u'::pg_catalog.oid);\n",
yb_properties->tablegroup_oid);

if(strcmp(yb_properties->tablegroup_name, "default") == 0)
if (strcmp(yb_properties->tablegroup_name, "default") == 0)
{
appendPQExpBufferStr(q,
"\n-- For YB colocation backup without tablespace information, must preserve default tablegroup tables\n");
Expand Down Expand Up @@ -16683,13 +16683,13 @@ dumpIndex(Archive *fout, const IndxInfo *indxinfo)
getYbTablePropertiesAndReloptions(fout, yb_properties, yb_reloptions,
indxinfo->dobj.catId.oid, indxinfo->dobj.name, tbinfo->relkind);

if(yb_properties && yb_properties->is_colocated){
if (yb_properties && yb_properties->is_colocated){
appendPQExpBufferStr(q,
"\n-- For YB colocation backup, must preserve implicit tablegroup pg_yb_tablegroup oid\n");
appendPQExpBuffer(q,
"SELECT pg_catalog.binary_upgrade_set_next_tablegroup_oid('%u'::pg_catalog.oid);\n",
yb_properties->tablegroup_oid);
if(strcmp(yb_properties->tablegroup_name, "default") == 0)
if (strcmp(yb_properties->tablegroup_name, "default") == 0)
{
appendPQExpBufferStr(q,
"\n-- For YB colocation backup without tablespace information, must preserve default tablegroup tables\n");
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/bin/pgbench/pgbench.c
Original file line number Diff line number Diff line change
Expand Up @@ -8747,7 +8747,7 @@ main(int argc, char **argv)
initStats(&stats, 0);

/* Start metrics webserver if any metrics args are set */
if(yb_metrics_arg_set)
if (yb_metrics_arg_set)
{
YbInitMetricsWebserver(argv[0]);
}
Expand Down
13 changes: 10 additions & 3 deletions src/postgres/ybsimplelint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ if ! [[ "$1" == src/postgres/src/backend/snowball/libstemmer/* ||
fi
grep -nE '/\*(\w+|\s\w+|\w+\s)\*/' "$1" \
| sed 's/^/error:bad_parameter_comment_spacing:/'
grep -nE '\s(if|else if|for|while)\(' "$1" \
| grep -vE 'while\((0|1)\)' \
| sed 's/^/error:bad_spacing_after_if_else_for_while:/'
if ! [[ "$1" == src/postgres/contrib/ltree/* ||
"$1" == src/postgres/src/backend/snowball/libstemmer/* ||
"$1" == src/postgres/src/backend/utils/adt/tsquery.c ||
"$1" == src/postgres/src/interfaces/ecpg/test/expected/* ||
"$1" == src/postgres/src/interfaces/ecpg/test/thread/* ||
"$1" == src/postgres/src/pl/plperl/ppport.h ]]; then
grep -nE '^\s*(if|else if|for|while)\(' "$1" \
| grep -vE 'while\((0|1)\)' \
| sed 's/^/error:bad_spacing_after_if_else_for_while:/'
fi

# Comments
grep -nE '//\s' "$1" \
Expand Down

0 comments on commit 5e804f1

Please sign in to comment.