Skip to content

Commit 9811ffa

Browse files
committed
CCM-11438 Lint fix
1 parent e8a40dc commit 9811ffa

File tree

11 files changed

+57
-45
lines changed

11 files changed

+57
-45
lines changed

frontend/src/__tests__/components/molecules/Personalisation.test.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,24 @@ describe('Personalisation component', () => {
1010
const pdsDetails = screen.getByTestId('pds-personalisation-fields-details');
1111
expect(pdsDetails).not.toHaveAttribute('open');
1212

13-
expect(screen.getByTestId('pds-personalisation-fields-summary')).toBeInTheDocument();
14-
expect(screen.getByTestId('pds-personalisation-fields-text')).toBeInTheDocument();
13+
expect(
14+
screen.getByTestId('pds-personalisation-fields-summary')
15+
).toBeInTheDocument();
16+
expect(
17+
screen.getByTestId('pds-personalisation-fields-text')
18+
).toBeInTheDocument();
1519

16-
const customDetails = screen.getByTestId('custom-personalisation-fields-details');
20+
const customDetails = screen.getByTestId(
21+
'custom-personalisation-fields-details'
22+
);
1723
expect(customDetails).not.toHaveAttribute('open');
1824

19-
expect(screen.getByTestId('custom-personalisation-fields-summary')).toBeInTheDocument();
20-
expect(screen.getByTestId('custom-personalisation-fields-text')).toBeInTheDocument();
25+
expect(
26+
screen.getByTestId('custom-personalisation-fields-summary')
27+
).toBeInTheDocument();
28+
expect(
29+
screen.getByTestId('custom-personalisation-fields-text')
30+
).toBeInTheDocument();
2131
});
2232

2333
it('matches snapshot', () => {

frontend/src/components/atoms/CodeExample/CodeExample.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ const CodeExample: React.FC<CodeExampleProps> = ({
1818
{ariaText}
1919
</span>
2020
<pre className='nhsuk-code-block'>
21-
<code
22-
aria-describedby={ariaId}
23-
className={codeClassName}
24-
>
21+
<code aria-describedby={ariaId} className={codeClassName}>
2522
{children}
2623
</code>
2724
</pre>

frontend/src/components/forms/SmsTemplateForm/SmsTemplateForm.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { calculateHowManySmsMessages } from './view-actions';
3131
import { validate } from '@utils/client-validate-form';
3232
import Link from 'next/link';
3333
import classNames from 'classnames';
34-
import { MarkdownContent } from '@molecules/MarkdownContent/MarkdownContent';
3534
import { ContentRenderer } from '@molecules/ContentRenderer/ContentRenderer';
3635

3736
export const SmsTemplateForm: FC<
@@ -64,8 +63,6 @@ export const SmsTemplateForm: FC<
6463
buttonText,
6564
errorHeading,
6665
pageHeadingSuffix,
67-
smsPricingLink,
68-
smsPricingText,
6966
templateMessageLabelText,
7067
templateMessageFooterText,
7168
templateNameHintText,

frontend/src/components/molecules/ContentRenderer/ContentRenderer.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CodeExample from '@atoms/CodeExample/CodeExample';
22
import { MarkdownContent } from '@molecules/MarkdownContent/MarkdownContent';
33

4-
type StandardBlock = { id?: string; testId?: string; };
4+
type StandardBlock = { id?: string; testId?: string };
55
export type MarkdownTextBlock = StandardBlock & { type: 'text'; text: string };
66
export type CodeBlock = StandardBlock & {
77
type: 'code';
@@ -24,7 +24,7 @@ export function ContentRenderer({ content, variables }: ContentRendererProps) {
2424
const key = block.id ?? index;
2525

2626
switch (block.type) {
27-
case 'text':
27+
case 'text': {
2828
return (
2929
<MarkdownContent
3030
id={block.id}
@@ -34,7 +34,8 @@ export function ContentRenderer({ content, variables }: ContentRendererProps) {
3434
variables={variables}
3535
/>
3636
);
37-
case 'code':
37+
}
38+
case 'code': {
3839
return (
3940
<CodeExample
4041
id={block.id}
@@ -46,16 +47,19 @@ export function ContentRenderer({ content, variables }: ContentRendererProps) {
4647
{block.code}
4748
</CodeExample>
4849
);
49-
case 'list':
50+
}
51+
case 'list': {
5052
return (
5153
<ul id={block.id} data-testid={block.testId} key={key}>
5254
{block.items.map((item, itemId) => (
5355
<li key={itemId}>{item}</li>
5456
))}
5557
</ul>
5658
);
57-
default:
59+
}
60+
default: {
5861
return null;
62+
}
5963
}
6064
})}
6165
</>

frontend/src/components/molecules/MarkdownContent/MarkdownContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export function MarkdownContent({
2323
<Markdown
2424
key={index}
2525
{...(id ? { id: items.length > 1 ? `${id}-${index}` : id } : {})}
26-
{...(testId ? {'data-testid': items.length > 1 ? `${testId}-${index}` : testId, } : {})}
26+
{...(testId
27+
? {
28+
'data-testid': items.length > 1 ? `${testId}-${index}` : testId,
29+
}
30+
: {})}
2731
options={{
2832
forceBlock: true,
2933
wrapper: React.Fragment,

frontend/src/components/molecules/MessageFormatting/MessageFormatting.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export function MessageFormatting({
2929
const id = toKebabCase(section.title);
3030
return (
3131
<Details data-testid={`${id}-details`} key={id}>
32-
<Details.Summary data-testid={`${id}-summary`}>{section.title}</Details.Summary>
32+
<Details.Summary data-testid={`${id}-summary`}>
33+
{section.title}
34+
</Details.Summary>
3335
<Details.Text data-testid={`${id}-text`}>
3436
<ContentRenderer content={section.content} />
3537
</Details.Text>

frontend/src/components/molecules/Personalisation/Personalisation.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ export function Personalisation() {
1212
{personalisationContent.header}
1313
</h2>
1414

15-
<ContentRenderer content={personalisationContent.leadParagraph}/>
15+
<ContentRenderer content={personalisationContent.leadParagraph} />
1616

1717
{personalisationContent.details.map((section) => {
1818
const id = toKebabCase(section.title);
1919
return (
20-
<Details key={id} data-testid={`${id}-details`}>
21-
<Details.Summary data-testid={`${id}-summary`}>
22-
{section.title}
23-
</Details.Summary>
24-
<Details.Text data-testid={`${id}-text`}>
25-
<ContentRenderer
26-
content={section.content}
27-
/>
28-
</Details.Text>
29-
</Details>
30-
)})}
20+
<Details key={id} data-testid={`${id}-details`}>
21+
<Details.Summary data-testid={`${id}-summary`}>
22+
{section.title}
23+
</Details.Summary>
24+
<Details.Text data-testid={`${id}-text`}>
25+
<ContentRenderer content={section.content} />
26+
</Details.Text>
27+
</Details>
28+
);
29+
})}
3130
</>
3231
);
3332
}

frontend/src/components/molecules/PreviewTemplateDetails/common.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import styles from './PreviewTemplateDetails.module.scss';
88
import { JSX } from 'react';
99
import content from '@content/content';
10-
import { TemplateDto, TemplateStatus } from 'nhs-notify-backend-client';
10+
import { TemplateDto } from 'nhs-notify-backend-client';
1111
import classNames from 'classnames';
1212
import { toKebabCase } from '@utils/kebab-case';
1313

frontend/src/content/content.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
CodeBlock,
3-
ContentBlock,
4-
MarkdownTextBlock,
5-
} from '@molecules/ContentRenderer/ContentRenderer';
1+
import { ContentBlock } from '@molecules/ContentRenderer/ContentRenderer';
62
import { getBasePath } from '@utils/get-base-path';
73
import { TemplateStatus, TemplateType } from 'nhs-notify-backend-client';
84

@@ -878,14 +874,14 @@ const smsTemplateFooter: ContentBlock[] = [
878874
{
879875
type: 'text',
880876
testId: 'character-message-count',
881-
text: `{{characters}} {{characters|character|characters}} \nThis template will be sent as {{count}} {{count|text message|text messages}}. \nIf you're using personalisation fields, it could send as more.`
877+
text: `{{characters}} {{characters|character|characters}} \nThis template will be sent as {{count}} {{count|text message|text messages}}. \nIf you're using personalisation fields, it could send as more.`,
882878
},
883879
{
884880
type: 'text',
885881
testId: 'sms-pricing-info',
886882
text: '[Learn more about character counts and text messaging pricing (opens in a new tab)](/pricing/text-messages)',
887-
}
888-
]
883+
},
884+
];
889885

890886
const templateFormSms = {
891887
pageTitle: generatePageTitle('Create text message template'),

frontend/src/utils/interpolate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ export function interpolate(
2727
template: string,
2828
variables: Record<string, string | number> = {}
2929
): string {
30-
return template.replace(/{{(.*?)}}/g, (_, token) => {
30+
return template.replaceAll(/{{\s*([\w|]+?)\s*}}/g, (_, token) => {
3131
const parts = token.trim().split('|');
3232

3333
if (parts.length === 3) {
3434
const [variable, singular, plural] = parts;
3535
const value = Number(variables[variable]);
36-
if (isNaN(value)) return plural;
36+
if (Number.isNaN(value)) return plural;
3737
return value === 1 ? singular : plural;
3838
}
3939

4040
const value = variables[parts[0]];
41-
return value != null ? String(value) : '';
41+
return value == null ? '' : String(value);
4242
});
4343
}

0 commit comments

Comments
 (0)