ESLint: Add prefer-const rule
Require const declarations for variables that are never reassigned after being declared. If a variable is never reassigned, using the const declaration is better. const declaration tells readers, “this variable is never reassigned,” reducing cognitive load and improving maintainability.
This commit is contained in:
parent
3207afce90
commit
4000b8d5e5
14 changed files with 55 additions and 47 deletions
|
|
@ -41,7 +41,7 @@ const handleKeyDown = (e, handleClose) => {
|
|||
};
|
||||
|
||||
const onSave = (values) => {
|
||||
let customizations = {
|
||||
const customizations = {
|
||||
packages: values['selected-packages']?.map((p) => p.name),
|
||||
};
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ const onSave = (values) => {
|
|||
|
||||
if (values['file-system-config-radio'] === 'manual') {
|
||||
customizations.filesystem = [];
|
||||
for (let fsc of values['file-system-configuration']) {
|
||||
for (const fsc of values['file-system-configuration']) {
|
||||
customizations.filesystem.push({
|
||||
mountpoint: fsc.mountpoint,
|
||||
min_size: fsc.size * fsc.unit,
|
||||
|
|
@ -77,9 +77,9 @@ const onSave = (values) => {
|
|||
}
|
||||
}
|
||||
|
||||
let requests = [];
|
||||
const requests = [];
|
||||
if (values['target-environment']?.aws) {
|
||||
let request = {
|
||||
const request = {
|
||||
distribution: values.release,
|
||||
image_name: values?.['image-name'],
|
||||
image_requests: [
|
||||
|
|
@ -116,7 +116,7 @@ const onSave = (values) => {
|
|||
break;
|
||||
}
|
||||
|
||||
let request = {
|
||||
const request = {
|
||||
distribution: values.release,
|
||||
image_name: values?.['image-name'],
|
||||
image_requests: [
|
||||
|
|
@ -138,7 +138,7 @@ const onSave = (values) => {
|
|||
}
|
||||
|
||||
if (values['target-environment']?.azure) {
|
||||
let request = {
|
||||
const request = {
|
||||
distribution: values.release,
|
||||
image_name: values?.['image-name'],
|
||||
image_requests: [
|
||||
|
|
@ -161,7 +161,7 @@ const onSave = (values) => {
|
|||
}
|
||||
|
||||
if (values['target-environment']?.vsphere) {
|
||||
let request = {
|
||||
const request = {
|
||||
distribution: values.release,
|
||||
image_name: values?.['image-name'],
|
||||
image_requests: [
|
||||
|
|
@ -180,7 +180,7 @@ const onSave = (values) => {
|
|||
}
|
||||
|
||||
if (values['target-environment']?.['guest-image']) {
|
||||
let request = {
|
||||
const request = {
|
||||
distribution: values.release,
|
||||
image_name: values?.['image-name'],
|
||||
image_requests: [
|
||||
|
|
@ -199,7 +199,7 @@ const onSave = (values) => {
|
|||
}
|
||||
|
||||
if (values['target-environment']?.['image-installer']) {
|
||||
let request = {
|
||||
const request = {
|
||||
distribution: values.release,
|
||||
image_name: values?.['image-name'],
|
||||
image_requests: [
|
||||
|
|
@ -247,8 +247,9 @@ const getPackageDescription = async (release, arch, repoUrls, packageName) => {
|
|||
pack = data.find((pack) => packageName === pack.name);
|
||||
} else {
|
||||
const args = [release, arch, packageName];
|
||||
let { data, meta } = await api.getPackages(...args);
|
||||
|
||||
const response = await api.getPackages(...args);
|
||||
let { data } = response;
|
||||
const { meta } = response;
|
||||
// the package should be found in the 0 index
|
||||
// if not then fetch all package matches and search for the package
|
||||
if (data[0]?.name === packageName) {
|
||||
|
|
@ -271,7 +272,7 @@ const requestToState = (composeRequest) => {
|
|||
if (composeRequest) {
|
||||
const imageRequest = composeRequest.image_requests[0];
|
||||
const uploadRequest = imageRequest.upload_request;
|
||||
let formState = {};
|
||||
const formState = {};
|
||||
|
||||
formState['image-name'] = composeRequest.image_name;
|
||||
|
||||
|
|
@ -332,7 +333,7 @@ const requestToState = (composeRequest) => {
|
|||
|
||||
// customizations
|
||||
// packages
|
||||
let packs = [];
|
||||
const packs = [];
|
||||
|
||||
const distro = composeRequest?.distribution;
|
||||
const distroRepoUrls = getDistroRepoUrls(distro);
|
||||
|
|
@ -378,8 +379,8 @@ const requestToState = (composeRequest) => {
|
|||
const fs = composeRequest?.customizations?.filesystem;
|
||||
if (fs) {
|
||||
formState['file-system-config-radio'] = 'manual';
|
||||
let fileSystemConfiguration = [];
|
||||
for (let fsc of fs) {
|
||||
const fileSystemConfiguration = [];
|
||||
for (const fsc of fs) {
|
||||
const [size, unit] = parseSizeUnit(fsc.min_size);
|
||||
fileSystemConfiguration.push({
|
||||
mountpoint: fsc.mountpoint,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import SizeUnit from './SizeUnit';
|
|||
|
||||
import { UNIT_GIB } from '../../../constants';
|
||||
|
||||
let initialRow = {
|
||||
const initialRow = {
|
||||
id: uuidv4(),
|
||||
mountpoint: '/',
|
||||
fstype: 'xfs',
|
||||
|
|
@ -112,12 +112,12 @@ const FileSystemConfiguration = ({ ...props }) => {
|
|||
};
|
||||
|
||||
const removeRow = (id) => {
|
||||
let removeIndex = rows.map((e) => e.id).indexOf(id);
|
||||
let newRows = [...rows];
|
||||
const removeIndex = rows.map((e) => e.id).indexOf(id);
|
||||
const newRows = [...rows];
|
||||
newRows.splice(removeIndex, 1);
|
||||
|
||||
let removeOrderIndex = itemOrder.indexOf(id);
|
||||
let newOrder = [...itemOrder];
|
||||
const removeOrderIndex = itemOrder.indexOf(id);
|
||||
const newOrder = [...itemOrder];
|
||||
newOrder.splice(removeOrderIndex, 1);
|
||||
|
||||
setRows(newRows);
|
||||
|
|
@ -216,10 +216,10 @@ const FileSystemConfiguration = ({ ...props }) => {
|
|||
};
|
||||
|
||||
const setMountpoint = (id, mp) => {
|
||||
let newRows = [...rows];
|
||||
const newRows = [...rows];
|
||||
for (let i = 0; i < newRows.length; i++) {
|
||||
if (newRows[i].id === id) {
|
||||
let newRow = { ...newRows[i] };
|
||||
const newRow = { ...newRows[i] };
|
||||
newRow.mountpoint = mp;
|
||||
newRows.splice(i, 1, newRow);
|
||||
break;
|
||||
|
|
@ -230,10 +230,10 @@ const FileSystemConfiguration = ({ ...props }) => {
|
|||
};
|
||||
|
||||
const setSize = (id, s, u) => {
|
||||
let newRows = [...rows];
|
||||
const newRows = [...rows];
|
||||
for (let i = 0; i < newRows.length; i++) {
|
||||
if (newRows[i].id === id) {
|
||||
let newRow = { ...newRows[i] };
|
||||
const newRow = { ...newRows[i] };
|
||||
newRow.size = s;
|
||||
newRow.unit = u;
|
||||
newRows.splice(i, 1, newRow);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ const MountPoint = ({ ...props }) => {
|
|||
|
||||
// split
|
||||
useEffect(() => {
|
||||
for (let p of validPrefixes) {
|
||||
for (const p of validPrefixes) {
|
||||
if (props.mountpoint.startsWith(p)) {
|
||||
setPrefix(p);
|
||||
setSuffix(props.mountpoint.substring(p.length));
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ export const RedHatPackages = ({ defaultArch }) => {
|
|||
getState()?.values?.architecture || defaultArch,
|
||||
packagesSearchName,
|
||||
];
|
||||
let { data, meta } = await api.getPackages(...args);
|
||||
const response = await api.getPackages(...args);
|
||||
let { data } = response;
|
||||
const { meta } = response;
|
||||
if (data?.length === meta.count) {
|
||||
return data;
|
||||
} else if (data) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const FileSystemConfigurationValidator = () => (fsc) => {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
let mpFreqs = {};
|
||||
const mpFreqs = {};
|
||||
for (const fs of fsc) {
|
||||
const mp = fs.mountpoint;
|
||||
if (mp in mpFreqs) {
|
||||
|
|
@ -13,14 +13,14 @@ const FileSystemConfigurationValidator = () => (fsc) => {
|
|||
}
|
||||
}
|
||||
|
||||
let duplicates = [];
|
||||
const duplicates = [];
|
||||
for (const [k, v] of Object.entries(mpFreqs)) {
|
||||
if (v > 1) {
|
||||
duplicates.push(k);
|
||||
}
|
||||
}
|
||||
|
||||
let root = mpFreqs['/'] >= 1;
|
||||
const root = mpFreqs['/'] >= 1;
|
||||
return duplicates.length === 0 && root
|
||||
? undefined
|
||||
: {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ const TargetEnvironmentValidator = () => (targets) => {
|
|||
// be set to true. This reduces the value to
|
||||
// a single boolean which is a flag for whether
|
||||
// at least one target has been selected or not
|
||||
let valid = Object.values(targets).reduce(
|
||||
const valid = Object.values(targets).reduce(
|
||||
(prev, curr) => curr || prev,
|
||||
false
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue