Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/musicutils.js: Pretiffy,linting and JSDoc Documentation #2814

Closed
wants to merge 14 commits into from

Conversation

daksh4469
Copy link
Member

Issue Reference: #2767, #2630, #2609

@daksh4469
Copy link
Member Author

I have restructured the code as there were many errors of the type: used before it is defined.
I also had to make global variables writable to fix the errors.
This was a very big file, thus has to fix errors in phases and thus there are so many commits to fixing these errors.

Please Review @meganindya.

Copy link
Member

@ricknjacky ricknjacky left a comment

Choose a reason for hiding this comment

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

cherry pick your commits, 14 commits for just one file is too much, I can see that at times you have even repeated your commit messages.

Slice them down a little bit, do a rebase.
It's easier to review if commits are clustered and not blown out of proportions into 2 digit numbers for just one file.

@daksh4469
Copy link
Member Author

Thanks for the review @ricknjacky...
I didn't know how to check for lining errors earlier, but now I know. So, this will definitely not happen again.

@ricknjacky
Copy link
Member

A paraphrase :-
Using modern, feature-rich IDEs/text-editors like Atom, Brackets, WebStorm, Sublime Text, Visual Studio Code, etc. makes life way easier. These come with a directory-tree explorer, and an integrated terminal, at the very least, while having support for plugins/extensions to expand their functionality.

Some (non-exhaustive) benefits of using these are syntax highlighting, warning/error annotations, formatting, auto-refactoring, tons of customizable keyboard shortcuts, etc.

Not a hard and fast rule, it's your call on which editor you chose to use as extensions are available in almost all of them, just a suggestion VSCode is best alternative out there.

@daksh4469
Copy link
Member Author

daksh4469 commented Feb 6, 2021

I already use VSCode and had also added the ESLint extension but didn't know why it wasn't working. I also saw that the .eslintrc file was already present in our project repo.
Still don't know why it didn't work.
Do you know how to enable this? @ricknjacky @meganindya

@meganindya
Copy link
Member

Gotta enable it ... right bottom corner

@daksh4469
Copy link
Member Author

Thanks @meganindya ..... got it.

@meganindya
Copy link
Member

This is huuuge

@daksh4469
Copy link
Member Author

daksh4469 commented Feb 6, 2021

Yeah... and that's why it has this many linting errors and so many commits.....

@meganindya
Copy link
Member

Pls run down what you've done. I can't follow.

@daksh4469
Copy link
Member Author

daksh4469 commented Feb 7, 2021

Yeah..so what I did was firstly Pretiffied the file and added JSDoc documentation and removed the debug logs. Then when I pushed these commits,
there were many errors generated (around 450 including warnings). Now, these errors were of 5 types:

  1. 'var' is not defined
  2. 'var' was used before it was defined
  3. 'var' is assigned to itself
  4. Read-only global 'var' should not be modified
  5. Unexpected lexical declaration in case block
  • Now, to resolve error 1, all such variables were defined globally: /* global var */.
  • This further generated errors of type 4, which I resolved by making them 'writable': /* global var: writable */.
  • The error of type 3 was produced just once in the case of this line: keySignature = keySignature;.
    Thus. this line was removed as it didn't affect the functionality.
  • Error 4 was most common in this file wherein a variable or a function would be defined below the part where it was being used. Here, I repositioned all the const to the top. For functions with this type of error, I moved such functions above their first occurrence of usage.
    Incorrect:
    function a(){
       b();
    }
    
    function b(){
     ......
    }
    
    After Correction:
    function b(){
       ......
    }
    
    function a(){
     b();
    }
    
    
    Now, one major problem I faced, which could not be resolved by the above method, was in the case of the functions numberToPitch(i, temperament, startPitch, offset) and getNoteFromInterval(pitch, interval) , as both these functions used the other one. This was of the type:
    function a(){
       b();
    }
    
    function b(){
       a();
    }
    
    So, to resolve this, I declared one of the functions above their usage. Example:
    let b;
    function a(){
       b();
    }
    
    
    b = function(){
       a();
    }
    
  • Error 5 was just occurring due to the absence of curly braces in the definition of a case of a switch statement.
    Incorrect:
    case:
        .........
        .........
        
    
    Correct:
    case: {
         ........
         ........
    }
    

Since there were a huge number of functions in this file, It took a lot of commits to resolve all of them.

Copy link
Member

@ricknjacky ricknjacky left a comment

Choose a reason for hiding this comment

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

you can close this PR,
I recently dealt with this file and it is linted, prettified etc (:

@daksh4469 daksh4469 closed this Mar 2, 2021
@daksh4469 daksh4469 deleted the daksh4469-main branch March 13, 2021 08:43
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