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

chore: ESLint setup in OpenEMR #6708

Merged
merged 20 commits into from
Aug 9, 2023

Conversation

raskolnikov-rodion
Copy link
Contributor

@raskolnikov-rodion raskolnikov-rodion commented Jul 31, 2023

Picking up from #3795.

This proposal is supposed to be a more gentle introduction of ESLint into the project. Just laying the foundation. Suggestions on how to make this setup better support the project needs are welcome!

This time, we're only extending the eslint:recommended configuration, with some of the errors turned into warnings. Notable errors include no-undef (1931 occurrences) and no-unused-vars (2405 occurrences).

The quiet option is enabled in the script because otherwise logs would be flooded by warnings. But warnings are still highlighted in IDEs, so we benefit from its checks.

In the future, we can brainstorm strategies to revert those warnings back into errors and extend other configurations, such as the Airbnb one, if desired.

After configuration was done I fixed errors in some files. Some of them I simply disabled the rule as I don't have enough context to judge what would be an appropriate fix. Please take your time and review carefully 🙂

below added by @bradymiller :
Up For Grabs demo for this PR is at (resets to the code in this PR daily at 8:30 am UTC time):
https://www.open-emr.org/wiki/index.php/Development_Demo#Gamma_-_Up_For_Grabs_Demo

package.json Outdated Show resolved Hide resolved
Copy link
Member

@adunsulag adunsulag left a comment

Choose a reason for hiding this comment

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

The minified telehealth piece needs to be compiled.

Other than that, my only concern is if you did a testing on generating a ccda document to make sure it is generating those documents properly. The linting shouldn't change the behavior, but its critical to make sure that piece continues to function if the linting slightly altered the behavior.

]
, dataKey: "meta.ccda_header.participants"
}];
var participants = (exports.participant = [
Copy link
Member

Choose a reason for hiding this comment

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

I'm unfamiliar with this syntax, there's no arrow function here, nor do I see any IFF here. Why are we wrapping this in parenthesis and have you tested the ccda generator with these changes?

Copy link
Contributor Author

@raskolnikov-rodion raskolnikov-rodion Aug 1, 2023

Choose a reason for hiding this comment

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

My Prettier plugin automatically introduced formatting changes in some of the files before I turned it off. In this case, we have a multi-line expression, so it was wrapped in parenthesis for readability purposes. It does not create any functional impact. You can verify by creating these two files:

// module.js
var data = (exports.data = [{ secretKey: '12345'}]);
console.log(`data[0].secretKey in module.js: ${data[0].secretKey}`);
// app.js
const { data: dt } = require('./module.js');
console.log(`dt[0].secretKey in app.js: ${dt[0].secretKey}`);

And then running node app.js. It should result in the same output, with or without the parenthesis in line 1 of module.js. So they are inoffensive, but I can go back to the file and remove them, if preferred.

Copy link
Member

Choose a reason for hiding this comment

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

No changes needed, thanks for the clarification.

@@ -113,7 +113,7 @@ var processOptions = function (opts) {
return {
resultType: (opts && opts.resultType && opts.resultType.toLowerCase()) || 'value',
flatten: (opts && opts.flatten) || false,
wrap: (opts && opts.hasOwnProperty('wrap')) ? opts.wrap : null,
wrap: (opts && Object.prototype.hasOwnProperty.call(opts, 'wrap')) ? opts.wrap : null,
Copy link
Member

Choose a reason for hiding this comment

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

Is the concern here with Object.prototype just to ensure that someone hasn't overridden the hasOwnProperty method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's part of the reason. The other part is because the object may not have access to this function, even though it comes from Object.prototype. This happens when you create an object using Object.create(null). Therefore, the operation is deemed unsafe and the linter throws an error.

If you'd like more details you can read here.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Thanks for the clarification.

@@ -429,49 +429,61 @@ function install(done) {
// combine dependencies and napa sources into one object
const dependencies = packages.dependencies;
for (let key in packages.napa) {
if (packages.napa.hasOwnProperty(key)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming you've tested the asset builder to verify the linter didn't break anything?

@@ -36,7 +36,7 @@ export function RegistrationChecker(scriptLocation)
return result.json();
})
.then(registrationSettings => {
if (registrationSettings && registrationSettings.hasOwnProperty('errorCode')) {
if (registrationSettings && Object.prototype.hasOwnProperty.call(registrationSettings, 'errorCode')) {
Copy link
Member

Choose a reason for hiding this comment

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

If you are going to change these values you need to rebuild the minified json in the telehealth src using

cd ./openemr/interface/modules/custom_modules/oe-module-comlink-telehealth/public/assets/js/
npm run build

@raskolnikov-rodion
Copy link
Contributor Author

The minified telehealth piece needs to be compiled.

Other than that, my only concern is if you did a testing on generating a ccda document to make sure it is generating those documents properly. The linting shouldn't change the behavior, but its critical to make sure that piece continues to function if the linting slightly altered the behavior.

Hey @adunsulag thanks for your review! I tested running the scripts contained in the README file

composer install --no-dev
npm install
npm run build
composer dump-autoload -o

and I got no errors. If I'm not mistaken this also tests the gulpfile too, right?

I'm new to the project so I don't know how to test generating a ccda document, so if you (or anyone else) can give me some pointers on how to do that I'll be able to report back and it'd be much appreaciated.

I rebuilt the telehealth file, will push it right away. Let me know if there's anything else I can do.

@stephenwaite
Copy link
Member

hi @raskolnikov-rodion , check out the Creating Random Patients Video Tutorial which will create ccdas in the process of just amazing fun along the way :)

@bradymiller
Copy link
Member

Up For Grabs demo for this PR is at (resets to the code in this PR daily at 8:30 am UTC time):
https://www.open-emr.org/wiki/index.php/Development_Demo#Gamma_-_Up_For_Grabs_Demo

@bradymiller
Copy link
Member

btw, the alpine 3.18 docker demo care coordination module is breaking since ccda build broken, so is broken on the up for grabs demo. This is not your issue @raskolnikov-rodion . Looking into it (for some reason, then alpine 3.18 demo docker is bringing in nodejs 20 instead of 18 whereas the production/flex alpine 3.18 dockers are correctly bringing in 18).

@bradymiller
Copy link
Member

Above alpine 3.18 demo is fixed (odd issue where if do not explicitly bring in nodejs package, the npm packages brings in nodejs 20 instead of nodejs 18: openemr/demo_farm_openemr@4a7ce96), so the Care Coordination module (Modules->Carecoordination in menu) now works.

@bradymiller
Copy link
Member

bradymiller commented Aug 7, 2023

hi @raskolnikov-rodion , Would be very neat to have this js lint. Would it make sense to run it like do the css lint stuff where can then run it as a github action?

@bradymiller
Copy link
Member

bradymiller commented Aug 7, 2023

Also, is this able to do autocorrect for certain rules (like the css lint and php lint do?)?

@bradymiller
Copy link
Member

One more question. Is this able to check embedded js in the .php scripts?

@raskolnikov-rodion
Copy link
Contributor Author

hi @raskolnikov-rodion , check out the Creating Random Patients Video Tutorial which will create ccdas in the process of just amazing fun along the way :)

Hi @stephenwaite , thanks for sharing the link to the tutorial, it was really helpful! I was able to follow all the steps and generate 10 random patients as described, with no apparent errors in the process 🙂

image

@raskolnikov-rodion
Copy link
Contributor Author

Hi @bradymiller , thanks for setting up the demo for the pull request!

Would it make sense to run it like do the css lint stuff where can then run it as a github action?

Yes! I just added a step for ESLint in styling.yml file, right after the stylelint check, following the same pattern. See if it makes sense and let me know if you have any suggestions.

Also, is this able to do autocorrect for certain rules (like the css lint and php lint do?)?

Yes, ESLint has a --fix option just like the other linters, which is able to fix some errors automatically. If there's interest we could even setup some hooks to run these lint fixes before commiting or pushing.

One more question. Is this able to check embedded js in the .php scripts?

I don't know, as I have never used ESLint with PHP files. But it could be worth looking into it. A quick search on npm gives this plugin, so it may be possible. I'm thinking we finish the setup for JS files in this PR, and extend it for PHP in a future PR, so we keep changes small and focused. What do you think?

@bradymiller bradymiller merged commit 7de6b61 into openemr:master Aug 9, 2023
@bradymiller
Copy link
Member

2DV(1)

@bradymiller
Copy link
Member

bradymiller commented Aug 9, 2023

@bradymiller , note to self. incorporate this (and --fix command) in the devtools in the docker dev environments

UPDATE, PRs are here:
#6719
openemr/openemr-devops#363

@raskolnikov-rodion raskolnikov-rodion deleted the chore/eslint-setup branch August 10, 2023 08:03
@adunsulag adunsulag changed the title chore(eslint): ESLint setup chore: ESLint setup in OpenEMR Nov 16, 2023
@adunsulag adunsulag added this to the 7.0.2 milestone Nov 16, 2023
@adunsulag adunsulag added the developers This issue targets an issue that is for developers/collaborators/module writers/technical users label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developers This issue targets an issue that is for developers/collaborators/module writers/technical users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants