Migrate components to eslint
This commit is contained in:
parent
de66486e41
commit
b13dbcfa77
69 changed files with 875 additions and 800 deletions
|
@ -24,25 +24,23 @@ export class Intl extends React.Component<Props> {
|
|||
index: number,
|
||||
placeholderName: string,
|
||||
key: number
|
||||
): FullJSXType | undefined {
|
||||
): FullJSXType | null {
|
||||
const { id, components } = this.props;
|
||||
|
||||
if (!components) {
|
||||
// tslint:disable-next-line no-console
|
||||
console.log(
|
||||
window.log.error(
|
||||
`Error: Intl component prop not provided; Metadata: id '${id}', index ${index}, placeholder '${placeholderName}'`
|
||||
);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Array.isArray(components)) {
|
||||
if (!components || !components.length || components.length <= index) {
|
||||
// tslint:disable-next-line no-console
|
||||
console.log(
|
||||
window.log.error(
|
||||
`Error: Intl missing provided component for id '${id}', index ${index}`
|
||||
);
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return <React.Fragment key={key}>{components[index]}</React.Fragment>;
|
||||
|
@ -50,28 +48,30 @@ export class Intl extends React.Component<Props> {
|
|||
|
||||
const value = components[placeholderName];
|
||||
if (!value) {
|
||||
// tslint:disable-next-line no-console
|
||||
console.log(
|
||||
window.log.error(
|
||||
`Error: Intl missing provided component for id '${id}', placeholder '${placeholderName}'`
|
||||
);
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return <React.Fragment key={key}>{value}</React.Fragment>;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
public render() {
|
||||
const { components, id, i18n, renderText } = this.props;
|
||||
|
||||
const text = i18n(id);
|
||||
const results: Array<any> = [];
|
||||
const results: Array<
|
||||
string | JSX.Element | Array<string | JSX.Element> | null
|
||||
> = [];
|
||||
const FIND_REPLACEMENTS = /\$([^$]+)\$/g;
|
||||
|
||||
// We have to do this, because renderText is not required in our Props object,
|
||||
// but it is always provided via defaultProps.
|
||||
if (!renderText) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Array.isArray(components) && components.length > 1) {
|
||||
|
@ -92,7 +92,7 @@ export class Intl extends React.Component<Props> {
|
|||
while (match) {
|
||||
if (lastTextIndex < match.index) {
|
||||
const textWithNoReplacements = text.slice(lastTextIndex, match.index);
|
||||
results.push(renderText({ text: textWithNoReplacements, key: key }));
|
||||
results.push(renderText({ text: textWithNoReplacements, key }));
|
||||
key += 1;
|
||||
}
|
||||
|
||||
|
@ -101,13 +101,12 @@ export class Intl extends React.Component<Props> {
|
|||
componentIndex += 1;
|
||||
key += 1;
|
||||
|
||||
// @ts-ignore
|
||||
lastTextIndex = FIND_REPLACEMENTS.lastIndex;
|
||||
match = FIND_REPLACEMENTS.exec(text);
|
||||
}
|
||||
|
||||
if (lastTextIndex < text.length) {
|
||||
results.push(renderText({ text: text.slice(lastTextIndex), key: key }));
|
||||
results.push(renderText({ text: text.slice(lastTextIndex), key }));
|
||||
key += 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue