-
Notifications
You must be signed in to change notification settings - Fork 823
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
Lint and Prettify JavaScript files #2609
Comments
@meganindya I want to work on this, Any heads up on the plan of action? :) |
We need to come to a conclusion first regarding the linting and formatting rules. We have a bigger goal of adding some kind of automated testing at both the code end (e.g. unit tests) and the application end (e.g. crashes). But, I think that needs to wait before other inconsistencies are sorted, this one being one of them. @walterbender comments? |
Is there a decent JavaScript equivalent of https://pypi.org/project/black ??? |
AFAIK Prettier is the most popular code formatter for JavaScript. There's a CLI, and extensions/plugins for modern IDE like text-editors (e.g. VS Code). And, it can work in conjunction with ESLint. I believe we need both — a code formatter for code readability, and a linter for maintaining coding standards. |
We need to tweak the prettier parameters -- I've run it over the code in the past and it made a real mess (from my Pythonic POV). |
The .prettierrc.json file contains the configurations. As such there aren't a lot of options to deal with; most of these are fairly obvious ones. However, it indeed makes tons of changes since the files we have right now aren't formatted. Which options according to you need changing? |
You've seen a lot of the same issues as me in your code clean ups: if ( is a particularly annoying one. |
If the conditions are long, they'll indeed break up like this into multiple lines, but there is an indentation. Sometimes I've observed that the indentation isn't proper, most often due to using tabs instead of spaces. Isn't
the convention if they can't fit within the line character limit? |
I'd prefer:
But ESlint is probably the first task. It'd be good to break up some of the larger files too. I started work on block.js last week -- moving a bunch of block-specific definitions to the block prototype definitions, e.g., the default pie menu values. I'd like to move all of the pie menu (controller) code out as well. This is going to take some time. (But we are in much better shape than we were a year ago.) |
I think we should totally port to ES6+ as well. |
Maybe we should add a checkbox list of files that need ES6+ porting? |
I'll go through the files and create the checklist in a new issue. I don't think even the |
Btw, we also need to change the requireJS style of importing the files. Possibly, we might actually treat most of them as completely independent modules, rather than adding everything to the global scope. |
I finished pulling the pie menus out of block.js. Still lots of opportunity for cleaning things up, but it is at least a bit more manageable. |
I predict that's pretty much shrinking the size of that file in half? I plan to work on |
Yes. Almost exactly a 50-50 split. |
Took care of a lot of var --> let clean up today. But still a little more to do: activity: 16 |
I guess we should use |
hey @meganindya I await this, so that I too can contribute to this. |
@ricknjacky see #2629. I'll just add the checklists quickly. |
Could you assign me this task |
Hey @meganindya can I make a PR to prettify all the codebase, at once, it would not induce any breaking changes, as I'm just formatting the whole code, so it might be easy to review that. What's your opinion? |
Please give a count of the number of files that'll be affected. |
For the first commit I would be pushing the changes in the js folder for the files.
That's a total of 19 files. |
Go ahead ... create a PR |
I think the lint errors are sorted out. |
I ran a statistics on the entire codebase. See results.
As far as the (JS) code is concerned, there are 103
.js
files in the/js
directory, which have a total of 82312 lines of code, 10751 blank lines, and 9796 comment lines, making a sum total of 102859 lines in the files.Here's the per file count:
There are 25 files with more than a 1000 lines of code. Evidently, dealing with so many files and these large number of lines is a challenge. Also, code has been written over a period of 6 years — mostly added on top of the existing code at each time. So, there is an insufficiency of standard in place. There exists code stretching
ES5 - ES8
.The goal, here, is to maintain a standard which could help towards better code comprehension, handling, and management. I have previously configured GitHub Actions' Super Linter with ESLint configurations. However, that currently is inactive (it ignores all warnings and errors at the moment), because it finds numerous anomalies.
On running ESLint at the time of writing this yields:
We need to improve these files gradually. I've recently added a
.prettierrc.json
configuration file to auto prettify the files. The.eslintrc.json
contains current linting configurations.I personally use Visual Studio Code - Insiders as my text-editor cum IDE with several extensions that help with writing
JavaScript
. I keep ESLint and Prettier running.The text was updated successfully, but these errors were encountered: