From 72f172a9b654e8ed4d4570df3963443ef743ddfb Mon Sep 17 00:00:00 2001 From: April Bowler Date: Tue, 16 Mar 2021 10:44:14 -0700 Subject: [PATCH] Fix Bug 1696517 - Upgrade flow to 0.146.0 (#1888) Co-authored-by: Axel Hecht --- .eslintrc.js | 2 + frontend/.flowconfig | 6 +- frontend/flow-typed/myLibDef.js | 36 +++++++++++ frontend/package.json | 2 +- frontend/src/App.js | 2 +- frontend/src/core/api/base.js | 6 +- frontend/src/core/api/comment.js | 13 ++-- frontend/src/core/api/entity.js | 12 ++-- frontend/src/core/api/filter.js | 2 +- frontend/src/core/api/index.js | 20 +++--- frontend/src/core/api/l10n.js | 2 +- frontend/src/core/api/locale.js | 2 +- frontend/src/core/api/machinery.js | 2 +- frontend/src/core/api/project.js | 2 +- frontend/src/core/api/resource.js | 2 +- frontend/src/core/api/translation.js | 18 +++--- .../core/comments/components/AddComment.js | 12 ++-- .../src/core/comments/components/Comment.js | 2 +- .../core/comments/components/CommentsList.js | 2 +- .../core/diff/components/TranslationDiff.js | 2 +- frontend/src/core/diff/withDiff.js | 2 +- .../editor/components/EditorMainAction.js | 6 +- .../src/core/editor/components/EditorMenu.js | 2 +- .../core/editor/components/EditorSettings.js | 8 +-- .../core/editor/components/FailedChecks.js | 6 +- .../editor/components/KeyboardShortcuts.js | 6 +- .../editor/components/TranslationLength.js | 6 +- .../editor/hooks/useAddTextToTranslation.js | 5 +- .../src/core/editor/hooks/useClearEditor.js | 2 +- .../hooks/useCopyMachineryTranslation.js | 4 +- .../editor/hooks/useCopyOriginalIntoEditor.js | 2 +- .../hooks/useCopyOtherLocaleTranslation.js | 4 +- .../core/editor/hooks/useHandleShortcuts.js | 9 ++- .../core/editor/hooks/useSendTranslation.js | 5 +- .../core/editor/hooks/useUpdateTranslation.js | 5 +- .../hooks/useUpdateTranslationStatus.js | 6 +- frontend/src/core/editor/selectors.js | 4 +- frontend/src/core/l10n/actions.js | 2 +- .../components/AppLocalizationProvider.js | 4 +- .../src/core/lightbox/components/Lightbox.js | 6 +- frontend/src/core/locale/actions.js | 4 +- frontend/src/core/locale/getPluralExamples.js | 4 +- frontend/src/core/notification/actions.js | 3 +- .../components/NotificationPanel.js | 4 +- .../placeable/components/WithPlaceables.js | 2 +- .../components/WithPlaceablesForFluent.js | 5 +- .../WithPlaceablesForFluentNoLeadingSpace.js | 2 +- .../WithPlaceablesNoLeadingSpace.js | 7 ++- .../core/placeable/parsers/altAttribute.js | 4 +- .../core/placeable/parsers/camelCaseString.js | 4 +- .../core/placeable/parsers/emailPattern.js | 4 +- .../core/placeable/parsers/escapeSequence.js | 2 +- .../src/core/placeable/parsers/filePattern.js | 4 +- .../core/placeable/parsers/fluentFunction.js | 4 +- .../parsers/fluentParametrizedTerm.js | 4 +- .../core/placeable/parsers/fluentString.js | 4 +- .../src/core/placeable/parsers/fluentTerm.js | 4 +- .../parsers/javaFormattingVariable.js | 4 +- .../core/placeable/parsers/jsonPlaceholder.js | 4 +- .../core/placeable/parsers/leadingSpace.js | 4 +- .../core/placeable/parsers/multipleSpaces.js | 4 +- .../parsers/narrowNonBreakingSpace.js | 4 +- .../placeable/parsers/newlineCharacter.js | 2 +- .../core/placeable/parsers/newlineEscape.js | 2 +- .../placeable/parsers/nonBreakingSpace.js | 2 +- .../core/placeable/parsers/nsisVariable.js | 4 +- .../core/placeable/parsers/numberString.js | 4 +- .../core/placeable/parsers/optionPattern.js | 4 +- .../src/core/placeable/parsers/punctuation.js | 6 +- .../parsers/pythonFormatNamedString.js | 4 +- .../placeable/parsers/pythonFormatString.js | 4 +- .../parsers/pythonFormattingVariable.js | 4 +- .../core/placeable/parsers/qtFormatting.js | 4 +- .../parsers/shortCapitalNumberString.js | 4 +- .../parsers/stringFormattingVariable.js | 4 +- .../core/placeable/parsers/tabCharacter.js | 2 +- .../src/core/placeable/parsers/thinSpace.js | 4 +- .../core/placeable/parsers/unusualSpace.js | 4 +- .../src/core/placeable/parsers/uriPattern.js | 6 +- .../src/core/placeable/parsers/xmlEntity.js | 4 +- frontend/src/core/placeable/parsers/xmlTag.js | 4 +- frontend/src/core/plural/actions.js | 4 +- .../core/plural/components/PluralSelector.js | 6 +- .../core/project/components/ProjectItem.js | 2 +- .../core/project/components/ProjectMenu.js | 12 ++-- .../core/project/components/ProjectPercent.js | 2 +- .../core/resource/components/ResourceItem.js | 2 +- .../core/resource/components/ResourceMenu.js | 12 ++-- .../resource/components/ResourcePercent.js | 2 +- frontend/src/core/term/components/Term.js | 2 +- .../src/core/term/components/TermsList.js | 2 +- frontend/src/core/term/getMarker.js | 2 +- .../components/FluentTranslation.js | 6 +- .../components/GenericTranslation.js | 6 +- .../components/TranslationProxy.js | 2 +- frontend/src/core/user/actions.js | 4 +- .../src/core/user/components/FileUpload.js | 4 +- frontend/src/core/user/components/SignIn.js | 2 +- .../src/core/user/components/SignInLink.js | 4 +- frontend/src/core/user/components/SignOut.js | 4 +- .../core/user/components/UserAutoUpdater.js | 4 +- .../src/core/user/components/UserAvatar.js | 3 +- .../src/core/user/components/UserControls.js | 10 +-- frontend/src/core/user/components/UserMenu.js | 8 +-- .../core/user/components/UserNotification.js | 2 +- .../user/components/UserNotificationsMenu.js | 12 ++-- .../core/utils/fluent/areSupportedElements.js | 2 +- .../src/core/utils/fluent/convertSyntax.js | 2 +- .../src/core/utils/fluent/getSimplePreview.js | 2 +- .../src/core/utils/fluent/isSimpleMessage.js | 2 +- .../fluent/isSimpleSingleAttributeMessage.js | 4 +- .../core/utils/fluent/isSupportedMessage.js | 2 +- frontend/src/core/utils/fluent/parser.js | 2 +- frontend/src/core/utils/fluent/serializer.js | 2 +- frontend/src/index.js | 2 +- .../batchactions/components/ApproveAll.js | 12 ++-- .../batchactions/components/BatchActions.js | 29 +++++---- .../batchactions/components/RejectAll.js | 16 ++--- .../batchactions/components/ReplaceAll.js | 12 ++-- .../entitieslist/components/EntitiesList.js | 29 ++++++--- .../modules/entitieslist/components/Entity.js | 12 ++-- .../components/ContextIssueButton.js | 2 +- .../components/EditorSelector.js | 2 +- .../entitydetails/components/EntityDetails.js | 55 ++++++++++------ .../components/EntityNavigation.js | 8 ++- .../components/FluentAttribute.js | 2 +- .../components/GenericOriginalString.js | 2 +- .../entitydetails/components/Helpers.js | 2 +- .../entitydetails/components/Metadata.js | 24 ++++--- .../components/OriginalStringProxy.js | 2 +- .../entitydetails/components/Property.js | 2 +- .../entitydetails/components/Screenshots.js | 4 +- .../entitydetails/components/TermsPopup.js | 2 +- .../fluenteditor/components/FluentEditor.js | 2 +- .../components/rich/RichEditor.js | 2 +- .../components/rich/RichTranslationForm.js | 6 +- .../components/simple/SimpleEditor.js | 2 +- .../components/source/SourceEditor.js | 2 +- .../components/FluentOriginalString.js | 2 +- .../fluentoriginal/components/RichString.js | 2 +- .../fluentoriginal/components/SimpleString.js | 2 +- .../fluentoriginal/components/SourceString.js | 2 +- .../genericeditor/components/GenericEditor.js | 2 +- .../components/GenericTranslationForm.js | 6 +- frontend/src/modules/history/actions.js | 2 +- .../src/modules/history/components/History.js | 5 +- .../modules/history/components/Translation.js | 34 ++++++---- .../components/InteractiveTour.js | 10 +-- .../machinery/components/ConcordanceSearch.js | 2 +- .../src/modules/machinery/components/Count.js | 2 +- .../modules/machinery/components/Machinery.js | 12 ++-- .../machinery/components/Translation.js | 4 +- .../machinery/components/TranslationSource.js | 7 ++- .../components/source/CaighdeanTranslation.js | 4 +- .../components/source/GoogleTranslation.js | 4 +- .../components/source/MicrosoftTerminology.js | 6 +- .../components/source/MicrosoftTranslation.js | 4 +- .../components/source/SystranTranslation.js | 4 +- .../components/source/TranslationMemory.js | 4 +- .../modules/navbar/components/Navigation.js | 8 +-- .../modules/otherlocales/components/Count.js | 2 +- .../otherlocales/components/OtherLocales.js | 11 ++-- .../otherlocales/components/Translation.js | 6 +- .../projectinfo/components/ProjectInfo.js | 11 ++-- .../components/ProgressChart.js | 2 +- .../components/ResourceProgress.js | 6 +- .../modules/search/components/FiltersPanel.js | 25 +++++--- .../modules/search/components/SearchBox.js | 62 ++++++++++++------- .../search/components/TimeRangeFilter.js | 33 ++++++---- .../search/components/chart-options.js | 2 +- frontend/src/modules/search/withSearch.js | 5 +- .../modules/teamcomments/components/Count.js | 2 +- .../teamcomments/components/TeamComments.js | 4 +- .../src/modules/terms/components/Count.js | 2 +- .../src/modules/terms/components/Terms.js | 2 +- .../components/UnsavedChanges.js | 8 +-- frontend/src/rootReducer.js | 2 +- frontend/yarn.lock | 8 +-- 178 files changed, 649 insertions(+), 440 deletions(-) create mode 100644 frontend/flow-typed/myLibDef.js diff --git a/.eslintrc.js b/.eslintrc.js index c6d8a8b33..5ab3b7829 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -59,6 +59,8 @@ module.exports = { SyntheticMouseEvent: false, TimeoutID: false, "$Diff": false, + "$ReadOnlyArray": false, + "React$Element": false, }, plugins: [ 'react', diff --git a/frontend/.flowconfig b/frontend/.flowconfig index dc4b39e27..0edc27e22 100644 --- a/frontend/.flowconfig +++ b/frontend/.flowconfig @@ -10,9 +10,7 @@ module.system=node module.system.node.resolve_dirname=node_modules module.system.node.resolve_dirname=./src - -# This is used to ignore some Flow errors if needed. -suppress_comment= \\(.\\|\n\\)*\\$FLOW_FIXME -suppress_comment= \\(.\\|\n\\)*\\$FLOW_IGNORE +module.name_mapper='^core\(.*\)$' -> '/src/core/\1' +module.name_mapper='^modules\(.*\)$' -> '/src/modules/\1' [strict] diff --git a/frontend/flow-typed/myLibDef.js b/frontend/flow-typed/myLibDef.js new file mode 100644 index 000000000..40b4f1810 --- /dev/null +++ b/frontend/flow-typed/myLibDef.js @@ -0,0 +1,36 @@ +declare module '@fluent/react' { + declare export class ReactLocalization { + constructor(Array): ReactLocalization; + } + + declare export function LocalizationProvider( + props: any, + ): React$Element; + + declare export interface LocalizedProps { + id: string; + attrs?: { [string]: boolean }; + children?: React$Node; + vars?: { [string]: any }; + elems?: { [string]: ?React$Element }; + } + declare export function Localized( + props: LocalizedProps, + ): React$Element; +} + +declare module 'react-content-marker' { + declare export type TagFunction = (input: string) => React$Element; + declare export interface Parser { + rule: string | RegExp; + tag: TagFunction; + matchIndex?: number; + } + declare export default function createMarker(parsers: Array): any; + declare export function mark( + content: string | Array, + rule: string | RegExp, + tag: TagFunction, + matchIndex?: number, + ): Array; +} diff --git a/frontend/package.json b/frontend/package.json index 11cf47eb9..027d5c9fe 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -11,7 +11,7 @@ "connected-react-router": "6.8.0", "date-and-time": "0.14.2", "diff-match-patch": "1.0.4", - "flow-bin": "0.95.1", + "flow-bin": "0.146.0", "highcharts": "7.2.2", "highcharts-react-official": "2.2.2", "html-react-parser": "0.13.0", diff --git a/frontend/src/App.js b/frontend/src/App.js index 8077fa333..be1dddbff 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -150,4 +150,4 @@ const mapStateToProps = (state: Object): Props => { }; }; -export default connect(mapStateToProps)(App); +export default (connect(mapStateToProps)(App): any); diff --git a/frontend/src/core/api/base.js b/frontend/src/core/api/base.js index 451a484be..2f3e34d82 100644 --- a/frontend/src/core/api/base.js +++ b/frontend/src/core/api/base.js @@ -34,13 +34,13 @@ export default class APIBase { return new URL(url, window.location.origin); } - toCamelCase = (s: string) => { + toCamelCase: (s: string) => string = (s: string) => { return s.replace(/([-_][a-z])/gi, ($1) => { return $1.toUpperCase().replace('-', '').replace('_', ''); }); }; - isObject = function (obj: any) { + isObject: (obj: any) => boolean = function (obj: any) { return ( obj === Object(obj) && !Array.isArray(obj) && @@ -96,7 +96,7 @@ export default class APIBase { } } - keysToCamelCase(results: any) { + keysToCamelCase(results: any): any { if (this.isObject(results)) { const newObj: any = {}; diff --git a/frontend/src/core/api/comment.js b/frontend/src/core/api/comment.js index 06607bbc1..3125250ec 100644 --- a/frontend/src/core/api/comment.js +++ b/frontend/src/core/api/comment.js @@ -3,7 +3,12 @@ import APIBase from './base'; export default class CommentAPI extends APIBase { - add(entity: number, locale: string, comment: string, translation: ?number) { + add( + entity: number, + locale: string, + comment: string, + translation: ?number, + ): Promise { const payload = new URLSearchParams(); payload.append('entity', entity.toString()); payload.append('locale', locale); @@ -20,7 +25,7 @@ export default class CommentAPI extends APIBase { return this.fetch('/add-comment/', 'POST', payload, headers); } - _updateComment(url: string, commentId: number) { + _updateComment(url: string, commentId: number): Promise { const payload = new URLSearchParams(); payload.append('comment_id', commentId.toString()); @@ -32,11 +37,11 @@ export default class CommentAPI extends APIBase { return this.fetch(url, 'POST', payload, headers); } - pinComment(commentId: number) { + pinComment(commentId: number): Promise { return this._updateComment('/pin-comment/', commentId); } - unpinComment(commentId: number) { + unpinComment(commentId: number): Promise { return this._updateComment('/unpin-comment/', commentId); } } diff --git a/frontend/src/core/api/entity.js b/frontend/src/core/api/entity.js index 4a19e922f..1dd4461e1 100644 --- a/frontend/src/core/api/entity.js +++ b/frontend/src/core/api/entity.js @@ -11,7 +11,7 @@ export default class EntityAPI extends APIBase { entities: Array, find: ?string, replace: ?string, - ) { + ): Promise { const payload = new FormData(); const csrfToken = this.getCSRFToken(); @@ -116,7 +116,11 @@ export default class EntityAPI extends APIBase { return await this.fetch('/get-entities/', 'POST', payload, headers); } - async getHistory(entity: number, locale: string, pluralForm: number = -1) { + async getHistory( + entity: number, + locale: string, + pluralForm: number = -1, + ): Promise { const payload = new URLSearchParams(); payload.append('entity', entity.toString()); payload.append('locale', locale); @@ -160,7 +164,7 @@ export default class EntityAPI extends APIBase { return results; } - async getTeamComments(entity: number, locale: string) { + async getTeamComments(entity: number, locale: string): Promise { const payload = new URLSearchParams(); payload.append('entity', entity.toString()); payload.append('locale', locale); @@ -178,7 +182,7 @@ export default class EntityAPI extends APIBase { return this.keysToCamelCase(results); } - async getTerms(sourceString: string, locale: string) { + async getTerms(sourceString: string, locale: string): Promise { const payload = new URLSearchParams(); payload.append('source_string', sourceString); payload.append('locale', locale); diff --git a/frontend/src/core/api/filter.js b/frontend/src/core/api/filter.js index 4dac22fa2..127308920 100644 --- a/frontend/src/core/api/filter.js +++ b/frontend/src/core/api/filter.js @@ -6,7 +6,7 @@ export default class FilterAPI extends APIBase { /** * Return data needed for filtering strings. */ - async get(locale: string, project: string, resource: string) { + async get(locale: string, project: string, resource: string): Promise { const headers = new Headers(); headers.append('X-Requested-With', 'XMLHttpRequest'); diff --git a/frontend/src/core/api/index.js b/frontend/src/core/api/index.js index 1f69bb1fa..58bfd98f7 100644 --- a/frontend/src/core/api/index.js +++ b/frontend/src/core/api/index.js @@ -29,14 +29,14 @@ export type { } from './types'; export default { - entity: new EntityAPI(), - comment: new CommentAPI(), - filter: new FilterAPI(), - locale: new LocaleAPI(), - l10n: new L10nAPI(), - machinery: new MachineryAPI(), - project: new ProjectAPI(), - resource: new ResourceAPI(), - translation: new TranslationAPI(), - user: new UserAPI(), + entity: (new EntityAPI(): EntityAPI), + comment: (new CommentAPI(): CommentAPI), + filter: (new FilterAPI(): FilterAPI), + locale: (new LocaleAPI(): LocaleAPI), + l10n: (new L10nAPI(): L10nAPI), + machinery: (new MachineryAPI(): MachineryAPI), + project: (new ProjectAPI(): ProjectAPI), + resource: (new ResourceAPI(): ResourceAPI), + translation: (new TranslationAPI(): TranslationAPI), + user: (new UserAPI(): UserAPI), }; diff --git a/frontend/src/core/api/l10n.js b/frontend/src/core/api/l10n.js index 0d7374447..446e8ac13 100644 --- a/frontend/src/core/api/l10n.js +++ b/frontend/src/core/api/l10n.js @@ -3,7 +3,7 @@ import APIBase from './base'; export default class L10nAPI extends APIBase { - async get(locale: string) { + async get(locale: string): Promise { const url = this.getFullURL(`/static/locale/${locale}/translate.ftl`); const response = await fetch(url); return await response.text(); diff --git a/frontend/src/core/api/locale.js b/frontend/src/core/api/locale.js index 2de18c0dc..9b5b0f632 100644 --- a/frontend/src/core/api/locale.js +++ b/frontend/src/core/api/locale.js @@ -3,7 +3,7 @@ import APIBase from './base'; export default class LocaleAPI extends APIBase { - async get(code: string) { + async get(code: string): Promise { const query = `{ locale(code: "${code}") { code diff --git a/frontend/src/core/api/machinery.js b/frontend/src/core/api/machinery.js index 246971c67..2ebb713ac 100644 --- a/frontend/src/core/api/machinery.js +++ b/frontend/src/core/api/machinery.js @@ -12,7 +12,7 @@ type ConcordanceTranslations = {| |}; export default class MachineryAPI extends APIBase { - async _get(url: string, params: Object) { + async _get(url: string, params: Object): Promise { const payload = new URLSearchParams(); for (let param in params) { payload.append(param, params[param]); diff --git a/frontend/src/core/api/project.js b/frontend/src/core/api/project.js index a738ba7c8..ad05f0015 100644 --- a/frontend/src/core/api/project.js +++ b/frontend/src/core/api/project.js @@ -3,7 +3,7 @@ import APIBase from './base'; export default class ProjectAPI extends APIBase { - async get(slug: string) { + async get(slug: string): Promise { const query = `{ project(slug: "${slug}") { slug diff --git a/frontend/src/core/api/resource.js b/frontend/src/core/api/resource.js index 4be5cb13c..ffff800be 100644 --- a/frontend/src/core/api/resource.js +++ b/frontend/src/core/api/resource.js @@ -3,7 +3,7 @@ import APIBase from './base'; export default class ResourceAPI extends APIBase { - async getAll(locale: string, project: string) { + async getAll(locale: string, project: string): Promise { const url = `/${locale}/${project}/parts/`; const headers = new Headers(); diff --git a/frontend/src/core/api/translation.js b/frontend/src/core/api/translation.js index 4a38e3a4e..6435eb958 100644 --- a/frontend/src/core/api/translation.js +++ b/frontend/src/core/api/translation.js @@ -20,7 +20,7 @@ export default class TranslationAPI extends APIBase { resource: string, ignoreWarnings: ?boolean, machinerySources: Array, - ) { + ): Promise { const csrfToken = this.getCSRFToken(); const payload = new URLSearchParams(); @@ -58,7 +58,7 @@ export default class TranslationAPI extends APIBase { id: number, resource: string, ignoreWarnings: ?boolean, - ) { + ): Promise { const csrfToken = this.getCSRFToken(); const payload = new URLSearchParams(); @@ -79,7 +79,11 @@ export default class TranslationAPI extends APIBase { return this.fetch(url, 'POST', payload, headers); } - approve(id: number, resource: string, ignoreWarnings: ?boolean) { + approve( + id: number, + resource: string, + ignoreWarnings: ?boolean, + ): Promise { return this._changeStatus( '/translations/approve/', id, @@ -88,19 +92,19 @@ export default class TranslationAPI extends APIBase { ); } - unapprove(id: number, resource: string) { + unapprove(id: number, resource: string): Promise { return this._changeStatus('/translations/unapprove/', id, resource); } - reject(id: number, resource: string) { + reject(id: number, resource: string): Promise { return this._changeStatus('/translations/reject/', id, resource); } - unreject(id: number, resource: string) { + unreject(id: number, resource: string): Promise { return this._changeStatus('/translations/unreject/', id, resource); } - delete(id: number) { + delete(id: number): Promise { const payload = new URLSearchParams(); payload.append('translation', id.toString()); diff --git a/frontend/src/core/comments/components/AddComment.js b/frontend/src/core/comments/components/AddComment.js index 4546e8bbf..82417f4d8 100644 --- a/frontend/src/core/comments/components/AddComment.js +++ b/frontend/src/core/comments/components/AddComment.js @@ -24,7 +24,7 @@ type Props = {| resetContactPerson?: () => void, |}; -export default function AddComment(props: Props) { +export default function AddComment(props: Props): React.Element<'div'> { const { parameters, translation, @@ -209,9 +209,9 @@ export default function AddComment(props: Props) { // This allows for the mention suggestions to stay properly positioned // when the container scrolls. React.useEffect(() => { - // Flow does not recognize the event listeners with 'SyntheticEvent`, - // so I'm ignoring the errors Flow throws here. - // $FLOW_IGNORE + // Flow does not recognize the addEventListener with 'SyntheticEvent` listeners, + // so I'm ignoring the errors Flow throws below. + const handleScroll = (e: SyntheticEvent) => { const element = e.currentTarget; setScrollPosition(element.scrollTop); @@ -225,17 +225,21 @@ export default function AddComment(props: Props) { } if (historyScroll) { + // $FlowIgnore historyScroll.addEventListener('scroll', handleScroll); } if (teamsScroll) { + //$FlowIgnore teamsScroll.addEventListener('scroll', handleScroll); } return () => { if (historyScroll) { + // $FlowIgnore historyScroll.removeEventListener('scroll', handleScroll); } if (teamsScroll) { + // $FlowIgnore teamsScroll.removeEventListener('scroll', handleScroll); } }; diff --git a/frontend/src/core/comments/components/Comment.js b/frontend/src/core/comments/components/Comment.js index e620e4c71..ff171f9f2 100644 --- a/frontend/src/core/comments/components/Comment.js +++ b/frontend/src/core/comments/components/Comment.js @@ -18,7 +18,7 @@ type Props = {| togglePinnedStatus?: (boolean, number) => void, |}; -export default function Comment(props: Props) { +export default function Comment(props: Props): null | React.Element<'li'> { const { comment, canPin, togglePinnedStatus } = props; if (!comment) { diff --git a/frontend/src/core/comments/components/CommentsList.js b/frontend/src/core/comments/components/CommentsList.js index 431315219..c47559700 100644 --- a/frontend/src/core/comments/components/CommentsList.js +++ b/frontend/src/core/comments/components/CommentsList.js @@ -25,7 +25,7 @@ type Props = {| resetContactPerson?: () => void, |}; -export default function CommentsList(props: Props) { +export default function CommentsList(props: Props): React.Element<'div'> { const { comments, parameters, diff --git a/frontend/src/core/diff/components/TranslationDiff.js b/frontend/src/core/diff/components/TranslationDiff.js index 369e02aee..26b97ec29 100644 --- a/frontend/src/core/diff/components/TranslationDiff.js +++ b/frontend/src/core/diff/components/TranslationDiff.js @@ -19,7 +19,7 @@ type Props = {| * Removed slices are wrapped in . */ export default class TranslationDiff extends React.Component { - render() { + render(): React.Node { const { base, target } = this.props; return getDiff(base, target); } diff --git a/frontend/src/core/diff/withDiff.js b/frontend/src/core/diff/withDiff.js index 7de295ee4..dae99c6da 100644 --- a/frontend/src/core/diff/withDiff.js +++ b/frontend/src/core/diff/withDiff.js @@ -7,7 +7,7 @@ import './components/TranslationDiff.css'; const dmp = new DiffMatchPatch(); -export function getDiff(base: string, target: string) { +export function getDiff(base: string, target: string): React.Node { const diff = dmp.diff_main(base, target); dmp.diff_cleanupSemantic(diff); diff --git a/frontend/src/core/editor/components/EditorMainAction.js b/frontend/src/core/editor/components/EditorMainAction.js index d81b67780..4d0e2afb3 100644 --- a/frontend/src/core/editor/components/EditorMainAction.js +++ b/frontend/src/core/editor/components/EditorMainAction.js @@ -23,7 +23,9 @@ type Props = { * Otherwise, if the "force suggestion" user setting is on, it renders "Suggest". * Otherwise, it renders "Save". */ -export default function EditorMainAction(props: Props) { +export default function EditorMainAction( + props: Props, +): React.Element { const isRunningRequest = useSelector( (state) => state.editor.isRunningRequest, ); @@ -51,7 +53,7 @@ export default function EditorMainAction(props: Props) { action: Function, title: string, label: string, - glyph: ?React.Node, + glyph: ?React.Element<'i'>, }; if ( diff --git a/frontend/src/core/editor/components/EditorMenu.js b/frontend/src/core/editor/components/EditorMenu.js index 8e0f0b6fb..88a2c1a55 100644 --- a/frontend/src/core/editor/components/EditorMenu.js +++ b/frontend/src/core/editor/components/EditorMenu.js @@ -30,7 +30,7 @@ type Props = {| * If the entity is read-only, shows a read-only notification. * Otherise, shows the various tools to control the editor. */ -export default function EditorMenu(props: Props) { +export default function EditorMenu(props: Props): React.Element<'menu'> { return ( {props.firstItemHook} diff --git a/frontend/src/core/editor/components/EditorSettings.js b/frontend/src/core/editor/components/EditorSettings.js index a01eebac2..8292b0188 100644 --- a/frontend/src/core/editor/components/EditorSettings.js +++ b/frontend/src/core/editor/components/EditorSettings.js @@ -28,7 +28,7 @@ export function EditorSettings({ settings, toggleSetting, onDiscard, -}: EditorSettingsProps) { +}: EditorSettingsProps): React.Element<'ul'> { const ref = React.useRef(null); useOnDiscard(ref, onDiscard); @@ -89,13 +89,13 @@ export default class EditorSettingsBase extends React.Component { }; } - toggleVisibility = () => { + toggleVisibility: () => void = () => { this.setState((state) => { return { visible: !state.visible }; }); }; - handleDiscard = () => { + handleDiscard: () => void = () => { this.setState({ visible: false, }); @@ -106,7 +106,7 @@ export default class EditorSettingsBase extends React.Component { this.toggleVisibility(); } - render() { + render(): React.Element<'div'> { return (
{ const dispatch = useDispatch(); const errors = useSelector((state) => state.editor.errors); @@ -91,7 +93,7 @@ export default function FailedChecks(props: FailedChecksProps) { } type MainActionProps = {| - source: number, + source: string, user: UserState, isTranslator: boolean, errors: Array, diff --git a/frontend/src/core/editor/components/KeyboardShortcuts.js b/frontend/src/core/editor/components/KeyboardShortcuts.js index fa97fe4a6..733c116a2 100644 --- a/frontend/src/core/editor/components/KeyboardShortcuts.js +++ b/frontend/src/core/editor/components/KeyboardShortcuts.js @@ -231,19 +231,19 @@ export default class KeyboardShortcutsBase extends React.Component< }; } - toggleVisibility = () => { + toggleVisibility: () => void = () => { this.setState((state) => { return { visible: !state.visible }; }); }; - handleDiscard = () => { + handleDiscard: () => void = () => { this.setState({ visible: false, }); }; - render() { + render(): React.Element<'div'> { return (
{ - getLimit() { + getLimit(): null | number { const { comment, format } = this.props; if (format !== 'lang') { @@ -44,7 +44,7 @@ export default class TranslationLength extends React.Component { // Only used for countdown. // Source: https://stackoverflow.com/a/47140708 - stripHTML(translation: string) { + stripHTML(translation: string): string { const doc = new DOMParser().parseFromString(translation, 'text/html'); if (!doc.body) { @@ -54,7 +54,7 @@ export default class TranslationLength extends React.Component { return doc.body.textContent || ''; } - render() { + render(): React.Element<'div'> { const { original, translation } = this.props; const limit = this.getLimit(); diff --git a/frontend/src/core/editor/hooks/useAddTextToTranslation.js b/frontend/src/core/editor/hooks/useAddTextToTranslation.js index 4ea673275..2bf0b4fd5 100644 --- a/frontend/src/core/editor/hooks/useAddTextToTranslation.js +++ b/frontend/src/core/editor/hooks/useAddTextToTranslation.js @@ -8,7 +8,10 @@ import { actions } from '..'; /** * Return a function to add text to the content of the editor. */ -export default function useAddTextToTranslation() { +export default function useAddTextToTranslation(): ( + content: string, + changeSource?: string, +) => void { const dispatch = useDispatch(); return useCallback( diff --git a/frontend/src/core/editor/hooks/useClearEditor.js b/frontend/src/core/editor/hooks/useClearEditor.js index c26e21c5d..bd95e1ab6 100644 --- a/frontend/src/core/editor/hooks/useClearEditor.js +++ b/frontend/src/core/editor/hooks/useClearEditor.js @@ -5,7 +5,7 @@ import useUpdateTranslation from './useUpdateTranslation'; /** * Return a function to clear the content of the editor. */ -export default function useClearEditor() { +export default function useClearEditor(): () => void { const updateTranslation = useUpdateTranslation(); return () => { diff --git a/frontend/src/core/editor/hooks/useCopyMachineryTranslation.js b/frontend/src/core/editor/hooks/useCopyMachineryTranslation.js index 216409125..e0a54866c 100644 --- a/frontend/src/core/editor/hooks/useCopyMachineryTranslation.js +++ b/frontend/src/core/editor/hooks/useCopyMachineryTranslation.js @@ -15,7 +15,9 @@ import useUpdateTranslation from './useUpdateTranslation'; /** * Return a function to copy the original translation into the editor. */ -export default function useCopyMachineryTranslation() { +export default function useCopyMachineryTranslation(): ( + translation: MachineryTranslation, +) => void { const dispatch = useDispatch(); const addTextToTranslation = useAddTextToTranslation(); diff --git a/frontend/src/core/editor/hooks/useCopyOriginalIntoEditor.js b/frontend/src/core/editor/hooks/useCopyOriginalIntoEditor.js index 4984f3720..297ec2f77 100644 --- a/frontend/src/core/editor/hooks/useCopyOriginalIntoEditor.js +++ b/frontend/src/core/editor/hooks/useCopyOriginalIntoEditor.js @@ -10,7 +10,7 @@ import useUpdateTranslation from './useUpdateTranslation'; /** * Return a function to copy the original translation into the editor. */ -export default function useCopyOriginalIntoEditor() { +export default function useCopyOriginalIntoEditor(): () => void { const updateTranslation = useUpdateTranslation(); const entity = useSelector((state) => diff --git a/frontend/src/core/editor/hooks/useCopyOtherLocaleTranslation.js b/frontend/src/core/editor/hooks/useCopyOtherLocaleTranslation.js index ccba25085..faa663b65 100644 --- a/frontend/src/core/editor/hooks/useCopyOtherLocaleTranslation.js +++ b/frontend/src/core/editor/hooks/useCopyOtherLocaleTranslation.js @@ -11,7 +11,9 @@ import useUpdateTranslation from './useUpdateTranslation'; /** * Return a function to copy the other locale translation into the editor. */ -export default function useCopyOtherLocaleTranslation() { +export default function useCopyOtherLocaleTranslation(): ( + translation: OtherLocaleTranslation, +) => void { const updateTranslation = useUpdateTranslation(); const isReadOnlyEditor = useSelector((state) => entities.selectors.isReadOnlyEditor(state), diff --git a/frontend/src/core/editor/hooks/useHandleShortcuts.js b/frontend/src/core/editor/hooks/useHandleShortcuts.js index 1263187ac..58e81f920 100644 --- a/frontend/src/core/editor/hooks/useHandleShortcuts.js +++ b/frontend/src/core/editor/hooks/useHandleShortcuts.js @@ -9,7 +9,12 @@ import * as unsavedchanges from 'modules/unsavedchanges'; /** * Return a function to handle shortcuts in a translation form. */ -export default function useHandleShortcuts() { +export default function useHandleShortcuts(): ( + event: SyntheticKeyboardEvent, + sendTranslation: (ignoreWarnings?: boolean, translation?: string) => void, + clearEditorCustom?: () => void, + copyOriginalIntoEditorCustom?: () => void, +) => void { const dispatch = useDispatch(); const clearEditor = editor.useClearEditor(); @@ -143,7 +148,7 @@ export default function useHandleShortcuts() { } const numTranslations = - translations.length + (searchResults && searchResults.length); + translations.length + (searchResults?.length || 0); if (!numTranslations) { return; } diff --git a/frontend/src/core/editor/hooks/useSendTranslation.js b/frontend/src/core/editor/hooks/useSendTranslation.js index 1d7e6b2f9..9c6d7b9c6 100644 --- a/frontend/src/core/editor/hooks/useSendTranslation.js +++ b/frontend/src/core/editor/hooks/useSendTranslation.js @@ -11,7 +11,10 @@ import { actions } from '..'; /** * Return a function to send a translation to the server. */ -export default function useSendTranslation() { +export default function useSendTranslation(): ( + ignoreWarnings?: boolean, + content?: string, +) => void { const dispatch = useDispatch(); const translation = useSelector((state) => state.editor.translation); diff --git a/frontend/src/core/editor/hooks/useUpdateTranslation.js b/frontend/src/core/editor/hooks/useUpdateTranslation.js index c9ce7f9a9..03c3dba49 100644 --- a/frontend/src/core/editor/hooks/useUpdateTranslation.js +++ b/frontend/src/core/editor/hooks/useUpdateTranslation.js @@ -10,7 +10,10 @@ import type { Translation } from 'core/editor'; /** * Return a function to update the content of the editor. */ -export default function useUpdateTranslation() { +export default function useUpdateTranslation(): ( + translation: Translation, + changeSource?: string, +) => void { const dispatch = useDispatch(); return useCallback( diff --git a/frontend/src/core/editor/hooks/useUpdateTranslationStatus.js b/frontend/src/core/editor/hooks/useUpdateTranslationStatus.js index 621483ecc..edd5a417f 100644 --- a/frontend/src/core/editor/hooks/useUpdateTranslationStatus.js +++ b/frontend/src/core/editor/hooks/useUpdateTranslationStatus.js @@ -14,7 +14,11 @@ import type { ChangeOperation } from 'modules/history'; /** * Return a function to update the status (approved, rejected... ) of a translation. */ -export default function useUpdateTranslationStatus() { +export default function useUpdateTranslationStatus(): ( + translationId: number, + change: ChangeOperation, + ignoreWarnings: ?boolean, +) => void { const dispatch = useDispatch(); const entity = useSelector((state) => diff --git a/frontend/src/core/editor/selectors.js b/frontend/src/core/editor/selectors.js index 47cd8a3e9..3ce7dc2b7 100644 --- a/frontend/src/core/editor/selectors.js +++ b/frontend/src/core/editor/selectors.js @@ -31,7 +31,7 @@ export function _existingTranslation( (translation === initialTranslation || // If translation is a FluentMessage, from the fluent editor. (translation.equals && - // $FLOW_IGNORE: `equals`, if defined, will always be a function. + // $FlowIgnore: `equals`, if defined, will always be a function. translation.equals(initialTranslation))) ) { existingTranslation = activeTranslation; @@ -109,7 +109,7 @@ function _isFluentMessage(editorState: EditorState) { /** * Returns `true` if the current editor translation contains a Fluent message. */ -const isFluentTranslationMessage = createSelector( +const isFluentTranslationMessage: any = createSelector( editorSelector, _isFluentMessage, ); diff --git a/frontend/src/core/l10n/actions.js b/frontend/src/core/l10n/actions.js index 4422dd9e2..e9880cc1d 100644 --- a/frontend/src/core/l10n/actions.js +++ b/frontend/src/core/l10n/actions.js @@ -44,7 +44,7 @@ export function receive(localization: ReactLocalization): ReceiveAction { * This fetches the translations for the UI for each given locale, bundles * those and store them to be used in showing a localized interface. */ -export function get(locales: Array): Function { +export function get(locales: $ReadOnlyArray): Function { return async (dispatch) => { dispatch(request()); diff --git a/frontend/src/core/l10n/components/AppLocalizationProvider.js b/frontend/src/core/l10n/components/AppLocalizationProvider.js index a2b1054f9..a0b322347 100644 --- a/frontend/src/core/l10n/components/AppLocalizationProvider.js +++ b/frontend/src/core/l10n/components/AppLocalizationProvider.js @@ -42,7 +42,7 @@ export class AppLocalizationProviderBase extends React.Component this.props.dispatch(l10n.actions.get(locales)); } - render() { + render(): React.Element { const { children, l10n } = this.props; return ( @@ -59,4 +59,4 @@ const mapStateToProps = (state: Object): Props => { }; }; -export default connect(mapStateToProps)(AppLocalizationProviderBase); +export default (connect(mapStateToProps)(AppLocalizationProviderBase): any); diff --git a/frontend/src/core/lightbox/components/Lightbox.js b/frontend/src/core/lightbox/components/Lightbox.js index 7194e0d2b..68c0cc423 100644 --- a/frontend/src/core/lightbox/components/Lightbox.js +++ b/frontend/src/core/lightbox/components/Lightbox.js @@ -63,11 +63,11 @@ function LightboxContent({ image, onClose }: ContentProps) { } export class LightboxBase extends React.Component { - close = () => { + close: () => void = () => { this.props.dispatch(close()); }; - render() { + render(): null | React.Element { const { lightbox } = this.props; if (!lightbox.isOpen) { @@ -84,4 +84,4 @@ const mapStateToProps = (state: Object): Props => { }; }; -export default connect(mapStateToProps)(LightboxBase); +export default (connect(mapStateToProps)(LightboxBase): any); diff --git a/frontend/src/core/locale/actions.js b/frontend/src/core/locale/actions.js index ec75f4ccb..25309ca1a 100644 --- a/frontend/src/core/locale/actions.js +++ b/frontend/src/core/locale/actions.js @@ -32,7 +32,7 @@ export type Locale = {| export type RequestAction = {| type: typeof REQUEST, |}; -export function request() { +export function request(): RequestAction { return { type: REQUEST, }; @@ -42,7 +42,7 @@ export type ReceiveAction = {| type: typeof RECEIVE, locale: Locale, |}; -export function receive(locale: Locale) { +export function receive(locale: Locale): ReceiveAction { return { type: RECEIVE, locale, diff --git a/frontend/src/core/locale/getPluralExamples.js b/frontend/src/core/locale/getPluralExamples.js index 29a412bef..16e03924b 100644 --- a/frontend/src/core/locale/getPluralExamples.js +++ b/frontend/src/core/locale/getPluralExamples.js @@ -16,7 +16,9 @@ import type { Locale } from './actions'; * @param {Locale} locale A Locale object. * @returns {Object} A map of locale's cldrPlurals and their plural examples. */ -export default function getPluralExamples(locale: Locale) { +export default function getPluralExamples( + locale: Locale, +): { [number]: number } { const pluralsCount = locale.cldrPlurals.length; const examples = {}; diff --git a/frontend/src/core/notification/actions.js b/frontend/src/core/notification/actions.js index 968ddb611..5ea8ddad2 100644 --- a/frontend/src/core/notification/actions.js +++ b/frontend/src/core/notification/actions.js @@ -1,6 +1,5 @@ /* @flow */ -import { Localized } from '@fluent/react'; import shortid from 'shortid'; export const ADD: 'notification/ADD' = 'notification/ADD'; @@ -14,7 +13,7 @@ export type NotificationType = export type NotificationMessage = {| +type: NotificationType, - +content: string | typeof Localized, + +content: string | React$Element, +key?: string, |}; diff --git a/frontend/src/core/notification/components/NotificationPanel.js b/frontend/src/core/notification/components/NotificationPanel.js index 02e994cd5..4404921ee 100644 --- a/frontend/src/core/notification/components/NotificationPanel.js +++ b/frontend/src/core/notification/components/NotificationPanel.js @@ -47,12 +47,12 @@ export default class NotificationPanel extends React.Component { } } - hide = () => { + hide: () => void = () => { clearTimeout(this.hideTimeout); this.setState({ hiding: true }); }; - render() { + render(): React.Element<'div'> { const { notification } = this.props; let hideClass = ''; diff --git a/frontend/src/core/placeable/components/WithPlaceables.js b/frontend/src/core/placeable/components/WithPlaceables.js index a53862378..9a165a674 100644 --- a/frontend/src/core/placeable/components/WithPlaceables.js +++ b/frontend/src/core/placeable/components/WithPlaceables.js @@ -83,6 +83,6 @@ export const rules = [ /** * Component that marks placeables in a string. */ -const WithPlaceables = createMarker(rules); +const WithPlaceables: any = createMarker(rules); export default WithPlaceables; diff --git a/frontend/src/core/placeable/components/WithPlaceablesForFluent.js b/frontend/src/core/placeable/components/WithPlaceablesForFluent.js index 875f714c5..59f791919 100644 --- a/frontend/src/core/placeable/components/WithPlaceablesForFluent.js +++ b/frontend/src/core/placeable/components/WithPlaceablesForFluent.js @@ -1,6 +1,7 @@ /* @flow */ import createMarker from 'react-content-marker'; +import type { Parser } from 'react-content-marker'; import './WithPlaceables.css'; @@ -11,7 +12,7 @@ import fluentString from '../parsers/fluentString'; import fluentTerm from '../parsers/fluentTerm'; import multipleSpaces from '../parsers/multipleSpaces'; -export function getRulesWithFluent(rules: Array) { +export function getRulesWithFluent(rules: Array): Array { const newRules = [...rules]; // Insert after the last space-related rule. @@ -31,6 +32,6 @@ export function getRulesWithFluent(rules: Array) { * The Fluent rules must come right after the space rules, otherwise it * generates a lot of false positives. */ -const WithPlaceablesForFluent = createMarker(getRulesWithFluent(rules)); +const WithPlaceablesForFluent: any = createMarker(getRulesWithFluent(rules)); export default WithPlaceablesForFluent; diff --git a/frontend/src/core/placeable/components/WithPlaceablesForFluentNoLeadingSpace.js b/frontend/src/core/placeable/components/WithPlaceablesForFluentNoLeadingSpace.js index b47902f8e..e1aacf5f8 100644 --- a/frontend/src/core/placeable/components/WithPlaceablesForFluentNoLeadingSpace.js +++ b/frontend/src/core/placeable/components/WithPlaceablesForFluentNoLeadingSpace.js @@ -14,7 +14,7 @@ import { getRulesWithoutLeadingSpace } from './WithPlaceablesNoLeadingSpace'; * * See ./WithPlaceablesNoLeadingSpace.js for documentation. */ -const WithPlaceablesForFluentNoLeadingSpace = createMarker( +const WithPlaceablesForFluentNoLeadingSpace: any = createMarker( getRulesWithFluent(getRulesWithoutLeadingSpace(rules)), ); diff --git a/frontend/src/core/placeable/components/WithPlaceablesNoLeadingSpace.js b/frontend/src/core/placeable/components/WithPlaceablesNoLeadingSpace.js index d72f18f82..f6a52bf22 100644 --- a/frontend/src/core/placeable/components/WithPlaceablesNoLeadingSpace.js +++ b/frontend/src/core/placeable/components/WithPlaceablesNoLeadingSpace.js @@ -1,6 +1,7 @@ /* @flow */ import createMarker from 'react-content-marker'; +import type { Parser } from 'react-content-marker'; import './WithPlaceables.css'; @@ -8,7 +9,9 @@ import { rules } from './WithPlaceables'; import leadingSpace from '../parsers/leadingSpace'; import unusualSpace from '../parsers/unusualSpace'; -export function getRulesWithoutLeadingSpace(rules: Array) { +export function getRulesWithoutLeadingSpace( + rules: Array, +): Array { let newRules = [...rules]; newRules.splice(newRules.indexOf(leadingSpace), 1); newRules.splice(newRules.indexOf(unusualSpace), 1); @@ -26,7 +29,7 @@ export function getRulesWithoutLeadingSpace(rules: Array) { * have a special Placeables component without that parser, for use in * combination with other parsing tools (like diff). */ -const WithPlaceablesNoLeadingSpace = createMarker( +const WithPlaceablesNoLeadingSpace: any = createMarker( getRulesWithoutLeadingSpace(rules), ); diff --git a/frontend/src/core/placeable/parsers/altAttribute.js b/frontend/src/core/placeable/parsers/altAttribute.js index 0c7efe7f5..099460542 100644 --- a/frontend/src/core/placeable/parsers/altAttribute.js +++ b/frontend/src/core/placeable/parsers/altAttribute.js @@ -15,8 +15,8 @@ import { Localized } from '@fluent/react'; * https://github.com/translate/translate/blob/2.3.1/translate/storage/placeables/general.py#L55 */ const altAttribute = { - rule: /(alt=".*?")/i, - tag: (x: string) => { + rule: (/(alt=".*?")/i: RegExp), + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + rule: (/({ ?[A-W0-9\-_]+[^}]* ?})/: RegExp), + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + rule: (/({ ?"[^}]*" ?})/: RegExp), + tag: (x: string): React.Element => { return ( { + rule: (/({ ?-[^}]* ?})/: RegExp), + tag: (x: string): React.Element => { return ( diff --git a/frontend/src/core/placeable/parsers/javaFormattingVariable.js b/frontend/src/core/placeable/parsers/javaFormattingVariable.js index 3047c5702..3807e0ba8 100644 --- a/frontend/src/core/placeable/parsers/javaFormattingVariable.js +++ b/frontend/src/core/placeable/parsers/javaFormattingVariable.js @@ -24,9 +24,9 @@ import { Localized } from '@fluent/react'; * https://github.com/translate/translate/blob/2.3.1/translate/storage/placeables/general.py#L127 */ const javaFormattingVariable = { - rule: /({[0-9]+(,\s*(number(,\s*(integer|currency|percent|[-0#.,E;%\u2030\u00a4']+)?)?|(date|time)(,\s*(short|medium|long|full|.+?))?|choice,([^{]+({.+})?)+)?)?})/, + rule: (/({[0-9]+(,\s*(number(,\s*(integer|currency|percent|[-0#.,E;%\u2030\u00a4']+)?)?|(date|time)(,\s*(short|medium|long|full|.+?))?|choice,([^{]+({.+})?)+)?)?})/: RegExp), matchIndex: 0, - tag: (x: string) => { + tag: (x: string): React.Element => { return ( { + rule: (/(\$[A-Z0-9_]+\$)/: RegExp), + tag: (x: string): React.Element => { return ( { + rule: (/(^ +)/: RegExp), + tag: (x: string): React.Element => { return ( { + rule: (/( +)/: RegExp), + tag: (x: string): React.Element => { return ( { + rule: (/([\u202F])/: RegExp), + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( +\-= ]*\)[+|-|0\d+|#]?[.\d+]?[s|d|e|f|g|o|x|c|%])/i, - tag: (x: string) => { + rule: (/(%\([[\w\d!.,[\]%:$<>+\-= ]*\)[+|-|0\d+|#]?[.\d+]?[s|d|e|f|g|o|x|c|%])/i: RegExp), + tag: (x: string): React.Element => { return ( +-= ]*\}?})/, - tag: (x: string) => { + rule: (/(\{{?[\w\d!.,[\]%:$<>+-= ]*\}?})/: RegExp), + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + rule: (/(\b([A-Z][0-9])|([0-9][A-Z])\b)/: RegExp), + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + tag: (x: string): React.Element => { return ( { + rule: (/([\u2009])/: RegExp), + tag: (x: string): React.Element => { return ( diff --git a/frontend/src/core/placeable/parsers/unusualSpace.js b/frontend/src/core/placeable/parsers/unusualSpace.js index a07c56b7f..1ac5c6848 100644 --- a/frontend/src/core/placeable/parsers/unusualSpace.js +++ b/frontend/src/core/placeable/parsers/unusualSpace.js @@ -16,8 +16,8 @@ import { Localized } from '@fluent/react'; * "hello world" */ const unusualSpace = { - rule: /( +$|[\r\n\t]( +)| {2,})/, - tag: (x: string) => { + rule: (/( +$|[\r\n\t]( +)| {2,})/: RegExp), + tag: (x: string): React.Element => { return ( ),"]))/.source + ')', 'i', // This one is not case sensitive. - ), + ): RegExp), matchIndex: 0, - tag: (x: string) => { + tag: (x: string): React.Element => { return ( diff --git a/frontend/src/core/placeable/parsers/xmlEntity.js b/frontend/src/core/placeable/parsers/xmlEntity.js index b0a6f36c9..c7e366b97 100644 --- a/frontend/src/core/placeable/parsers/xmlEntity.js +++ b/frontend/src/core/placeable/parsers/xmlEntity.js @@ -15,9 +15,9 @@ import { Localized } from '@fluent/react'; * https://github.com/translate/translate/blob/2.3.1/translate/storage/placeables/general.py#L254 */ const xmlEntity = { - rule: /(&(([a-zA-Z][a-zA-Z0-9.-]*)|([#](\d{1,5}|x[a-fA-F0-9]{1,5})+));)/, + rule: (/(&(([a-zA-Z][a-zA-Z0-9.-]*)|([#](\d{1,5}|x[a-fA-F0-9]{1,5})+));)/: RegExp), matchIndex: 0, - tag: (x: string) => { + tag: (x: string): React.Element => { return ( diff --git a/frontend/src/core/placeable/parsers/xmlTag.js b/frontend/src/core/placeable/parsers/xmlTag.js index b2cfd4da0..189d86536 100644 --- a/frontend/src/core/placeable/parsers/xmlTag.js +++ b/frontend/src/core/placeable/parsers/xmlTag.js @@ -16,9 +16,9 @@ import { Localized } from '@fluent/react'; * https://github.com/translate/translate/blob/2.3.1/translate/storage/placeables/general.py#L301 */ const xmlTag = { - rule: /(<[\w.:]+(\s([\w.:-]+=((".*?")|('.*?')))?)*\/?>|<\/[\w.]+>)/, + rule: (/(<[\w.:]+(\s([\w.:-]+=((".*?")|('.*?')))?)*\/?>|<\/[\w.]+>)/: RegExp), matchIndex: 0, - tag: (x: string) => { + tag: (x: string): React.Element => { return ( diff --git a/frontend/src/core/plural/actions.js b/frontend/src/core/plural/actions.js index 363c9057c..54691296a 100644 --- a/frontend/src/core/plural/actions.js +++ b/frontend/src/core/plural/actions.js @@ -28,7 +28,7 @@ export function moveToNextTranslation( export type ResetAction = {| type: typeof RESET, |}; -export function reset() { +export function reset(): ResetAction { return { type: RESET, }; @@ -38,7 +38,7 @@ export type SelectAction = {| type: typeof SELECT, pluralForm: number, |}; -export function select(pluralForm: number) { +export function select(pluralForm: number): SelectAction { return { type: SELECT, pluralForm, diff --git a/frontend/src/core/plural/components/PluralSelector.js b/frontend/src/core/plural/components/PluralSelector.js index 188157cbd..858c00777 100644 --- a/frontend/src/core/plural/components/PluralSelector.js +++ b/frontend/src/core/plural/components/PluralSelector.js @@ -58,7 +58,7 @@ export class PluralSelectorBase extends React.Component { ); } - render() { + render(): null | React.Element<'nav'> { const props = this.props; const { pluralForm } = props; @@ -96,7 +96,9 @@ export class PluralSelectorBase extends React.Component { } } -export default function PluralSelector(props: WrapperProps) { +export default function PluralSelector( + props: WrapperProps, +): React.Element { const state = { locale: useSelector((state) => state[locale.NAME]), pluralForm: useSelector((state) => selectors.getPluralForm(state)), diff --git a/frontend/src/core/project/components/ProjectItem.js b/frontend/src/core/project/components/ProjectItem.js index 22abb420e..e234c83f6 100644 --- a/frontend/src/core/project/components/ProjectItem.js +++ b/frontend/src/core/project/components/ProjectItem.js @@ -18,7 +18,7 @@ type Props = {| /** * Render a project menu item. */ -export default function ProjectItem(props: Props) { +export default function ProjectItem(props: Props): React.Element<'li'> { const { parameters, localization, navigateToPath } = props; const project = localization.project; const className = parameters.project === project.slug ? 'current' : null; diff --git a/frontend/src/core/project/components/ProjectMenu.js b/frontend/src/core/project/components/ProjectMenu.js index e0fd21f2e..f02e1a44a 100644 --- a/frontend/src/core/project/components/ProjectMenu.js +++ b/frontend/src/core/project/components/ProjectMenu.js @@ -36,7 +36,7 @@ export function ProjectMenu({ parameters, onDiscard, onNavigate, -}: ProjectMenuProps) { +}: ProjectMenuProps): React.Element<'div'> { // Searching const [search, setSearch] = React.useState(''); @@ -193,19 +193,21 @@ export default class ProjectMenuBase extends React.Component { }; } - toggleVisibility = () => { + toggleVisibility: () => void = () => { this.setState((state) => { return { visible: !state.visible }; }); }; - handleDiscard = () => { + handleDiscard: () => void = () => { this.setState({ visible: false, }); }; - navigateToPath = (event: SyntheticMouseEvent) => { + navigateToPath: (event: SyntheticMouseEvent) => void = ( + event: SyntheticMouseEvent, + ) => { event.preventDefault(); const path = event.currentTarget.pathname; @@ -216,7 +218,7 @@ export default class ProjectMenuBase extends React.Component { }); }; - render() { + render(): React.Element<'li'> { const { locale, parameters, project } = this.props; if (parameters.project !== 'all-projects') { diff --git a/frontend/src/core/project/components/ProjectPercent.js b/frontend/src/core/project/components/ProjectPercent.js index 2a741c2e5..eb2c47dea 100644 --- a/frontend/src/core/project/components/ProjectPercent.js +++ b/frontend/src/core/project/components/ProjectPercent.js @@ -13,7 +13,7 @@ type Props = {| /** * Render a project item percentage. */ -export default function ProjectPercent(props: Props) { +export default function ProjectPercent(props: Props): React.Element<'span'> { const { approvedStrings, stringsWithWarnings, diff --git a/frontend/src/core/resource/components/ResourceItem.js b/frontend/src/core/resource/components/ResourceItem.js index 763cfc4b4..40ca2507f 100644 --- a/frontend/src/core/resource/components/ResourceItem.js +++ b/frontend/src/core/resource/components/ResourceItem.js @@ -18,7 +18,7 @@ type Props = {| /** * Render a resource menu item. */ -export default function ResourceItem(props: Props) { +export default function ResourceItem(props: Props): React.Element<'li'> { const { parameters, resource, navigateToPath } = props; const className = parameters.resource === resource.path ? 'current' : null; diff --git a/frontend/src/core/resource/components/ResourceMenu.js b/frontend/src/core/resource/components/ResourceMenu.js index 2a988c93b..8a4f309dc 100644 --- a/frontend/src/core/resource/components/ResourceMenu.js +++ b/frontend/src/core/resource/components/ResourceMenu.js @@ -36,7 +36,7 @@ export function ResourceMenu({ resources, onDiscard, onNavigate, -}: ResourceMenuProps) { +}: ResourceMenuProps): React.Element<'div'> { // Searching const [search, setSearch] = React.useState(''); const resourceElements = resources.resources.filter( @@ -216,19 +216,21 @@ export default class ResourceMenuBase extends React.Component { }; } - toggleVisibility = () => { + toggleVisibility: () => void = () => { this.setState((state) => { return { visible: !state.visible }; }); }; - handleDiscard = () => { + handleDiscard: () => void = () => { this.setState({ visible: false, }); }; - navigateToPath = (event: SyntheticMouseEvent) => { + navigateToPath: (event: SyntheticMouseEvent) => void = ( + event: SyntheticMouseEvent, + ) => { event.preventDefault(); const path = event.currentTarget.pathname; @@ -239,7 +241,7 @@ export default class ResourceMenuBase extends React.Component { }); }; - render() { + render(): null | React.Element<'li'> { const { parameters, resources } = this.props; if (parameters.project === 'all-projects') { diff --git a/frontend/src/core/resource/components/ResourcePercent.js b/frontend/src/core/resource/components/ResourcePercent.js index f88c8a4ff..f5750f54d 100644 --- a/frontend/src/core/resource/components/ResourcePercent.js +++ b/frontend/src/core/resource/components/ResourcePercent.js @@ -13,7 +13,7 @@ type Props = {| /** * Render a resource item percentage. */ -export default function ResourcePercent(props: Props) { +export default function ResourcePercent(props: Props): React.Element<'span'> { const { approvedStrings, stringsWithWarnings, diff --git a/frontend/src/core/term/components/Term.js b/frontend/src/core/term/components/Term.js index c3452b9ac..5113e217d 100644 --- a/frontend/src/core/term/components/Term.js +++ b/frontend/src/core/term/components/Term.js @@ -18,7 +18,7 @@ type Props = {| /** * Shows term entry with its metadata. */ -export default function Term(props: Props) { +export default function Term(props: Props): React.Element { const { isReadOnlyEditor, locale, term } = props; const copyTermIntoEditor = (translation: string) => { diff --git a/frontend/src/core/term/components/TermsList.js b/frontend/src/core/term/components/TermsList.js index 68bd383c2..76ba8d98f 100644 --- a/frontend/src/core/term/components/TermsList.js +++ b/frontend/src/core/term/components/TermsList.js @@ -19,7 +19,7 @@ type Props = {| /** * Shows a list of terms. */ -export default function TermsList(props: Props) { +export default function TermsList(props: Props): React.Element<'ul'> { return (
    {props.terms.map((term, i) => { diff --git a/frontend/src/core/term/getMarker.js b/frontend/src/core/term/getMarker.js index faddbf271..b1f1e56e9 100644 --- a/frontend/src/core/term/getMarker.js +++ b/frontend/src/core/term/getMarker.js @@ -13,7 +13,7 @@ import { import type { TermState } from 'core/term'; -export default function getMarker(terms: TermState, forFluent: ?boolean) { +export default function getMarker(terms: TermState, forFluent: ?boolean): any { let placeableRules = getRulesWithoutLeadingSpace(rules); if (forFluent) { diff --git a/frontend/src/core/translation/components/FluentTranslation.js b/frontend/src/core/translation/components/FluentTranslation.js index a32ebac72..c9ffd8086 100644 --- a/frontend/src/core/translation/components/FluentTranslation.js +++ b/frontend/src/core/translation/components/FluentTranslation.js @@ -12,18 +12,18 @@ import { withSearch } from 'modules/search'; import type { TranslationProps } from './GenericTranslation'; -// $FLOW_IGNORE: I just can't get HOC working with Flow. +// $FlowIgnore: I just can't get HOC working with Flow. const TranslationPlaceablesDiff = withDiff( WithPlaceablesForFluentNoLeadingSpace, ); -// $FLOW_IGNORE: I just can't get HOC working with Flow. +// $FlowIgnore: I just can't get HOC working with Flow. const TranslationPlaceablesSearch = withSearch( WithPlaceablesForFluentNoLeadingSpace, ); export default class FluentTranslation extends React.Component { - render() { + render(): React.Element { const { content, diffTarget, search } = this.props; if (diffTarget) { diff --git a/frontend/src/core/translation/components/GenericTranslation.js b/frontend/src/core/translation/components/GenericTranslation.js index d56b6f9d1..061782d77 100644 --- a/frontend/src/core/translation/components/GenericTranslation.js +++ b/frontend/src/core/translation/components/GenericTranslation.js @@ -6,10 +6,10 @@ import { withDiff } from 'core/diff'; import { WithPlaceables, WithPlaceablesNoLeadingSpace } from 'core/placeable'; import { withSearch } from 'modules/search'; -// $FLOW_IGNORE: I just can't get HOC working with Flow. +// $FlowIgnore: I just can't get HOC working with Flow. const TranslationPlaceablesDiff = withDiff(WithPlaceablesNoLeadingSpace); -// $FLOW_IGNORE: I just can't get HOC working with Flow. +// $FlowIgnore: I just can't get HOC working with Flow. const TranslationPlaceablesSearch = withSearch(WithPlaceablesNoLeadingSpace); export type TranslationProps = {| @@ -19,7 +19,7 @@ export type TranslationProps = {| |}; export default class GenericTranslation extends React.Component { - render() { + render(): React.Element { const { content, diffTarget, search } = this.props; if (diffTarget) { diff --git a/frontend/src/core/translation/components/TranslationProxy.js b/frontend/src/core/translation/components/TranslationProxy.js index bd3ef108a..6872397be 100644 --- a/frontend/src/core/translation/components/TranslationProxy.js +++ b/frontend/src/core/translation/components/TranslationProxy.js @@ -13,7 +13,7 @@ type Props = {| |}; export default class TranslationProxy extends React.Component { - render() { + render(): null | React.Element { const { content, diffTarget, format, search } = this.props; if (!content) { diff --git a/frontend/src/core/user/actions.js b/frontend/src/core/user/actions.js index 2f8b00f31..2a6dad70d 100644 --- a/frontend/src/core/user/actions.js +++ b/frontend/src/core/user/actions.js @@ -30,10 +30,10 @@ export function updateTourStatus(step: number): Function { }; } -export type Settings = { +export type Settings = {| runQualityChecks?: boolean, forceSuggestions?: boolean, -}; +|}; /** * Update the user settings. diff --git a/frontend/src/core/user/components/FileUpload.js b/frontend/src/core/user/components/FileUpload.js index c5d39c0f7..07a0ff24f 100644 --- a/frontend/src/core/user/components/FileUpload.js +++ b/frontend/src/core/user/components/FileUpload.js @@ -22,14 +22,14 @@ export default class FileUpload extends React.Component { this.uploadForm = React.createRef(); } - submitForm = () => { + submitForm: () => void = () => { const form = this.uploadForm.current; if (form) { form.submit(); } }; - render() { + render(): React.Element<'form'> { const { parameters } = this.props; /* TODO: Refactor core.api.base and reuse getCSRFToken() here */ diff --git a/frontend/src/core/user/components/SignIn.js b/frontend/src/core/user/components/SignIn.js index 0fe6b8665..19ac0cc65 100644 --- a/frontend/src/core/user/components/SignIn.js +++ b/frontend/src/core/user/components/SignIn.js @@ -15,7 +15,7 @@ type Props = {| * Render a Sign In link styled as a button. */ export default class SignIn extends React.Component { - render() { + render(): React.Element<'span'> { return ( diff --git a/frontend/src/core/user/components/SignInLink.js b/frontend/src/core/user/components/SignInLink.js index 1aecd3b26..c88885b86 100644 --- a/frontend/src/core/user/components/SignInLink.js +++ b/frontend/src/core/user/components/SignInLink.js @@ -11,7 +11,7 @@ type Props = {| * Render a link to the Sign In process. */ export default class SignInLink extends React.Component { - generateSignInURL() { + generateSignInURL(): string { const absoluteUrl = window.location.origin + this.props.url; const parsedUrl = new URL(absoluteUrl); const next = window.location.pathname + window.location.search; @@ -21,7 +21,7 @@ export default class SignInLink extends React.Component { return parsedUrl.toString(); } - render() { + render(): React.Element<'a'> { return {this.props.children}; } } diff --git a/frontend/src/core/user/components/SignOut.js b/frontend/src/core/user/components/SignOut.js index b6e27c2fe..4c0d44c8e 100644 --- a/frontend/src/core/user/components/SignOut.js +++ b/frontend/src/core/user/components/SignOut.js @@ -11,11 +11,11 @@ type Props = {| * Render a Sign Out link. */ export default class SignOut extends React.Component { - signOut = () => { + signOut: () => void = () => { this.props.signOut(); }; - render() { + render(): React.Element { return ( { timer: ?IntervalID; - fetchUserData = () => { + fetchUserData: () => void = () => { this.props.getUserData(); }; @@ -28,7 +28,7 @@ export default class UserAutoUpdater extends React.Component { } } - render() { + render(): null { return null; } } diff --git a/frontend/src/core/user/components/UserAvatar.js b/frontend/src/core/user/components/UserAvatar.js index 198051832..b34fdca8f 100644 --- a/frontend/src/core/user/components/UserAvatar.js +++ b/frontend/src/core/user/components/UserAvatar.js @@ -1,5 +1,6 @@ /* @flow */ +import type { Element } from 'React'; import React from 'react'; import { Localized } from '@fluent/react'; @@ -9,7 +10,7 @@ type Props = {| imageUrl: string, |}; -export default function UserAvatar(props: Props) { +export default function UserAvatar(props: Props): Element<'div'> { const { username, title, imageUrl } = props; return ( diff --git a/frontend/src/core/user/components/UserControls.js b/frontend/src/core/user/components/UserControls.js index 144cdc6f3..68f29f583 100644 --- a/frontend/src/core/user/components/UserControls.js +++ b/frontend/src/core/user/components/UserControls.js @@ -32,20 +32,20 @@ type InternalProps = { }; export class UserControlsBase extends React.Component { - getUserData = () => { + getUserData: () => void = () => { this.props.dispatch(actions.get()); }; - markAllNotificationsAsRead = () => { + markAllNotificationsAsRead: () => void = () => { this.props.dispatch(actions.markAllNotificationsAsRead()); }; - signUserOut = () => { + signUserOut: () => void = () => { const { user } = this.props; this.props.dispatch(actions.signOut(user.signOutURL)); }; - render() { + render(): React.Element<'div'> { const { isTranslator, parameters, user, selectedEntity } = this.props; const isReadOnly = selectedEntity ? selectedEntity.readonly : true; @@ -82,4 +82,4 @@ const mapStateToProps = (state: Object): Props => { }; }; -export default connect(mapStateToProps)(UserControlsBase); +export default (connect(mapStateToProps)(UserControlsBase): any); diff --git a/frontend/src/core/user/components/UserMenu.js b/frontend/src/core/user/components/UserMenu.js index 9e907c030..74d3d95ee 100644 --- a/frontend/src/core/user/components/UserMenu.js +++ b/frontend/src/core/user/components/UserMenu.js @@ -35,7 +35,7 @@ export function UserMenu({ isReadOnly, signOut, onDiscard, -}: UserMenuProps) { +}: UserMenuProps): React.Element<'ul'> { const { locale, project, resource } = parameters; const canDownload = @@ -246,19 +246,19 @@ export default class UserMenuBase extends React.Component { }; } - toggleVisibility = () => { + toggleVisibility: () => void = () => { this.setState((state) => { return { visible: !state.visible }; }); }; - handleDiscard = () => { + handleDiscard: () => void = () => { this.setState({ visible: false, }); }; - render() { + render(): React.Element<'div'> { const { isReadOnly, isTranslator, diff --git a/frontend/src/core/user/components/UserNotification.js b/frontend/src/core/user/components/UserNotification.js index 22556dfd3..bf14305a3 100644 --- a/frontend/src/core/user/components/UserNotification.js +++ b/frontend/src/core/user/components/UserNotification.js @@ -35,7 +35,7 @@ export default class UserNotification extends React.Component { } } - render() { + render(): React.Element<'li'> { const { notification } = this.props; let className = 'user-notification'; diff --git a/frontend/src/core/user/components/UserNotificationsMenu.js b/frontend/src/core/user/components/UserNotificationsMenu.js index 05f5f4bef..ae7f59a14 100644 --- a/frontend/src/core/user/components/UserNotificationsMenu.js +++ b/frontend/src/core/user/components/UserNotificationsMenu.js @@ -29,7 +29,7 @@ type UserNotificationsMenuProps = { export function UserNotificationsMenu({ notifications, onDiscard, -}: UserNotificationsMenuProps) { +}: UserNotificationsMenuProps): React.Element<'div'> { const ref = React.useRef(null); useOnDiscard(ref, onDiscard); @@ -101,7 +101,7 @@ export default class UserNotificationsMenuBase extends React.Component< } } - handleClick = () => { + handleClick: () => void = () => { if (this.state.markAsRead) { this.setState({ markAsRead: false, @@ -112,25 +112,25 @@ export default class UserNotificationsMenuBase extends React.Component< this.markAllNotificationsAsRead(); }; - toggleVisibility = () => { + toggleVisibility: () => void = () => { this.setState((state) => { return { visible: !state.visible }; }); }; - markAllNotificationsAsRead = () => { + markAllNotificationsAsRead: () => void = () => { if (this.props.user.notifications.has_unread) { this.props.markAllNotificationsAsRead(); } }; - handleDiscard = () => { + handleDiscard: () => void = () => { this.setState({ visible: false, }); }; - render() { + render(): null | React.Element<'div'> { const { user } = this.props; if (!user || !user.isAuthenticated) { diff --git a/frontend/src/core/utils/fluent/areSupportedElements.js b/frontend/src/core/utils/fluent/areSupportedElements.js index 47796138b..0fea6432d 100644 --- a/frontend/src/core/utils/fluent/areSupportedElements.js +++ b/frontend/src/core/utils/fluent/areSupportedElements.js @@ -9,7 +9,7 @@ import isSimpleElement from './isSimpleElement'; * - simple elements or * - select expressions, whose variants are simple elements */ -export default function areSupportedElements(elements: Array) { +export default function areSupportedElements(elements: Array): boolean { return elements.every((element) => { return ( isSimpleElement(element) || diff --git a/frontend/src/core/utils/fluent/convertSyntax.js b/frontend/src/core/utils/fluent/convertSyntax.js index 0e3193059..d7db3feb7 100644 --- a/frontend/src/core/utils/fluent/convertSyntax.js +++ b/frontend/src/core/utils/fluent/convertSyntax.js @@ -128,7 +128,7 @@ export default function convertSyntax( original: string, initial: string, locale: Locale, -) { +): [FluentMessage, FluentMessage] | [string, string] { if ( fromSyntax === 'complex' && toSyntax === 'simple' && diff --git a/frontend/src/core/utils/fluent/getSimplePreview.js b/frontend/src/core/utils/fluent/getSimplePreview.js index af1b9fd99..03f4e5982 100644 --- a/frontend/src/core/utils/fluent/getSimplePreview.js +++ b/frontend/src/core/utils/fluent/getSimplePreview.js @@ -28,7 +28,7 @@ import serialize from './serialize'; * @returns {string} A simplified version of the Fluent message, or the original * content if it isn't a valid Fluent message. */ -export default function getSimplePreview(content: ?string) { +export default function getSimplePreview(content: ?string): string { if (!content) { return ''; } diff --git a/frontend/src/core/utils/fluent/isSimpleMessage.js b/frontend/src/core/utils/fluent/isSimpleMessage.js index 1e6bd443a..e66cb4152 100644 --- a/frontend/src/core/utils/fluent/isSimpleMessage.js +++ b/frontend/src/core/utils/fluent/isSimpleMessage.js @@ -8,7 +8,7 @@ import isSimpleElement from './isSimpleElement'; * A simple message has no attributes and all value * elements are simple. */ -export default function isSimpleMessage(message: Object) { +export default function isSimpleMessage(message: Object): boolean { if ( message && message.attributes && diff --git a/frontend/src/core/utils/fluent/isSimpleSingleAttributeMessage.js b/frontend/src/core/utils/fluent/isSimpleSingleAttributeMessage.js index 3a88f12c4..18d51dc42 100644 --- a/frontend/src/core/utils/fluent/isSimpleSingleAttributeMessage.js +++ b/frontend/src/core/utils/fluent/isSimpleSingleAttributeMessage.js @@ -6,7 +6,9 @@ import isSimpleElement from './isSimpleElement'; * Return true when message has no value and a single attribute with only simple * elements. */ -export default function isSimpleSingleAttributeMessage(message: Object) { +export default function isSimpleSingleAttributeMessage( + message: Object, +): boolean { if ( message && !message.value && diff --git a/frontend/src/core/utils/fluent/isSupportedMessage.js b/frontend/src/core/utils/fluent/isSupportedMessage.js index 4d25e24fc..aed4a1838 100644 --- a/frontend/src/core/utils/fluent/isSupportedMessage.js +++ b/frontend/src/core/utils/fluent/isSupportedMessage.js @@ -8,7 +8,7 @@ import areSupportedElements from './areSupportedElements'; * Message is supported if it's valid and all value elements * and all attribute elements are supported. */ -export default function isSupportedMessage(message: Object) { +export default function isSupportedMessage(message: Object): boolean { // Parse error if (message.type === 'Junk') { return false; diff --git a/frontend/src/core/utils/fluent/parser.js b/frontend/src/core/utils/fluent/parser.js index 8b4a277df..a9ab3e933 100644 --- a/frontend/src/core/utils/fluent/parser.js +++ b/frontend/src/core/utils/fluent/parser.js @@ -2,6 +2,6 @@ import { FluentParser } from '@fluent/syntax'; -const fluentParser = new FluentParser({ withSpans: false }); +const fluentParser: any = new FluentParser({ withSpans: false }); export default fluentParser; diff --git a/frontend/src/core/utils/fluent/serializer.js b/frontend/src/core/utils/fluent/serializer.js index 59b4c5838..bdfa6ff6f 100644 --- a/frontend/src/core/utils/fluent/serializer.js +++ b/frontend/src/core/utils/fluent/serializer.js @@ -2,6 +2,6 @@ import { FluentSerializer } from '@fluent/syntax'; -const fluentSerializer = new FluentSerializer(); +const fluentSerializer: any = new FluentSerializer(); export default fluentSerializer; diff --git a/frontend/src/index.js b/frontend/src/index.js index 8ac0fdf16..12606b1b0 100644 --- a/frontend/src/index.js +++ b/frontend/src/index.js @@ -31,6 +31,6 @@ ReactDOM.render( , - // $FLOW_IGNORE: we know that the 'root' element exists. + // $FlowIgnore: we know that the 'root' element exists. document.getElementById('root'), ); diff --git a/frontend/src/modules/batchactions/components/ApproveAll.js b/frontend/src/modules/batchactions/components/ApproveAll.js index 9fdd63d36..0ab67944d 100644 --- a/frontend/src/modules/batchactions/components/ApproveAll.js +++ b/frontend/src/modules/batchactions/components/ApproveAll.js @@ -14,7 +14,7 @@ type Props = {| * Renders Approve All batch action button. */ export default class ApproveAll extends React.Component { - renderDefault() { + renderDefault(): React.Element { return ( {'APPROVE ALL'} @@ -22,7 +22,7 @@ export default class ApproveAll extends React.Component { ); } - renderError() { + renderError(): React.Element { return ( {'OOPS, SOMETHING WENT WRONG'} @@ -30,7 +30,7 @@ export default class ApproveAll extends React.Component { ); } - renderInvalid() { + renderInvalid(): null | React.Element { const { response } = this.props.batchactions; if (!response) { @@ -47,7 +47,7 @@ export default class ApproveAll extends React.Component { ); } - renderSuccess() { + renderSuccess(): null | React.Element { const { response } = this.props.batchactions; if (!response) { @@ -64,7 +64,7 @@ export default class ApproveAll extends React.Component { ); } - renderTitle() { + renderTitle(): null | React.Node { const { response } = this.props.batchactions; if (response && response.action === 'approve') { @@ -86,7 +86,7 @@ export default class ApproveAll extends React.Component { } } - render() { + render(): React.Element<'button'> { return (