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
[BREAKING ENHANCEMENT] Refactor generate script to only lint generated files #9995
[BREAKING ENHANCEMENT] Refactor generate script to only lint generated files #9995
Conversation
This has been discussed on the Discord April of 2022. Thanks for implementing @Jan-PieterBaert Before this PR, Prettier ran on all code when running a generator. This is surprising for the code-bases where prettier isn't fully adopted yet and it hinders the adoption for prettier for people with slower machines. The motivation as to why it's okay to run Prettier on the whole code-base is because the code-base should be fully compliant either case. For that situation, this change is not a breaking change and it is only a performance improvement. Hindrance of prettier adoption on limited hardwareIn the chat conversation it became clear that at least one user (and probably more) disable Prettier because it makes developing EmberJS on a large codebase too slow. One of the reasons this may be is because a generator will run prettier on all the code, thus making the generation process substantially slower than what it should be. This PR will therefore make running generators on large projects faster. Unexpected changed filesWhen happily hacking an EmberJS codebase that isn't fully Prettier compatible yet, a user (like me) may notice suddenly a bunch of files have changed. The reader of this PR will know it comes from running |
@@ -13,11 +13,12 @@ | |||
"scripts": { | |||
"build": "ember build --environment=production", | |||
"lint": "npm-run-all --print-name --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", | |||
"lint:fix": "npm-run-all --print-name --aggregate-output --continue-on-error --parallel \"lint:*:fix\"", | |||
"lint:fix": "npm-run-all \"lint:fix:script -- .\"", |
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 lint:fix
script now assumes every lint:*:fix
script needs to run on the entire codebase because of the trailing .
.
I'm not sure if that's an assumption we can make.
E.g. when you have a custom script like "lint:json:fix": "prettier \"./**/*.json\" --write"
, instead of running prettier \"./**/*.json\" --write"
, this will run prettier \"./**/*.json\" --write" .
and will most likely fail / produce unexpected results as the trailing .
supersedes \"./**/*.json\"
.
Also:
- This removes the
--print-name
flag which was just added over in [BUGFIX] - Address npm-run-all and Yarn 3 conflict & Removed warning #9988 --
is not needed when using Yarn, using this results in the following warning:From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
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.
a solution for this could be to make a :script
version of the current lint:js:fix
and lint:hbs:fix
scripts which would take the files to run on as argument (with the .
being the default used when lint:js:fix
and lint:hbs:fix
are executed) and then running lint:*:fix:script
instead of lint:*:fix
@@ -13,11 +13,12 @@ | |||
"scripts": { | |||
"build": "ember build --environment=production", | |||
"lint": "npm-run-all --print-name --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", | |||
"lint:fix": "npm-run-all --print-name --aggregate-output --continue-on-error --parallel \"lint:*:fix\"", | |||
"lint:fix": "npm-run-all \"lint:fix:script -- .\"", | |||
"lint:fix:script": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:*:fix -- {@}\" --", |
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 :script
suffix feels unnecessary to me for a script name. Also, this script seems like it should not be run from the terminal, only by Ember CLI itself (?), which makes me wonder if it belongs 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.
The :script
suffix is just to make lint:fix
still executable as before, I put it here since I didn't know where to put it elsewhere, where do you think it would fit better than here?
"lint:hbs": "ember-template-lint .", | ||
"lint:hbs:fix": "ember-template-lint . --fix", | ||
"lint:hbs:fix": "ember-template-lint --fix", |
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.
It seems removing the .
makes the script unusable via the terminal. It doesn't fix lint violations anymore.
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.
would solving this by making a :script
version be the preferred way?
"lint:js": "eslint . --cache", | ||
"lint:js:fix": "eslint . --fix", | ||
"lint:js:fix": "eslint --fix", |
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.
It seems removing the .
makes the script unusable via the terminal. It doesn't fix lint violations anymore.
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.
would solving this by making a :script
version be the preferred way?
Also, just noticed that this sends every file to every I'll try to check on Wednesday with the rest of the team, what would be the best way forward. |
I understand/acknowledge the motivation behind this PR, but I'm not convinced that this is the right solution. Admittedly, I'm not sure what the right solution would be here, but personally, I wouldn't want to force these additional I'm also slightly "concerned" about the fact that now every generated file is passed along to every fix script (e.g. |
This was discussed during the CLI meeting. Everyone agreed that the current state is not ideal, but we also felt that the proposed solution would be to invasive/questionable for apps and addons and that your best bet at the moment would be to simply disable the functionality if it doesn't fit your workflow. This can be done via your {
"lintFix": false
} Thanks though for putting time and effort into this. |
One other "alternative" could be to have this functionality disabled by default and have users opt-in instead, but I assume we would need more community feedback on this before making such a decision. |
Also made a suggestion on Discord to improve the current situation a bit feedback-wise: |
@bertdeblock If I understand correctly, setting lintFix to false would mean all lint fixes are gone, which in turn means generated files will have a challenging structure (especially when blueprints expect linting to occur). It would also not help newcomers as they will not set this property and there is no obvious way of discovering when linting has ran and therefore also no obvious way of discovering this setting as a solution. I also understand the solution provided here is not as clean as it should be and I don't see an obvious path forward. Is there a different way to expose linting which could be used from blueprint generation? |
Setting
Not that I know of unfortunately, but maybe you can update the |
We ourselves are looking at a 100-something repositories with Ember code in them. We are looking at a solution with EmberJS as a whole whenever possible. Automated patches also don't tend to translate to new projects and on-boarding of new people. The git suggestion you make is a very interesting one though. Would an optional argument to I'd still be looking for a more sturdy solution but using git changed files would help a bit? |
This pull request changes the
package.json
file.With this pull request when generating files, the
lint:fix
script will be executed on only the generated files instead of the entire project.