action #91638
closed
Ensure standard javascript code
Added by livdywan over 3 years ago.
Updated over 3 years ago.
Category:
Feature requests
Description
Motivation¶
Our currenty Javascript linter js-beautify lives up to its name, the code looks a bit nicer but it doesn't cover much. It'd be desirable to flag more logical aspects like uses of const and not just aesthestics of the code.
Acceptance criteria¶
- AC1: semistandard and more common javascript code styles are ensured
Suggestions¶
- Subject changed from Consider Standard or to Ensure standard javascript code
- Description updated (diff)
- Status changed from New to Workable
- Priority changed from Normal to Low
- Target version changed from future to Ready
I wouldn't mind taking care of this. Unless someone else would like to use the opportunity to learn more about JavaScript dev tools. My recommendation would be:
- Put a
package.json
and eslint.json
into the repo that contain all the deps and settings (semi-standard + extended max line length)
- Create a
tools/eslint
script that will check if node is installed (give a useful message otherwise), update deps with npm in the local node_modules
, and then run eslint --fix over our JavaScript files (make sure it complains about violations it can't fix)
- Add a GitHub Action that runs eslint over our JavaScript files and annotates pull requests with rule violations
- Make sure all the temporary npm files are added to
.gitignore
- Update relevant documentation
Doing it this way also means that clever editors such as VSCode can use the settings to lint your code as you write it.
Just one thing comes to mind that you didn't mention. Make sure that we have a makefile target that does the linting and which is used in our CI - I don't care that much about installing npm and such here, but it should be trivial to reproduce whatever we do in CI without looking up command lines to execute. This has been a source of problems before. From a glance the mentioned GHA runs 3 different commands.
cdywan wrote:
Just one thing comes to mind that you didn't mention. Make sure that we have a makefile target that does the linting and which is used in our CI - I don't care that much about installing npm and such here, but it should be trivial to reproduce whatever we do in CI without looking up command lines to execute. This has been a source of problems before. From a glance the mentioned GHA runs 3 different commands.
Actually i think a separate GitHub Action would be better, since those can annotate the pull request diff with eslint rule violations.
I'll make a proof of concept to show GitHub PR annotations.
The PR also demonstrates how eslint is about more than just formatting, it's a proper linter that can find many other issues for us.
I think one thing the eslint results have shown is that our JavaScript code is in a very poor state. Merely running a prettifier over it is not gonna solve that, we also need to make a decision how we want to organise it (ESM etc.).
- Target version changed from Ready to future
- Status changed from Workable to In Progress
- Assignee set to kraih
- Status changed from In Progress to Feedback
The PR has actually been merged, so we now have ESLint (with only one rule activated) and the Prettier formatting standard. Rule violations will result in PR annotations on GitHub, and ESLint extensions can be used with IDEs. That should resolve this ticket. Next steps will be to enable more strict rules in ESLint and to fix our JavaScript code.
This commit shows one ESLint rule being enabled as an error. More can follow the same way, or be enabled with a category such as eslint:recommended
.
kraih wrote:
[…] That should resolve this ticket.
ok, but why did you not "resolve" it then? Do you think we need more rules enforced?
- Status changed from Feedback to Resolved
okurz wrote:
kraih wrote:
[…] That should resolve this ticket.
ok, but why did you not "resolve" it then? Do you think we need more rules enforced?
Fair point, if i leave this unresolved it could stay open forever since there will always be new ESLint rules for us to enable in the future.
kraih wrote:
Fair point, if i leave this unresolved it could stay open forever since there will always be new ESLint rules for us to enable in the future.
makes sense, thanks. We can update/add rules over time.
- Target version changed from future to Ready
Also available in: Atom
PDF