Skip to content

Conversation

@Androbin
Copy link
Contributor

Fixing #80


$(document).ajaxSend(ajaxSend);
$(document).ajaxComplete(ajaxComplete);
$(document).ajaxError(ajaxComplete);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'ajaxComplete' is not defined no-undef

/* global config, persistChoices, iso639Codes, iso639CodesInverse, populateTranslationList, showTranslateWebpageInterface */

$(document).ajaxSend(ajaxSend);
$(document).ajaxComplete(ajaxComplete);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'ajaxComplete' is not defined no-undef

/* exported SPACE_KEY_CODE, ENTER_KEY_CODE, HTTP_OK_CODE, HTTP_BAD_REQUEST_CODE, XHR_LOADING, XHR_DONE */
/* global config, persistChoices, iso639Codes, iso639CodesInverse, populateTranslationList, showTranslateWebpageInterface */

$(document).ajaxSend(ajaxSend);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'ajaxSend' is not defined no-undef

@Androbin
Copy link
Contributor Author

The CircleCI tests claim that ajaxComplete and synchronizeTextareaHeights aren't used.

/home/circleci/project/assets/js/util.js
   24:10  error  'ajaxComplete' is defined but never used                no-unused-vars
  108:10  error  'synchronizeTextareaHeights' is defined but never used  no-unused-vars

But this is not true, they are both exported and then imported by other modules.
@sushain97 Can you tell what to do?

@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
index.html.in Outdated
<script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script type="text/javascript" src="./js/init.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added separately? Pretty certain it shouldn't be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, needed a moment to figure out how things get loaded ...

};
}

// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shouldn't have been moved because compat.js only gets added for IEx-y versions but this shim is required for more than that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about having two separate levels of compat?
Something like compat-all.js and compat-ie.js?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unnecessarily complicated. Just putting it into util.js with a comment as to why seems OK to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complicated? Seems perfectly reasonable to me ...
I mean, it doesn't really belong in util.js and neither in init.js, does it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessarily complicated. If we start having multiple functions we polyfill for all browsers, then this makes sense. A file with literally one function is silly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just put all polyfills inside one file in the first place?
I mean, it's not like we'd be shipping all too much unnecessarily.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app already ships more KB of JS than it should because we don't use proper minification. There's no point in making it worse than it currently is by giving everyone polyfills they don't need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, but util.js is not ideal either. I'll move it back for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not ideal but I think it's a good compromise between simplicity and performance.

@sushain97
Copy link
Member

But this is not true, they are both exported and then imported by other modules.

I don't think they're exported from util.js?

Also, debounce should go in util.js. Rule of thumb: if it could be provided by a library instead, it probably belongs in util.

@Androbin
Copy link
Contributor Author

I don't think they're exported from util.js?

They are, by this line: assets/js/util.js#L410

Also, debounce should go in util.js.

It's only ever used in init.js and the linter would report this as well.

@sushain97
Copy link
Member

The line you mention is used by Flow, not the linter. Check out:

https://github.com/goavki/apertium-html-tools/blob/master/assets/js/util.js#L3

It's only ever used in init.js

That's fine. My argument still holds :)

@Androbin
Copy link
Contributor Author

The line you mention is used by Flow, not the linter.

Anyway, the CI tests fail if these functions are declared in util.js but not also used there.

@sushain97
Copy link
Member

Anyway, the CI tests fail if these functions are declared in util.js but not also used there.

No, they don't. Use the export comments correctly.

@Androbin
Copy link
Contributor Author

Okay, now I got it. Will update the imports.

@@ -1,14 +1,13 @@
/* @flow */
/* exported sendEvent, modeEnabled, filterLangList, getURLParam, onlyUnique, isSubset, safeRetrieve, callApy, apyRequestTimeout, isURL */
/* exported ajaxComplete, sendEvent, modeEnabled, filterLangList, getURLParam, onlyUnique, isSubset, synchronizeTextareaHeights, callApy, apyRequestTimeout, isURL */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 2 exceeds the maximum line length of 140 max-len

@Androbin
Copy link
Contributor Author

No errors in console when running locally.

@Androbin
Copy link
Contributor Author

I know @sushain97 thinks of having separate compat-all.js and compat-ie.js as being unnecessarily complicated. But considering that the code from compat.all.js doesn't belong in util.js or else, this should be justified.

@sushain97
Copy link
Member

I don't agree :) KISS.

Like I said in #80, this isn't complete until the build system prevents cyclic dependencies from recurring (ideally by running Flow).

@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
Makefile Outdated
debug: debugjs debugcss build/index.debug.html build/not-found.html fonts build/js/compat.js build/js/jquery.min.js build/js/bootstrap.min.js build/sitemap.xml build/strings/locales.json build/index.$(DEFAULT_LOCALE).html build/strings/$(DEFAULT_LOCALE).json images

prod: js css html fonts build/sitemap.xml build/manifest.json build/strings/locales.json localhtml images
prod: js flow css html fonts build/sitemap.xml build/manifest.json build/strings/locales.json localhtml images
Copy link
Member

@sushain97 sushain97 Dec 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this adds flow to the dependencies for building this project. We can't add any dependencies (for users).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we run make flow directly as part of CircleCI?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah :) before the make -j8 because that sometimes fails due to APy being down (hence the || true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I might open another ticket for typing html-tools with flow if you're interested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, put together the specs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look up the syntax and stuff while you are writing it up.

index.html.in Outdated
</script>

<!--[if lt IE 9]> <script type="text/javascript" src="./js/compat.js"></script> <![endif]-->
<!--[if lt IE 9]> <script type="text/javascript" src="./js/compat-ie.js"></script> <![endif]-->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed a spot?

### Clean ###
clean:
rm -rf build/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single trailing line with some whitespace on it.
Did it serve any purpose?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it should have been a single trailing line without whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other files in the repo don't have trailing newlines either. Do we want a trailing newline here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I thought they all did. They all should! Don't worry about the other files but let's retain one here.

Makefile Outdated
flow: build/js/all.js
grep -Ev '/\*:: *(ex|im)port ' $< | flow check-contents
flow: $(JSFILES)
grep -Ev '/\*:: *(ex|im)port ' $< | npm run flow check-contents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the grep be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought of that, too. This grep strips all lines containing the regex. When the comment has a line break, it keeps everything but the first line (not intended).

I don't know why this was introduced in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see an obvious reason to have it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the comment has a line break, it keeps everything but the first line (not intended).

Yeah this seems extra bad. Probably breaks the JS syntax wise?

I don't know why this was introduced in the first place.

I think Flow uses the export lines and they would have worked except for the cylic dependencies. So, @unhammer just effectively commented them out before passing to flow in anticipation of eventually fixing the cyclic dependencies and making it so flow would actually use the export/imports. So, it should be removable now.

@Androbin
Copy link
Contributor Author

When running flow via npm as part of make, it produces the following error:

npm ERR! path /home/circleci/project/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/circleci/project/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

@sushain97
Copy link
Member

When running flow via npm as part of make, it produces the following error:

I believe using flow instead of npm run flow fixes that (as it used to be in the Makefile).

@Androbin
Copy link
Contributor Author

The flow command is running now. But it produces errors due to not being able to find referenced modules.

@sushain97 sushain97 reopened this Dec 16, 2017
@sushain97
Copy link
Member

Oops, clicked the wrong button.

@Androbin
Copy link
Contributor Author

Maybe https://github.com/goavki/apertium-html-tools/blob/master/.flowconfig?

We need an extra file flow-typed/apertium.js which we reference by adding a [libs] path to .flowconfig.

@@ -0,0 +1,35 @@
declare module 'util' {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: Unexpected token module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sushain97 Got any idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hound's configuration allows for excluding files, I believe that would work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this triggered by jshint or eslint ? Shall I exclude this from both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jshint isn't being used for this project...

@sushain97
Copy link
Member

Lol, I don't know why the build is passing. It certainly shouldn't be (see below).

This is a lot of modifications so I don't think I expect you to fix them all. As long as you get flow actually running, it's fine.

I don't think apertium.js is needed in light of the following command running fine.

[573:569 - 0:636] 02:27:38 [[email protected]:o +1] ~/Documents/apertium-html-tools
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

[573:569 - 0:637] 02:27:39 [[email protected]:o +1] ~/Documents/apertium-html-tools
$ flow
Error: assets/js/translator.js:98
 98:                 if(ev.keyCode === ENTER_KEY_CODE && isURL($('input#webpage').val())) {
                                       ^^^^^^^^^^^^^^ ENTER_KEY_CODE. Could not resolve name

Error: assets/js/translator.js:315
315:             if(lastPunct && (event.keyCode === SPACE_KEY_CODE || event.keyCode === ENTER_KEY_CODE)) {
                                                    ^^^^^^^^^^^^^^ SPACE_KEY_CODE. Could not resolve name

Error: assets/js/translator.js:315
315:             if(lastPunct && (event.keyCode === SPACE_KEY_CODE || event.keyCode === ENTER_KEY_CODE)) {
                                                                                        ^^^^^^^^^^^^^^ ENTER_KEY_CODE. Could not resolve name

Error: assets/js/translator.js:414
414:         srcLangs = filterLangList(srcLangs.filter(onlyUnique));
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call of `filterLangList`. Called with too few arguments
  280: function filterLangList(langs/*: Array<string>*/, _filterFn/*: (lang: string) => bool*/) {
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function expects more arguments. See: assets/js/util.js:280

Error: assets/js/translator.js:415
415:         dstLangs = filterLangList(dstLangs.filter(onlyUnique));
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call of `filterLangList`. Called with too few arguments
  280: function filterLangList(langs/*: Array<string>*/, _filterFn/*: (lang: string) => bool*/) {
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function expects more arguments. See: assets/js/util.js:280

Error: assets/js/translator.js:487
487:             ' - ' + getDynamicLocalization('detected')
                         ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:595
595:         var sortLocale = (locale && locale in iso639Codes) ? iso639Codes[locale] : locale;
                               ^^^^^^ locale. Could not resolve name

Error: assets/js/translator.js:595
595:         var sortLocale = (locale && locale in iso639Codes) ? iso639Codes[locale] : locale;
                                                   ^^^^^^^^^^^ iso639Codes. Could not resolve name

Error: assets/js/translator.js:595
595:         var sortLocale = (locale && locale in iso639Codes) ? iso639Codes[locale] : locale;
                                                                  ^^^^^^^^^^^ iso639Codes. Could not resolve name

Error: assets/js/translator.js:607
607:             var aPossible = pairs[curSrcLang] && pairs[curSrcLang].indexOf(a) !== -1,
                                 ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
607:             var aPossible = pairs[curSrcLang] && pairs[curSrcLang].indexOf(a) !== -1,
                                       ^^^^^^^^^^ undefined

Error: assets/js/translator.js:608
608:                 bPossible = pairs[curSrcLang] && pairs[curSrcLang].indexOf(b) !== -1;
                                 ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
608:                 bPossible = pairs[curSrcLang] && pairs[curSrcLang].indexOf(b) !== -1;
                                       ^^^^^^^^^^ undefined

Error: assets/js/translator.js:643
643:         if(data.responseStatus === HTTP_OK_CODE) {
                                        ^^^^^^^^^^^^ HTTP_OK_CODE. Could not resolve name

Error: assets/js/translator.js:659
659:         if(pairs[curSrcLang] && pairs[curSrcLang].indexOf(curDstLang) !== -1) {
                ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
659:         if(pairs[curSrcLang] && pairs[curSrcLang].indexOf(curDstLang) !== -1) {
                      ^^^^^^^^^^ undefined

Error: assets/js/translator.js:660
660:             sendEvent('translator', 'translate', curSrcLang + '-' + curDstLang, originalText.length);
                 ^^^^^^^^^ sendEvent. Could not resolve name

Error: assets/js/translator.js:660
660:             sendEvent('translator', 'translate', curSrcLang + '-' + curDstLang, originalText.length);
                                                      ^^^^^^^^^^ undefined. This type cannot be added to
660:             sendEvent('translator', 'translate', curSrcLang + '-' + curDstLang, originalText.length);
                                                                   ^^^ string

Error: assets/js/translator.js:670
670:                 request = {'langpairs': curSrcLang + '|' + curDstLang};
                                             ^^^^^^^^^^ undefined. This type cannot be added to
670:                 request = {'langpairs': curSrcLang + '|' + curDstLang};
                                                          ^^^ string

Error: assets/js/translator.js:674
674:                 request = {'langpair': curSrcLang + '|' + curDstLang};
                                            ^^^^^^^^^^ undefined. This type cannot be added to
674:                 request = {'langpair': curSrcLang + '|' + curDstLang};
                                                         ^^^ string

Error: assets/js/translator.js:677
677:             request.q = originalText; // eslint-disable-line id-length
                         ^ property `q`. Property not found in
677:             request.q = originalText; // eslint-disable-line id-length
                 ^^^^^^^ object literal

Error: assets/js/translator.js:678
678:             request.markUnknown = $('#markUnknown').prop('checked') ? 'yes' : 'no';
                         ^^^^^^^^^^^ property `markUnknown`. Property not found in
678:             request.markUnknown = $('#markUnknown').prop('checked') ? 'yes' : 'no';
                 ^^^^^^^ object literal

Error: assets/js/translator.js:696
696:     var validPair = pairs[curSrcLang] && pairs[curSrcLang].indexOf(curDstLang) !== -1;
                         ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
696:     var validPair = pairs[curSrcLang] && pairs[curSrcLang].indexOf(curDstLang) !== -1;
                               ^^^^^^^^^^ undefined

Error: assets/js/translator.js:705
705:             docTranslateError(getDynamicLocalization('File_Too_Large'), 'File_Too_Large');
                                   ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:728
728:                 var xhr = new XMLHttpRequest({mozSystem: true});
                                                  ^^^^^^^^^^^^^^^^^ unused function argument
       v--------------------------
  154: declare class EventTarget {
  155:   addEventListener(type: MouseEventTypes, listener: MouseEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
  156:   addEventListener(type: FocusEventTypes, listener: FocusEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
  ...:
  201: }
       ^ default constructor expects no arguments. See lib: /private/tmp/flow/flowlib_2ede7e71/dom.js:154

Error: assets/js/translator.js:729
729:                 xhr.addEventListener('progress', updateProgressBar, false);
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call of method `addEventListener`. Could not decide which case to select
729:                 xhr.addEventListener('progress', updateProgressBar, false);
                     ^^^^^^^^^^^^^^^^^^^^ function type
  Case 6 may work:
  160:   addEventListener(type: ProgressEventTypes, listener: ProgressEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See lib: /private/tmp/flow/flowlib_2ede7e71/dom.js:160
  But if it doesn't, case 9 looks promising too:
  163:   addEventListener(type: string, listener: EventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See lib: /private/tmp/flow/flowlib_2ede7e71/dom.js:163
  Please provide additional annotation(s) to determine whether case 6 works (or consider merging it with case 9):
  806:     function updateProgressBar(ev) {
                                      ^^ ev

Error: assets/js/translator.js:735
735:                     if(this.readyState === XHR_LOADING) {
                                                ^^^^^^^^^^^ XHR_LOADING. Could not resolve name

Error: assets/js/translator.js:741
741:                     else if(this.readyState === XHR_DONE && xhr.status === HTTP_OK_CODE) {
                                                     ^^^^^^^^ XHR_DONE. Could not resolve name

Error: assets/js/translator.js:741
741:                     else if(this.readyState === XHR_DONE && xhr.status === HTTP_OK_CODE) {
                                                                                ^^^^^^^^^^^^ HTTP_OK_CODE. Could not resolve name

Error: assets/js/translator.js:761
761:                                             window.location.href = reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
                                                                                      ^^^^^^^ property `replace`. Property not found in
761:                                             window.location.href = reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
                                                                        ^^^^^^^^^^^^^ ArrayBuffer

Error: assets/js/translator.js:772
772:                             $('span#fileDownloadText').text(getDynamicLocalization('Download_File').replace('{{fileName}}', fileName));
                                                                 ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:777
777:                     else if(this.status >= HTTP_BAD_REQUEST_CODE) {
                                                ^^^^^^^^^^^^^^^^^^^^^ HTTP_BAD_REQUEST_CODE. Could not resolve name

Error: assets/js/translator.js:778
778:                         docTranslateError(getDynamicLocalization('Not_Available'));
                                               ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:782
782:                     docTranslateError(getDynamicLocalization('Not_Available'));
                                           ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:790
790:                 fileData.append('langpair', curSrcLang + '|' + curDstLang);
                                                 ^^^^^^^^^^ undefined. This type cannot be added to
790:                 fileData.append('langpair', curSrcLang + '|' + curDstLang);
                                                              ^^^ string

Error: assets/js/translator.js:794
794:                 sendEvent('translator', 'translateDoc', curSrcLang + '-' + curDstLang, file.size);
                     ^^^^^^^^^ sendEvent. Could not resolve name

Error: assets/js/translator.js:794
794:                 sendEvent('translator', 'translateDoc', curSrcLang + '-' + curDstLang, file.size);
                                                             ^^^^^^^^^^ undefined. This type cannot be added to
794:                 sendEvent('translator', 'translateDoc', curSrcLang + '-' + curDstLang, file.size);
                                                                          ^^^ string

Error: assets/js/translator.js:798
798:                 docTranslateError(getDynamicLocalization('Format_Not_Supported'), 'Format_Not_Supported');
                                       ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:803
803:         docTranslateError(getDynamicLocalization('Not_Available'));
                               ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:838
838:                 .text(getDynamicLocalization('Not_Available'))
                           ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:858
858:         if(data.responseStatus === HTTP_OK_CODE && translatedHtml) {
                                        ^^^^^^^^^^^^ HTTP_OK_CODE. Could not resolve name

Error: assets/js/translator.js:910
910:     if(pairs[curSrcLang] && pairs[curSrcLang].indexOf(curDstLang) !== -1) {
            ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
910:     if(pairs[curSrcLang] && pairs[curSrcLang].indexOf(curDstLang) !== -1) {
                  ^^^^^^^^^^ undefined

Error: assets/js/translator.js:911
911:         sendEvent('translator', 'translateWebpage', curSrcLang + '-' + curDstLang);
             ^^^^^^^^^ sendEvent. Could not resolve name

Error: assets/js/translator.js:911
911:         sendEvent('translator', 'translateWebpage', curSrcLang + '-' + curDstLang);
                                                         ^^^^^^^^^^ undefined. This type cannot be added to
911:         sendEvent('translator', 'translateWebpage', curSrcLang + '-' + curDstLang);
                                                                      ^^^ string

Error: assets/js/translator.js:921
921:                 'langpair': curSrcLang + '|' + curDstLang,
                                 ^^^^^^^^^^ undefined. This type cannot be added to
921:                 'langpair': curSrcLang + '|' + curDstLang,
                                              ^^^ string

Error: assets/js/translator.js:1021
1021:         .val(getDynamicLocalization('Not_Available'))
                   ^^^^^^^^^^^^^^^^^^^^^^ getDynamicLocalization. Could not resolve name

Error: assets/js/translator.js:1031
1031:         if(!pairs[curSrcLang] || pairs[curSrcLang].indexOf($(this).attr('data-code')) === -1) {
                  ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
1031:         if(!pairs[curSrcLang] || pairs[curSrcLang].indexOf($(this).attr('data-code')) === -1) {
                        ^^^^^^^^^^ undefined

Error: assets/js/translator.js:1036
1036:         if(!pairs[curSrcLang] || pairs[curSrcLang].indexOf($(this).attr('data-code')) === -1) {
                  ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
1036:         if(!pairs[curSrcLang] || pairs[curSrcLang].indexOf($(this).attr('data-code')) === -1) {
                        ^^^^^^^^^^ undefined

Error: assets/js/translator.js:1042
1042:         $(element).prop('disabled', !pairs[curSrcLang] || pairs[curSrcLang].indexOf($(element).val()) === -1);
                                           ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
1042:         $(element).prop('disabled', !pairs[curSrcLang] || pairs[curSrcLang].indexOf($(element).val()) === -1);
                                                 ^^^^^^^^^^ undefined

Error: assets/js/translator.js:1047
1047:     if(pairs[curSrcLang] && pairs[curSrcLang].indexOf(curDstLang) === -1) {
             ^^^^^^^^^^^^^^^^^ computed property. Computed property cannot be accessed with
1047:     if(pairs[curSrcLang] && pairs[curSrcLang].indexOf(curDstLang) === -1) {
                   ^^^^^^^^^^ undefined

Error: assets/js/translator.js:1056
1056:             newDstLang = filterLangList(pairs[curSrcLang])[0];
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call of `filterLangList`. Called with too few arguments
  280: function filterLangList(langs/*: Array<string>*/, _filterFn/*: (lang: string) => bool*/) {
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function expects more arguments. See: assets/js/util.js:280

Error: assets/js/translator.js:1077
1077: /*:: import {synchronizeTextareaHeights, modeEnabled, ajaxSend, ajaxComplete, filterLangList, onlyUnique, getLangByCode,
                                                                                                                ^^^^^^^^^^^^^ Named import from module `./util.js`. This module has no named export called `getLangByCode`.

Error: assets/js/translator.js:1081
1081: /*:: import {readCache,cache} from "./cache.js" */
                                         ^^^^^^^^^^^^ ./cache.js. Required module not found


... 72 more errors (only 50 out of 122 errors displayed)
To see all errors, re-run Flow with --show-all-errors

@Androbin
Copy link
Contributor Author

This is a lot of modifications so I don't think I expect you to fix them all.

But the errors are gone as of adding this file.

@sushain97
Copy link
Member

sushain97 commented Dec 16, 2017

But the errors are gone as of adding this file.

It has to be a false negative. A lot of these errors are valid ones. I also don't know how flow check-contents differs from flow check or if the way you're using it is even actually running flow.

@Androbin
Copy link
Contributor Author

#!/bin/bash -eo pipefail
make flow
test -d build/js || mkdir -p build/js
touch build/js/.d
./tools/read-conf.py -c config.conf js > build/js/config.js
echo "config.LOCALES = `cat assets/strings/locales.json`;" > build/js/locales.js
printf "config.PAIRS = " > build/js/listrequests.js
curl -Ss "https://www.apertium.org/apy/list?q=pairs" >> build/js/listrequests.js || ( rm build/js/listrequests.js; false; )
echo ";" >> build/js/listrequests.js
printf "config.GENERATORS = " >> build/js/listrequests.js
curl -Ss "https://www.apertium.org/apy/list?q=generators" >> build/js/listrequests.js || ( rm build/js/listrequests.js; false; )
echo ";" >> build/js/listrequests.js
printf "config.ANALYZERS = " >> build/js/listrequests.js
curl -Ss "https://www.apertium.org/apy/list?q=analyzers" >> build/js/listrequests.js || ( rm build/js/listrequests.js; false; )
echo ";" >> build/js/listrequests.js
printf "config.TAGGERS = " >> build/js/listrequests.js
curl -Ss "https://www.apertium.org/apy/list?q=taggers" >> build/js/listrequests.js || ( rm build/js/listrequests.js; false; )
echo ";" >> build/js/listrequests.js
for file in assets/js/strict.js; do \
	< $file flow check-contents; \
done
Launching Flow server for /home/circleci/project
Spawned flow server (pid=655)
Logs will go to /tmp/flow/zShomezScirclecizSproject.log
Monitor logs will go to /tmp/flow/zShomezScirclecizSproject.monitor_log
No errors!

@sushain97
Copy link
Member

See my previous comment. Adding that file should not get rid of all those errors.

@Androbin
Copy link
Contributor Author

This was just due to Flow not being able to resolve those references (across modules).

@sushain97
Copy link
Member

No.

The exports and imports are not correct. e.g. ENTER_KEY_CODE is not imported in translator.js.

@Androbin
Copy link
Contributor Author

The exports and imports are not correct. e.g. ENTER_KEY_CODE is not imported in translator.js.

You mean, in addition to /* global ENTER_KEY_CODE */ we also need /*:: import {ENTER_KEY_CODE} from "./util.js" */ ?

@sushain97
Copy link
Member

Yes. In fact, there are over 20 other similar errors. I don't think the way you changed the Makefile is actually running flow anymore.

@sushain97
Copy link
Member

These changes cut down the # of errors to 41 but there are still many more:

diff --git a/.flowconfig b/.flowconfig
index 28eb815..d5f5265 100644
--- a/.flowconfig
+++ b/.flowconfig
@@ -1,5 +1,5 @@
 [ignore]
-build/
+.*/build/.*

 [include]

diff --git a/assets/js/translator.js b/assets/js/translator.js
index d137f30..9872b7d 100644
--- a/assets/js/translator.js
+++ b/assets/js/translator.js
@@ -24,7 +24,7 @@ var PUNCTUATION_KEY_CODES = [46, 33, 58, 63, 47, 45, 190, 171, 49]; // eslint-di
 /* global config, modeEnabled, synchronizeTextareaHeights, persistChoices, getLangByCode, sendEvent, onlyUnique, restoreChoices
     getDynamicLocalization, locale, ajaxSend, ajaxComplete, localizeInterface, filterLangList, cache, readCache, iso639Codes,
     callApy, apyRequestTimeout, isURL */
-/* global SPACE_KEY_CODE, ENTER_KEY_CODE, HTTP_OK_CODE, XHR_LOADING, XHR_DONE, HTTP_OK_CODE, HTTP_BAD_REQUEST_CODE */
+/* global SPACE_KEY_CODE, ENTER_KEY_CODE, HTTP_OK_CODE, XHR_LOADING, XHR_DONE, HTTP_BAD_REQUEST_CODE */

 if(modeEnabled('translation')) {
     $(document).ready(function () {
@@ -1074,10 +1074,11 @@ function autoSelectDstLang() {
     }
 }

-/*:: import {synchronizeTextareaHeights, modeEnabled, ajaxSend, ajaxComplete, filterLangList, onlyUnique, getLangByCode,
-    callApy, apyRequestTimeout} from "./util.js" */
+/*:: export {populateTranslationList, showTranslateWebpageInterface} */
+/*:: import {synchronizeTextareaHeights, modeEnabled, ajaxSend, ajaxComplete, filterLangList, onlyUnique, sendEvent, XHR_DONE,
+    callApy, apyRequestTimeout, ENTER_KEY_CODE, SPACE_KEY_CODE, HTTP_OK_CODE, HTTP_BAD_REQUEST_CODE, XHR_LOADING} from "./util.js" */
 /*:: import {persistChoices, restoreChoices} from "./persistence.js" */
-/*:: import localizeInterface from "./localization.js" */
-/*:: import {readCache,cache} from "./cache.js" */
+/*:: import {localizeInterface, getLangByCode, getDynamicLocalization} from "./localization.js" */
+/*:: import {readCache, cache} from "./persistence.js" */
 /*:: import {config} from "./config.js" */
 /*:: import {isURL} from "./util.js" */
diff --git a/assets/js/util.js b/assets/js/util.js
index af13560..b914d87 100644
--- a/assets/js/util.js
+++ b/assets/js/util.js
@@ -304,7 +304,7 @@ function getURLParam(name) {

 /* eslint-disable */
 // From: http://stackoverflow.com/a/19696443/1266600 (source: AOSP)
-function isURL(text) {
+function isURL(text/*: string*/) {
     var re = /^((?:(http|https):\/\/(?:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,64}(?:\:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,25})?\@)?)?((?:(?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}\.)+(?:(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])|(?:biz|b[abdefghijmnorstvwyz])|(?:cat|com|coop|c[acdfghiklmnoruvxyz])|d[ejkmoz]|(?:edu|e[cegrstu])|f[ijkmor]|(?:gov|g[abdefghilmnpqrstuwy])|h[kmnrtu]|(?:info|int|i[delmnoqrst])|(?:jobs|j[emop])|k[eghimnrwyz]|l[abcikrstuvy]|(?:mil|mobi|museum|m[acdghklmnopqrstuvwxyz])|(?:name|net|n[acefgilopruz])|(?:org|om)|(?:pro|p[aefghklmnrstwy])|qa|r[eouw]|s[abcdeghijklmnortuvyz]|(?:tel|travel|t[cdfghjklmnoprtvwz])|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]))|(?:(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])))(?:\:\d{1,5})?)(\/(?:(?:[a-zA-Z0-9\;\/\?\:\@\&\=\#\~\-\.\+\!\*\'\(\)\,\_])|(?:\%[a-fA-F0-9]{2}))*)?(?:\s*$)/i;
     return text.search(re) === 0;
 }
@@ -408,7 +408,7 @@ function displayInstallationNotification() {
 }

 /*:: export {synchronizeTextareaHeights, modeEnabled, ajaxSend, ajaxComplete, filterLangList, onlyUnique, callApy,
-    SPACE_KEY_CODE, ENTER_KEY_CODE, HTTP_OK_CODE, HTTP_BAD_REQUEST_CODE, XHR_LOADING, XHR_DONE, apyRequestTimeout} */
+    SPACE_KEY_CODE, ENTER_KEY_CODE, HTTP_OK_CODE, HTTP_BAD_REQUEST_CODE, XHR_LOADING, XHR_DONE, apyRequestTimeout, isURL, sendEvent} */
 /*:: import {config} from "./config.js" */
 /*:: import {persistChoices} from "./persistence.js" */
 /*:: import {iso639Codes, iso639CodesInverse} from "./localization.js" */

@Androbin
Copy link
Contributor Author

I can fix them, no problem.

@Androbin
Copy link
Contributor Author

Imports/Exports were no problem.
But lots of errors are about (possibly) undefined values.
This could be a bit more tricky to fix.

@sushain97
Copy link
Member

sushain97 commented Dec 16, 2017

But lots of errors are about (possibly) undefined values. This could be a bit more tricky to fix.

Don't worry about it. I have a plan to handle those (i.e. fix some myself and make a task/issue for the rest).

This task will be complete if you clean up the extra files and stuff in this PR.

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup


# Build project
- run: cp config.conf.example config.conf
- run: flow check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest moving this up to the block above now.

.eslintignore Outdated
@@ -0,0 +1 @@
flow-typed/*.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be safe to kill this folder and files in it now.

Makefile Outdated
# grab the bin from https://github.com/facebook/flow/releases
flow: build/js/all.js
grep -Ev '/\*:: *(ex|im)port ' $< | flow check-contents
flow: $(JSFILES)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this make command can be removed now.

@apertium apertium deleted a comment from houndci-bot Dec 16, 2017
getDynamicLocalization, locale, ajaxSend, ajaxComplete, localizeInterface, filterLangList, cache, readCache, iso639Codes,
callApy, apyRequestTimeout, isURL */
/* global SPACE_KEY_CODE, ENTER_KEY_CODE, HTTP_OK_CODE, XHR_LOADING, XHR_DONE, HTTP_OK_CODE, HTTP_BAD_REQUEST_CODE */
callApy, apyRequestTimeout, isURL, iso639Codes, iso639CodesInverse */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'iso639CodesInverse' is defined but never used no-unused-vars

@sushain97 sushain97 changed the base branch from master to issue-80-flow December 16, 2017 20:39
@sushain97 sushain97 merged commit 425c582 into apertium:issue-80-flow Dec 16, 2017
@Androbin Androbin deleted the detangled branch December 16, 2017 20:40
sushain97 added a commit that referenced this pull request Dec 16, 2017
* [WIP] Disentangle JS modules (#225)

* Disentangle JS modules

* Fix imports

* Use flow on individual files

* Declare modules to Flow

* Run Flow directly

* Cleanup

* Fix some import/export issues

* Make the build work

* Tweak flow decl

* Move around the config decl to make build work
@sushain97
Copy link
Member

@Androbin if you'd like to take fixing up the types as a task, you can do so under the auspices of #228. My commit to master also contains some help with syntax (e.g. for generics) and model for how the comments should be formatted.

For purposes of task completion, I deem sufficient changes to be the lower of 20% overall improvement or 350 LOC modified (i.e. you can do either).

sushain97 pushed a commit that referenced this pull request Jan 4, 2018
* Add file download workaround for Safari (fixes #97)

* Changed Download_Browser_Warning

* Added workaround for Safari

Fixed translator.js

Fixed wierd bugs that I have no idea how I had made.

* Moved .fadeIn out of conditional block

* Added comments to increase code readability

* Allow right-click to download even if workaraound is used

* Revert string changes

* Fix multiple download in Safari >10

Fix es-lint

Fix es-lint

* Removed Download_Browser_Warning

* Change way we check for Safari version

Instead of looking at specific version (10, 11) look for one digit version (9, 8 and earlier)

* Remove unused global varaibles

* Extended comment about Safari workaround

* Run cleanup

* Fixes #201 (Chrome audit improvements)

* Improved Chrome audit performance

* Update Makefile

* Fixed formatting errors

* Fixed more formatting errors

* Revised "start_url"

* Removed sw.js

* Removed script for registering service worker

* Revised makefile, manifest.json, and index.html

* Improved Chrome audit performance further

* Improved audit performance further

* Fixed errors

* fixed houndci error

* Fixed final errors

* Added whitespace

* Fix <html> localisation

* Disentangle JS modules and fix Flow (fixes #80)

* [WIP] Disentangle JS modules (#225)

* Disentangle JS modules

* Fix imports

* Use flow on individual files

* Declare modules to Flow

* Run Flow directly

* Cleanup

* Fix some import/export issues

* Make the build work

* Tweak flow decl

* Move around the config decl to make build work

* Delete extra line

* Fix make debug (fixes #220)

* Improvements to Flow coverage

* Better flow coverage

* Doesn't look like the stubs actually belong to jQuery 3 so I'm reverting these changes

* Remove unnecessary var

* This name makes a lot more sense

* Remove unnecessary type annotations (clutter code & are obvious e.g. string literals)

* More unnecessary type annotations

* Remove more unnecessary annotations

* Prefer literal union type

* Add a type and remove one

* More fixes

* Fix persist choices

* Remove more redundant annotations

* Remove more unnecessary annotations

* Switch to Array<...> shortform

* Undo one of my 'fixes'

* Final flow fix

* Convert Object to {} shorthand

* Remove a couple more unnecessary annotations

* Some final cleanup

* Implement requested changes

* Add/Remove/Fix types

* Adapt config types

* Un-Flow strict.js

* Allow subtitle to be null

* Final tweaks

* Simplify progress bar update

* Split CSS into multiple files and improve organization (fixes #212)

* Split CSS into multiple files

* Better organization

* Minor tweaks

* Bring all the coverage over 90%

* Fix buggy UI with detect-language (fixes #236)

* Refactor repeated code into a function

* Fix the locale selector I probably broke

* Show translation not available less often

* Remove a warn that gets triggered all the time

* More generic port configuration with Docker

* Less awkward input label placement

* Slightly more sane language sorting with variants

* Significantly more sane translation language column computation

* Fix typo

* Store docker pair data in persistent volume and add update all script

* Include language modules download in deploy script (fixes #244)

* Minify JS and CSS (towards #130)

* Minify all.js and all.css

* Make minification fail gracefully

* Update README section on compression

* Use command line interfaces

* Update Dockerfile

* Update README.md

* Update README.md

* Fix dockerfiles

* Fix debug HTML

* Fetch monolingual modules before pairs in deploy-all script

* Merge handleTranslateSuccessResponse

* Update imports/exports

* Add JQuery modal/tooltip stubs

* Add config.SUGGESTIONS stubs

* Fix remaining Flow issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants