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

Adding --gitignore flag #508

Merged
merged 3 commits into from
Jun 14, 2024
Merged

Conversation

ElonVolo
Copy link
Collaborator

Adds a --gitignore flag that uses a .gitignore file in the current working directory to force jscodeshift to abstain from transforming files that match patterns specified in the .gitignore file.

Please note that this feature is added primarily for the benefit of beginners to jscodeshift, as a way to make the enormously timesaving technique of passing a project's .gitignore file to jscodeshift easily discoverable and learnable. The idea is that when the user looks at the jscodeshift help page, "--gitignore" jumps right out at them and they immediately make the connection.

It took me a year and a half of using jscodeshift before I realized I could simply just pass .gitignore to the utiliity, and creating a new ignore file for a freshly cloned project every day is an annoyance I wouldn't wish on others.

Due to the --gitignore flag being a discoverability feature, renaming it to something generic would impede the discoverability it's trying to promote.

Adds a --gitignore flag that uses a .gitignore file in the current working directory to force jscodeshift to abstain from transforming files that match patterns specified in the .gitignore file.

Please note that this feature is added primarily for the benefit of beginners to jscodeshift, as a way to make the enormously timesaving technique of passing a project's .gitignore file to jscodeshift easily discoverable and learnable. The idea is that when the user looks at the jscodeshift help page, "--gitignore" jumps right out at them and they immediately make the connection.

It took me a year and a half of using jscodeshift before I realized I could simply just pass .gitignore to the utiliity, and creating a new ignore file for a freshly cloned project every day is an annoyance I wouldn't wish on others.

Due to the --gitignore flag being a discoverability feature, renaming it to something generic would impede the discoverability it's trying to promote.
Again, --gitignore is supposed to jump out at you from the docs.
Copy link
Member

@Daniel15 Daniel15 left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me. Thanks!

@@ -20,6 +20,7 @@ const path = require('path');
const temp = require('temp');
const mkdirp = require('mkdirp');
const testUtils = require('../../utils/testUtils');
const { chdir } = require('process');
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Remove spaces - Facebook Meta style has no spaces around destructured variables

const {chdir} = require('process');

I guess we should configure Prettier for jscodeshift one day.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Daniel15 fixed.

README.md Outdated
jscodeshift -—ignore-config="MyIgnoreFile.gitignore" mytransform.js

// More than one ignore file
jscodeshift -—ignore-pattern="first_ignore_file.gitignore” -—ignore-pattern="second_ignore_file.gitignore” mytransform.js
Copy link
Member

Choose a reason for hiding this comment

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

It looks like all the new example commands use a hyphen and a dash (-—) rather than two hyphens (--). Can you please fix those?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

jscodeshift -—ignore-pattern="first_ignored_dir/**/*” -—ignore-pattern="second_ignored_dir/**/*” mytransform.js
```

__--ignore-config__ takes one or more paths to files containing lines with [.gitignore format](https://git-scm.com/docs/gitignore#_pattern_format) glob patterns.
Copy link
Member

Choose a reason for hiding this comment

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

So is --ignore-config just like --gitignore except you can specify the paths to the files with the ignore patterns?

Copy link
Collaborator Author

@ElonVolo ElonVolo May 27, 2022

Choose a reason for hiding this comment

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

Exactly. --ignore-config allows for more custom functionality than --gitignore.

The problem was never that jscodeshift's ignore features didn't provide extensive custom functionality for advanced users; the problem was that jscodeshift's ignore functionality didn't provide any basic, easy-to-discover features for beginning users. --gitignore is a simple UI affordance that directs new users to make use of their project's existing .gitignore file to ignore files that any sane person would never want to transform in a real world situation.

@ElonVolo ElonVolo closed this Jun 22, 2022
@ElonVolo ElonVolo reopened this Jun 14, 2024
@ElonVolo ElonVolo merged commit 0fac51d into facebook:main Jun 14, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants