-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
chore: ESLint setup in OpenEMR #6708
Conversation
There was a problem hiding this 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 = [ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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')) { |
There was a problem hiding this comment.
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
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. |
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 :) |
Up For Grabs demo for this PR is at (resets to the code in this PR daily at 8:30 am UTC time): |
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). |
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. |
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? |
Also, is this able to do autocorrect for certain rules (like the css lint and php lint do?)? |
One more question. Is this able to check embedded js in the .php scripts? |
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 🙂 |
Hi @bradymiller , thanks for setting up the demo for the pull request!
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.
Yes, ESLint has a
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? |
c77f31e
to
854ee8e
Compare
@bradymiller , note to self. incorporate this (and --fix command) in the devtools in the docker dev environments UPDATE, PRs are here: |
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