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

Lint generated files #6218

Closed
wants to merge 6 commits into from

Conversation

pantheredeye
Copy link
Collaborator

For [Generators] generated code should be linted and formatted #1551
and perhaps [Bug]: Scaffold generator creates a big block of whitespace in Form component #6097
and touches this: Generated Content has Lint Issues #4824

✅ What it does

Adds args -l --lint : "Lint Generated Files" : default: true to generator cli
Runs lint --fix on generated files.

Currently only works on "Directives."

I wanted to get the PR started to see if this was the route to go with this. Beyond the technical implementation, there is this nagging question surfaced in the issues linked above, which is summed up by @thedavidprice:

However, it's probably not as easy as globally running lint --fix:

we should consider whether or not it's OK to fix any/all pre-existing issues
there are many cases where generator boilerplate has unused vars
... ?

Approach:
I copied the writeFilesTask and made lintFilesTask, which calls lintFile (which is a copy of writeFile).

This is exported and called as a task in the Directives generator file.

🔮 What needs to be verified

Is this the approach to take?
I feel like it is still linting even after it says it is done. I do not know how to check to see if this is the case.
Is there a better way to call or abstract the writeFilesTask/lintFilesTask.
Confirm if we want to run lint files after every generator.

🚧 What is left to do

Add linting task to other appropriate generator files
Add testing?

👏 Credits

If you’re looking for an example of “what makes a good PR”, look no further than this one by Kim-Adeline:

Convert component generator to TS #632

@nx-cloud
Copy link

nx-cloud bot commented Aug 16, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 2466a05. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 14 targets

Sent with 💌 from NxCloud.

@netlify
Copy link

netlify bot commented Aug 16, 2022

Deploy Preview for redwoodjs-docs canceled.

Name Link
🔨 Latest commit 2466a05
🔍 Latest deploy log https://app.netlify.com/sites/redwoodjs-docs/deploys/62faf63999db7d00085e4729

@pantheredeye pantheredeye changed the title Bbb lint generators Lint generated files Aug 16, 2022

// const filename = path.basename(target)
// const targetDir = target.replace(filename, '')
execa('yarn rw lint --fix --path ', [`./${path.relative(base, target)}`], {

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input

[Shell argument](1) based on [library input](2) is later used in [shell command](3).
@Tobbe
Copy link
Member

Tobbe commented Aug 16, 2022

Thanks for getting started on this PR @pantheredeye

@Philzen outlined a different approach here: #6059 (comment) IIRC The reason he preferred doing it that way was concerns about speed. Adding linting to every generator command execution would slow the command down. And so it was better to make sure they just output correct code in the first place.

Do you have any thoughts on that @pantheredeye? And @Philzen, please do jump in here if you have anything more to add

@pantheredeye
Copy link
Collaborator Author

@Tobbe I had speed concerns, also. Especially around scaffolding. I like @Philzen's approach of attempting to address in the CI pipeline, before things ever go to main. It feels cleaner to address linting issues before code ever hits the main branch. This approach would provide better speed for developers using the generators.

I noticed his CI comment here: #6097 (comment), but had not noticed the comment you linked, which details his idea a little more in-depth. In the issue you linked, Phil mentioned getting an RFC going for linting in the CI pipeline. How about I start an RFC for addressing linting issues, mention both approaches, and see what the team at-large suggests?

I am happy to help out however you suggest. I am willing to give the CI approach a go, with some guidance.

@Tobbe
Copy link
Member

Tobbe commented Aug 16, 2022

@pantheredeye Thanks for linking that comment. I knew he had written that somewhere. For some reason I missed it when skimming over his recent PRs and comments...

An RFC mentioning both approaches sounds good! Please do that 🙂 That will also be a good place to document the core-team's decision on this.

Thanks for moving forward with this!

@Philzen
Copy link
Contributor

Philzen commented Aug 19, 2022

@pantheredeye @Tobbe

It feels cleaner to address linting issues before code ever hits the main branch.

That's exactly how i feel! Thanks for the RFC. I curated i list of issues and PRs that would all be prevented by following that approach, which i'm going to add to the issue.

Cheers!

@Tobbe
Copy link
Member

Tobbe commented Dec 17, 2023

I'm going to close this one in favor of #6223
Please do continue the discussion over in that RFC

@Tobbe Tobbe closed this Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants