Fixed the following SonarQube code smells:
1) Do not use the Array index in keys. 2) Import from the same module should be merged. 3) Mutable variables should not be exported. 4) Variables should not be initialized to undefined. 5) startswith or endswith method should be used. 6) Unwrap this unnecessarily grouped subpattern. Additionally, addressed many other SonarQube rules.pull/7575/head
parent
288fd7ed12
commit
dea5335ce5
|
@ -70,7 +70,7 @@ FROM alpine:latest AS env-builder
|
|||
|
||||
# Install dependencies
|
||||
COPY requirements.txt /
|
||||
RUN apk add --no-cache \
|
||||
RUN apk add --no-cache \
|
||||
make \
|
||||
python3 \
|
||||
py3-pip && \
|
||||
|
@ -187,7 +187,7 @@ COPY LICENSE /pgadmin4/LICENSE
|
|||
COPY DEPENDENCIES /pgadmin4/DEPENDENCIES
|
||||
|
||||
# Install runtime dependencies and configure everything in one RUN step
|
||||
RUN apk add \
|
||||
RUN apk add --no-cache \
|
||||
python3 \
|
||||
py3-pip \
|
||||
postfix \
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
{% trans copyright=copyright|e %}<li class="left" style="margin-left: 10px">© Copyright {{ copyright }}.</li>{% endtrans %}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
<li class="right" style="margin-right: 10px"><a href="genindex.html" title="General Index" accesskey="I">index</a></li>
|
||||
<li class="right" style="margin-right: 10px"><a href="genindex.html" title="General Index">index</a></li>
|
||||
{%- if next %}
|
||||
<li class="right" ><a href="{{ next.link|e }}" title="{{ next.title|striptags|e }}" accesskey="N">next</a> |</li>
|
||||
<li class="right" ><a href="{{ next.link|e }}" title="{{ next.title|striptags|e }}">next</a> |</li>
|
||||
{%- endif %}
|
||||
{%- if prev %}
|
||||
<li class="right" ><a href="{{ prev.link|e }}" title="{{ prev.title|striptags|e }}" accesskey="P">previous</a> |</li>
|
||||
<li class="right" ><a href="{{ prev.link|e }}" title="{{ prev.title|striptags|e }}">previous</a> |</li>
|
||||
{%- endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -212,7 +212,7 @@ function launchPgAdminWindow() {
|
|||
// https://github.com/nwjs/nw.js/issues/7973
|
||||
pgadminWindow.on('close', function () {
|
||||
// Resize Window
|
||||
resizeHeightBy = pgadminWindow.window.outerHeight - pgadminWindow.window.innerHeight;
|
||||
let resizeHeightBy = pgadminWindow.window.outerHeight - pgadminWindow.window.innerHeight;
|
||||
pgadminWindow.resizeBy(0, -resizeHeightBy);
|
||||
// Remove 'close' event handler, and then close window
|
||||
pgadminWindow.removeAllListeners('close');
|
||||
|
@ -554,7 +554,7 @@ function getSubMenu(menuItem) {
|
|||
if (sub.submenu?.items?.length) {
|
||||
sub.submenu.items.forEach((m) => {
|
||||
if (m.type == 'checkbox') {
|
||||
m.label == item.label ? m.checked = true : m.checked = false;
|
||||
m.checked = m.label == item.label;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
import * as Node from 'pgbrowser/node';
|
||||
import * as SchemaTreeNode from './schema_child_tree_node';
|
||||
|
||||
let SchemaChildNode = Node.extend({
|
||||
const SchemaChildNode = Node.extend({
|
||||
parent_type: ['schema', 'catalog'],
|
||||
canDrop: SchemaTreeNode.isTreeItemOfChildOfSchema,
|
||||
canDropCascade: SchemaTreeNode.isTreeItemOfChildOfSchema,
|
||||
|
|
|
@ -587,7 +587,7 @@ export default class ColumnSchema extends BaseUISchema {
|
|||
}
|
||||
|
||||
validate(state, setError) {
|
||||
let msg = undefined;
|
||||
let msg;
|
||||
|
||||
if (!_.isUndefined(state.cltype) && !isEmptyString(state.attlen)) {
|
||||
// Validation for Length field
|
||||
|
|
|
@ -527,7 +527,7 @@ def parse_rule_definition(res):
|
|||
condition_part = condition_part_match.group(1)
|
||||
|
||||
condition_match = re.search(
|
||||
r"(?:WHERE)\s+(\([\s\S]*\))\s+(?:DO)", condition_part)
|
||||
r"(?:WHERE)?\s+(\([\s\S]*\))\s+(?:DO)?", condition_part)
|
||||
|
||||
if condition_match is not None:
|
||||
condition = condition_match.group(1)
|
||||
|
@ -537,7 +537,7 @@ def parse_rule_definition(res):
|
|||
|
||||
# Parse data for statements
|
||||
statement_match = re.search(
|
||||
r"(?:DO\s+)(?:INSTEAD\s+)?([\s\S]*)(?:;)", data_def)
|
||||
r"(?:DO\s+)?(?:INSTEAD\s+)?([\s\S]*)(?:;)?", data_def)
|
||||
|
||||
statement = ''
|
||||
if statement_match is not None:
|
||||
|
|
|
@ -106,14 +106,14 @@ const DiskStatsTable = (props) => {
|
|||
<Table classNameRoot='Storage-tableWhiteSpace'>
|
||||
<thead>
|
||||
<tr>
|
||||
{tableHeader.map((item, index) => (
|
||||
<th key={index}>{item.header}</th>
|
||||
{tableHeader.map((item) => (
|
||||
<th key={item.header}>{item.header}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((item, index) => (
|
||||
<tr key={index}>
|
||||
{data.map((item) => (
|
||||
<tr key={item.file_system_type + item.mount_point}>
|
||||
{tableHeader.map((header, id) => (
|
||||
<td key={header.accessorKey+'-'+id}>{item[header.accessorKey]}</td>
|
||||
))}
|
||||
|
|
|
@ -54,8 +54,8 @@ const SummaryTable = (props) => {
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((item, index) => (
|
||||
<tr key={index}>
|
||||
{data.map((item) => (
|
||||
<tr key={item.name}>
|
||||
<td>{item.name}</td>
|
||||
<td>{item.value}</td>
|
||||
</tr>
|
||||
|
|
|
@ -248,8 +248,7 @@ export function getAWSSummary(cloud, cloudInstanceDetails, cloudDBDetails) {
|
|||
}
|
||||
|
||||
const getStorageType = (cloudInstanceDetails) => {
|
||||
let _storage_type = 'General Purpose SSD (gp2)',
|
||||
_io1 = undefined;
|
||||
let _storage_type = 'General Purpose SSD (gp2)', _io1;
|
||||
|
||||
if(cloudInstanceDetails.storage_type == 'gp2'){ _storage_type = 'General Purpose SSD (gp2)';}
|
||||
else if (cloudInstanceDetails.storage_type == 'gp3'){ _storage_type = 'General Purpose SSD (gp3)';}
|
||||
|
|
|
@ -273,7 +273,7 @@ export function checkClusternameAvailbility(clusterName){
|
|||
resolve(res.data);
|
||||
}
|
||||
}).catch((error) => {
|
||||
reject(gettext(`Error while checking server name availability with Microsoft Azure: ${error.response.data.errormsg}`));
|
||||
reject(new Error(gettext(`Error while checking server name availability with Microsoft Azure: ${error.response.data.errormsg}`)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -717,7 +717,7 @@ class AzureClusterSchema extends BaseUISchema {
|
|||
}
|
||||
|
||||
validate(data, setErr) {
|
||||
if ( !isEmptyString(data.name) && (!/^[a-z0-9\-]*$/.test(data.name) || data.name.length < 3)) {
|
||||
if ( !isEmptyString(data.name) && (!/^[a-z0-9-]*$/.test(data.name) || data.name.length < 3)) {
|
||||
setErr('name',gettext('Name must be more than 2 characters and must only contain lowercase letters, numbers, and hyphens'));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -8,14 +8,13 @@
|
|||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import { ToggleButton, ToggleButtonGroup } from '@mui/material';
|
||||
import { ToggleButton, ToggleButtonGroup, TableBody, TableCell, TableHead, TableRow } from '@mui/material';
|
||||
import CheckRoundedIcon from '@mui/icons-material/CheckRounded';
|
||||
import { DefaultButton, PrimaryButton } from '../../../../static/js/components/Buttons';
|
||||
import PropTypes from 'prop-types';
|
||||
import { getAWSSummary } from './aws';
|
||||
import {getAzureSummary} from './azure';
|
||||
import { getBigAnimalSummary } from './biganimal';
|
||||
import { TableBody, TableCell, TableHead, TableRow } from '@mui/material';
|
||||
import gettext from 'sources/gettext';
|
||||
import { getGoogleSummary } from './google';
|
||||
import { CLOUD_PROVIDERS_LABELS } from './cloud_constants';
|
||||
|
|
|
@ -158,9 +158,9 @@ function Multitext({currentXpos, currentYpos, label, maxWidth}) {
|
|||
return res;
|
||||
};
|
||||
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
for (let word in words) {
|
||||
let tmpArr = splitTextInMultiLine(
|
||||
currLine, widthSoFar, words[i]
|
||||
currLine, widthSoFar, word
|
||||
);
|
||||
|
||||
if (currLine) {
|
||||
|
|
|
@ -601,7 +601,7 @@ export default function DataGridView({
|
|||
<PgReactTableBody>
|
||||
{rows.map((row, i) => {
|
||||
return <PgReactTableRow key={row.index}>
|
||||
<DataTableRow index={i} key={i} row={row} totalRows={rows.length} isResizing={isResizing}
|
||||
<DataTableRow index={i} row={row} totalRows={rows.length} isResizing={isResizing}
|
||||
schema={schemaRef.current} schemaRef={schemaRef} accessPath={accessPath.concat([row.index])}
|
||||
moveRow={moveRow} isHovered={i == hoverIndex} setHoverIndex={setHoverIndex} viewHelperProps={viewHelperProps}
|
||||
/>
|
||||
|
|
|
@ -103,14 +103,11 @@ function isValueEqual(val1, val2) {
|
|||
/* If the orig value was null and new one is empty string, then its a "no change" */
|
||||
/* If the orig value and new value are of different datatype but of same value(numeric) "no change" */
|
||||
/* If the orig value is undefined or null and new value is boolean false "no change" */
|
||||
if (_.isEqual(val1, val2)
|
||||
return (_.isEqual(val1, val2)
|
||||
|| ((val1 === null || _.isUndefined(val1)) && val2 === '')
|
||||
|| ((val1 === null || _.isUndefined(val1)) && typeof(val2) === 'boolean' && !val2)
|
||||
|| (attrDefined ? (!_.isObject(val1) && _.isEqual(val1.toString(), val2.toString())) : false)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
);
|
||||
}
|
||||
|
||||
/* Compare two objects */
|
||||
|
@ -144,7 +141,7 @@ function getChangedData(topSchema, viewHelperProps, sessData, stringify=false, i
|
|||
if(_.isNull(change) && parseChanges.depth === 0) {
|
||||
change = '';
|
||||
}
|
||||
return levelChanges[id] = change;
|
||||
levelChanges[id] = change;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ export const PgReactTableCell = forwardRef(({row, cell, children, className}, re
|
|||
flex: `var(--col-${cell.column.id.replace(/\W/g, '_')}-size) 0 auto`,
|
||||
width: `calc(var(--col-${cell.column.id.replace(/\W/g, '_')}-size)*1px)`,
|
||||
...(cell.column.columnDef.maxSize ? { maxWidth: `${cell.column.columnDef.maxSize}px` } : {})
|
||||
}} role='cell'
|
||||
}}
|
||||
className={classNames.join(' ')}
|
||||
title={String(cell.getValue() ?? '')}>
|
||||
<div className='pgrd-row-cell-content'>{children}</div>
|
||||
|
@ -189,7 +189,7 @@ PgReactTableCell.propTypes = {
|
|||
|
||||
export const PgReactTableRow = forwardRef(({ children, className, ...props }, ref)=>{
|
||||
return (
|
||||
<div className={['pgrt-row', className].join(' ')} ref={ref} role="row" {...props}>
|
||||
<div className={['pgrt-row', className].join(' ')} ref={ref} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
|
@ -232,8 +232,8 @@ PgReactTableRowExpandContent.propTypes = {
|
|||
export function PgReactTableHeader({table}) {
|
||||
return (
|
||||
<div className='pgrt-header'>
|
||||
{table.getHeaderGroups().map((headerGroup, idx) => (
|
||||
<div key={idx} className='pgrt-header-row' style={{ }}>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<div key={headerGroup.id} className='pgrt-header-row' style={{ }}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<div
|
||||
key={header.id}
|
||||
|
|
|
@ -11,7 +11,7 @@ let getWindowOpener = (opener) => {
|
|||
return opener.opener?.pgAdmin ? getWindowOpener(opener.opener) : opener;
|
||||
};
|
||||
|
||||
let pgWindow = function() {
|
||||
const pgWindow = function() {
|
||||
let localPgWindow = null;
|
||||
try {
|
||||
if(window.opener?.pgAdmin) {
|
||||
|
|
|
@ -103,7 +103,7 @@ class BackupMessage(IProcessDesc):
|
|||
return ''
|
||||
|
||||
for arg in _args:
|
||||
if arg and len(arg) >= 2 and arg[:2] == '--':
|
||||
if arg and len(arg) >= 2 and arg.startswith('--'):
|
||||
self.cmd += ' ' + arg
|
||||
else:
|
||||
self.cmd += cmd_arg(arg)
|
||||
|
|
|
@ -269,7 +269,7 @@ export default class DebuggerModule {
|
|||
}
|
||||
|
||||
getUrl(_d, newTreeInfo, trans_id) {
|
||||
let baseUrl = undefined;
|
||||
let baseUrl;
|
||||
if (_d._type == 'function' || _d._type == 'edbfunc') {
|
||||
baseUrl = url_for(
|
||||
'debugger.initialize_target_for_function', {
|
||||
|
|
|
@ -24,7 +24,7 @@ class EmptySchema extends BaseUISchema {
|
|||
}
|
||||
|
||||
export function getTableDialogSchema(attributes, isNew, tableNodesDict, colTypes, schemas) {
|
||||
let treeNodeInfo = undefined;
|
||||
let treeNodeInfo;
|
||||
|
||||
let columnSchema = new ColumnSchema(
|
||||
()=>{/*This is intentional (SonarQube)*/},
|
||||
|
|
|
@ -80,7 +80,7 @@ class IEMessage(IProcessDesc):
|
|||
|
||||
replace_next = False
|
||||
for arg in _args:
|
||||
if arg and len(arg) >= 2 and arg[:2] == '--':
|
||||
if arg and len(arg) >= 2 and arg.startswith('--'):
|
||||
if arg == '--command':
|
||||
replace_next = True
|
||||
self._cmd += ' ' + arg
|
||||
|
|
|
@ -72,7 +72,7 @@ class RestoreMessage(IProcessDesc):
|
|||
return ''
|
||||
|
||||
for arg in _args:
|
||||
if arg and len(arg) >= 2 and arg[:2] == '--':
|
||||
if arg and len(arg) >= 2 and arg.startswith('--'):
|
||||
self.cmd += ' ' + arg
|
||||
else:
|
||||
self.cmd += cmd_arg(arg)
|
||||
|
|
|
@ -758,7 +758,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||
);
|
||||
});
|
||||
if(existIdx > -1) {
|
||||
reject(gettext('Connection with this configuration already present.'));
|
||||
reject(new Error(gettext('Connection with this configuration already present.')));
|
||||
return;
|
||||
}
|
||||
updateQueryToolConnection(connectionData, true)
|
||||
|
|
|
@ -189,7 +189,7 @@ export default function MacrosDialog({onClose, onSave}) {
|
|||
formType={'dialog'}
|
||||
getInitData={()=>{
|
||||
if(macrosErr) {
|
||||
return Promise.reject(macrosErr);
|
||||
return Promise.reject(new Error(macrosErr));
|
||||
}
|
||||
return Promise.resolve({macro: userMacrosData.filter((m)=>Boolean(m.name))});
|
||||
}}
|
||||
|
|
|
@ -14,7 +14,7 @@ import gettext from 'sources/gettext';
|
|||
import PropTypes from 'prop-types';
|
||||
import url_for from 'sources/url_for';
|
||||
import Loader from 'sources/components/Loader';
|
||||
import { Box } from '@mui/material';
|
||||
import { Box, useTheme } from '@mui/material';
|
||||
import ShowChartRoundedIcon from '@mui/icons-material/ShowChartRounded';
|
||||
import ZoomOutMapIcon from '@mui/icons-material/ZoomOutMap';
|
||||
import SaveAltIcon from '@mui/icons-material/SaveAlt';
|
||||
|
@ -26,7 +26,6 @@ import { LineChart, BarChart, PieChart, DATA_POINT_STYLE, DATA_POINT_SIZE,
|
|||
LightenDarkenColor} from 'sources/chartjs';
|
||||
import { QueryToolEventsContext, QueryToolContext } from '../QueryToolComponent';
|
||||
import { QUERY_TOOL_EVENTS, PANELS } from '../QueryToolConstants';
|
||||
import { useTheme } from '@mui/material';
|
||||
import { getChartColor } from '../../../../../../static/js/utils';
|
||||
|
||||
const StyledBox = styled(Box)(({theme}) => ({
|
||||
|
|
|
@ -166,10 +166,10 @@ class UserManagementCollection extends BaseUISchema {
|
|||
|
||||
if (state.auth_source != AUTH_METHODS['INTERNAL']) {
|
||||
if (obj.isNew(state) && obj.top?._sessData?.userManagement) {
|
||||
for (let i=0; i < obj.top._sessData.userManagement.length; i++) {
|
||||
if (obj.top._sessData.userManagement[i]?.id &&
|
||||
obj.top._sessData.userManagement[i].username.toLowerCase() == state.username.toLowerCase() &&
|
||||
obj.top._sessData.userManagement[i].auth_source == state.auth_source) {
|
||||
for (let user in obj.top._sessData.userManagement) {
|
||||
if (user?.id &&
|
||||
user.username.toLowerCase() == state.username.toLowerCase() &&
|
||||
user.auth_source == state.auth_source) {
|
||||
msg = gettext('User name \'%s\' already exists', state.username);
|
||||
setError('username', msg);
|
||||
return true;
|
||||
|
@ -179,7 +179,7 @@ class UserManagementCollection extends BaseUISchema {
|
|||
}
|
||||
|
||||
if (state.auth_source == AUTH_METHODS['INTERNAL']) {
|
||||
let email_filter = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
let email_filter = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
if (isEmptyString(state.email)) {
|
||||
msg = gettext('Email cannot be empty');
|
||||
setError('email', msg);
|
||||
|
@ -193,9 +193,9 @@ class UserManagementCollection extends BaseUISchema {
|
|||
}
|
||||
|
||||
if (obj.isNew(state) && obj.top?._sessData?.userManagement) {
|
||||
for (let i=0; i < obj.top._sessData.userManagement.length; i++) {
|
||||
if (obj.top._sessData.userManagement[i]?.id &&
|
||||
obj.top._sessData.userManagement[i].email?.toLowerCase() == state.email?.toLowerCase()) {
|
||||
for (let user in obj.top._sessData.userManagement) {
|
||||
if (user?.id &&
|
||||
user.email?.toLowerCase() == state.email?.toLowerCase()) {
|
||||
msg = gettext('Email address \'%s\' already exists', state.email);
|
||||
setError('email', msg);
|
||||
return true;
|
||||
|
|
|
@ -336,7 +336,7 @@ class Driver(BaseDriver):
|
|||
return True
|
||||
# certain types should not be quoted even though it contains a space.
|
||||
# Evilness.
|
||||
elif for_types and value[-2:] == "[]":
|
||||
elif for_types and value.endswith('[]'):
|
||||
val_noarray = value[:-2]
|
||||
|
||||
if for_types and val_noarray.lower() in [
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
let treeMenu = null;
|
||||
const treeMenu = null;
|
||||
|
||||
export {treeMenu};
|
||||
|
|
|
@ -95,6 +95,6 @@ export const addNewDatagridRow = async (user, ctrl)=>{
|
|||
await user.click(ctrl.container.querySelector('[data-test="add-row"] button'));
|
||||
};
|
||||
|
||||
export let genericBeforeEach = ()=> {
|
||||
export const genericBeforeEach = ()=> {
|
||||
pgWindow.pgAdmin = pgAdmin;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue