Skip to content

Commit 18cf588

Browse files
fix(lint): convert var→const, destructure useState, suppress structural LWC violations in wizard example
1 parent 32f60da commit 18cf588

1 file changed

Lines changed: 31 additions & 41 deletions

File tree

examples/03-multi-step-wizard/force-app/main/default/lwc/uswdsRequestWizard/uswdsRequestWizard.js

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,42 @@ import { createRecord } from 'lightning/uiRecordApi';
1414
import BUNDLE from '@salesforce/resourceUrl/sfGpsDsUsGovReactBundle';
1515

1616
// The three step names shown in StepIndicator.
17-
var STEPS = ['Topic', 'Details', 'Review'];
17+
const STEPS = ['Topic', 'Details', 'Review'];
1818

1919
// Topic options shown as cards in Step 1.
20-
var TOPICS = [
20+
const TOPICS = [
2121
{ value: 'foia', label: 'Freedom of Information', description: 'Request government records.' },
2222
{ value: 'benefits', label: 'Benefits', description: 'Questions about benefit eligibility.' },
2323
{ value: 'complaint', label: 'File a Complaint', description: 'Report an issue or concern.' }
2424
];
2525

2626
function makeFixture({ React, usGovReact, onSubmit }) {
27-
var StepIndicator = usGovReact.StepIndicator;
28-
var Card = usGovReact.Card;
29-
var CardGroup = usGovReact.CardGroup;
30-
var Input = usGovReact.Input;
31-
var Textarea = usGovReact.Textarea;
32-
var Button = usGovReact.Button;
33-
var SummaryBox = usGovReact.SummaryBox;
34-
var Modal = usGovReact.Modal;
35-
var Alert = usGovReact.Alert;
27+
const StepIndicator = usGovReact.StepIndicator;
28+
const Card = usGovReact.Card;
29+
const CardGroup = usGovReact.CardGroup;
30+
const Input = usGovReact.Input;
31+
const Textarea = usGovReact.Textarea;
32+
const Button = usGovReact.Button;
33+
const SummaryBox = usGovReact.SummaryBox;
34+
const Modal = usGovReact.Modal;
35+
const Alert = usGovReact.Alert;
3636

3737
return function RequestWizard(props) {
3838
// All wizard state lives here in React.
3939
// The LWC only needs to know about submission — it handles nothing else.
40-
var stepState = React.useState(1);
41-
var step = stepState[0];
42-
var setStep = stepState[1];
43-
44-
var topicState = React.useState('');
45-
var topic = topicState[0];
46-
var setTopic = topicState[1];
47-
48-
var subjectState = React.useState('');
49-
var subject = subjectState[0];
50-
var setSubject = subjectState[1];
51-
52-
var detailState = React.useState('');
53-
var detail = detailState[0];
54-
var setDetail = detailState[1];
55-
56-
var modalState = React.useState(false);
57-
var modalOpen = modalState[0];
58-
var setModalOpen = modalState[1];
40+
const [step, setStep] = React.useState(1);
41+
const [topic, setTopic] = React.useState('');
42+
const [subject, setSubject] = React.useState('');
43+
const [detail, setDetail] = React.useState('');
44+
const [modalOpen, setModalOpen] = React.useState(false);
5945

6046
// submitting, submitted, and errorMessage come from the LWC via props.
61-
var submitting = props.submitting || false;
62-
var submitted = props.submitted || false;
63-
var errorMessage = props.errorMessage || null;
47+
// code-analyzer-suppress-next-line eslint:react/prop-types
48+
const submitting = props.submitting || false;
49+
// code-analyzer-suppress-next-line eslint:react/prop-types
50+
const submitted = props.submitted || false;
51+
// code-analyzer-suppress-next-line eslint:react/prop-types
52+
const errorMessage = props.errorMessage || null;
6453

6554
// Success screen — shown after the LWC sets submitted=true.
6655
if (submitted) {
@@ -82,7 +71,7 @@ function makeFixture({ React, usGovReact, onSubmit }) {
8271
CardGroup,
8372
null,
8473
TOPICS.map(function(card, i) {
85-
var t = TOPICS[i];
74+
const t = TOPICS[i];
8675
return React.createElement(
8776
'div',
8877
{
@@ -157,7 +146,7 @@ function makeFixture({ React, usGovReact, onSubmit }) {
157146

158147
// ── Step 3: Review & Submit ─────────────────────────────────────────
159148
function renderStep3() {
160-
var topicLabel = (TOPICS.find(function(t) { return t.value === topic; }) || {}).label || topic;
149+
const topicLabel = (TOPICS.find(function(t) { return t.value === topic; }) || {}).label || topic;
161150

162151
return React.createElement(
163152
'div',
@@ -250,12 +239,13 @@ export default class UswdsRequestWizard extends LightningElement {
250239
_mount = null;
251240

252241
async connectedCallback() {
253-
var bundle = await import(BUNDLE);
254-
var React = bundle.React;
255-
var ReactDOM = bundle.ReactDOM;
256-
var usGovReact = bundle.usGovReact;
242+
// code-analyzer-suppress-next-line eslint:@lwc/lwc-platform/no-dynamic-import-identifier
243+
const bundle = await import(BUNDLE);
244+
const React = bundle.React;
245+
const ReactDOM = bundle.ReactDOM;
246+
const usGovReact = bundle.usGovReact;
257247

258-
var self = this;
248+
const self = this;
259249
function onSubmit(data) {
260250
self._handleSubmit(data);
261251
}
@@ -281,7 +271,7 @@ export default class UswdsRequestWizard extends LightningElement {
281271
});
282272
this._mount.reactProps = { submitting: false, submitted: true, errorMessage: null };
283273
} catch (err) {
284-
var msg = (err.body && err.body.message) ? err.body.message : 'Submission failed. Please try again.';
274+
const msg = (err.body && err.body.message) ? err.body.message : 'Submission failed. Please try again.';
285275
// Pass the error back as a prop — the React component renders it as an Alert.
286276
// All form data is preserved so the user can fix and resubmit without re-entering.
287277
this._mount.reactProps = { submitting: false, submitted: false, errorMessage: msg };

0 commit comments

Comments
 (0)