{"id":13436231,"url":"https://github.com/facebookincubator/fastmod","last_synced_at":"2025-03-18T20:31:06.192Z","repository":{"id":38858190,"uuid":"129819016","full_name":"facebookincubator/fastmod","owner":"facebookincubator","description":"A fast partial replacement for the codemod tool","archived":false,"fork":false,"pushed_at":"2024-04-23T20:16:00.000Z","size":157,"stargazers_count":1592,"open_issues_count":12,"forks_count":41,"subscribers_count":23,"default_branch":"main","last_synced_at":"2024-04-24T01:02:03.123Z","etag":null,"topics":["cli","command-line","command-line-tool","find-and-replace","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/facebookincubator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-16T23:39:07.000Z","updated_at":"2024-07-16T08:05:15.734Z","dependencies_parsed_at":"2022-07-12T17:39:45.757Z","dependency_job_id":"ff5a2bb6-807b-4158-8d76-966d07f1790e","html_url":"https://github.com/facebookincubator/fastmod","commit_stats":{"total_commits":66,"total_committers":12,"mean_commits":5.5,"dds":"0.24242424242424243","last_synced_commit":"52642518ffecae0dfb22d20db712641762fe1086"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookincubator%2Ffastmod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookincubator%2Ffastmod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookincubator%2Ffastmod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookincubator%2Ffastmod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facebookincubator","download_url":"https://codeload.github.com/facebookincubator/fastmod/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244301366,"owners_count":20430929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","command-line","command-line-tool","find-and-replace","rust"],"created_at":"2024-07-31T03:00:45.704Z","updated_at":"2025-03-18T20:31:06.187Z","avatar_url":"https://github.com/facebookincubator.png","language":"Rust","funding_links":[],"categories":["Software","Write code to change code","Rust","cli","\u003ca name=\"programming\"\u003e\u003c/a\u003eProgramming","Applications"],"sub_categories":["Generic","Utilities"],"readme":"# fastmod\n`fastmod` is a fast partial replacement for\n[codemod](https://github.com/facebook/codemod). Like `codemod`, it is\na tool to assist you with large-scale codebase refactors, and it\nsupports most of `codemod`'s options. `fastmod`'s major philosophical\ndifference from `codemod` is that it is focused on improving the use\ncase \"I want to use interactive mode to make sure my regex is correct,\nand then I want to apply the regex everywhere\". For this use case, it\noffers much better performance than `codemod`. Accordingly, `fastmod`\ndoes not support `codemod`'s `--start`, `--end`, or `--count` options,\nnor does it support anything like `codemod`'s Python API.\n\n## Examples\n\nLet's say you're deprecating your use of the `\u003cfont\u003e` tag. From the\ncommand line, you might make progress by running:\n\n```\nfastmod -m -d /home/jrosenstein/www --extensions php,html \\\n    '\u003cfont *color=\"?(.*?)\"?\u003e(.*?)\u003c/font\u003e' \\\n    '\u003cspan style=\"color: ${1};\"\u003e${2}\u003c/span\u003e'\n```\n\nFor each match of the regex, you'll be shown a colored diff and asked\nif you want to accept the change (the replacement of the `\u003cfont\u003e` tag\nwith a `\u003cspan\u003e` tag), reject it, or edit the line in question in your\n`$EDITOR` of choice.\n\nNOTE: Whereas `codemod` uses Python regexes, `fastmod` uses the Rust\n[regex](https://github.com/rust-lang/regex) crate, which supports a\nslightly different regex syntax and does not support look around or\nbackreferences. In particular, use `${1}` instead of `\\1` to get the\ncontents of the first capture group, and use `$$` to write a literal\n`$` in the replacement string. See the regex crate's\n[documentation](https://docs.rs/regex/#syntax) for details.\n\nA consequence of this syntax is that the use of single quotes instead\nof double quotes around the replacement text is important, because the\n`bash` shell itself cares about the `$` character in double-quoted\nstrings. If you must double-quote your input text, be careful to\nescape `$` characters properly!\n\n`fastmod` also offers a usability improvement over `codemod`: it\naccepts files or directories to process as extra positional arguments\nafter the regex and substitution. For instance, the example above\ncould have been rewritten as\n\n```\nfastmod -m --extensions php,html \\\n    '\u003cfont *color=\"?(.*?)\"?\u003e(.*?)\u003c/font\u003e' \\\n    '\u003cspan style=\"color: ${1};\"\u003e${2}\u003c/span\u003e' \\\n    /home/jrosenstein/www\n```\n\nThis makes it possible to use `fastmod` to process a list of files\nfrom somewhere else if needed. Note, however, that `fastmod` does its\nown parallel directory traversal internally, so doing `find ... |\nxargs fastmod ...` may be much slower than using `fastmod` by itself.\n\n## Requirements\n\n`fastmod` is primarily supported on macOS and Linux.\n\n`fastmod` has also been reported to work reasonably well on\nWindows. The major portability concerns are 1) the use of `$EDITOR`\nwith a fallback and 2) the console UI, which is descended from\n`codemod`'s ncurses-based text coloring \u0026 screen clearing\ncode. Windows-specific issues and PRs will be considered as long as\nthey aren't too invasive. For example, if something doesn't work on\nWindows because a Linux/Mac-specific API was used instead of\nequivalent POSIX or Rust standard library calls, we would be happy to\nfix that. On the other hand, we would like to avoid taking a direct\n`winapi` dependency or substantially increasing the size of our\ndependency graph for Windows-only enhancements.\n\n## Building `fastmod`\n\n`fastmod` is written in (stable) [Rust](https://www.rust-lang.org/)\nand compiles with Rust's `cargo` build system. To build:\n\n```\n$ git clone https://github.com/facebookincubator/fastmod.git\n$ cd fastmod\n$ cargo build --release\n$ ./target/release/fastmod --help\n...\n```\n\n## Installing fastmod\nThe easiest way to install fastmod is simply `cargo install\nfastmod`. If you have built `fastmod` from source following the\ndirections above, you can install your build with `cargo install`.\n\n## How `fastmod` works\n`fastmod` uses the\n[ignore](https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore)\ncrate to walk the given directory hierarchy using multiple threads in\nparallel while respecting `.gitignore`. It uses the\n[grep](https://github.com/BurntSushi/ripgrep/tree/master/crates/grep)\ncrate to match each file, reads matching files into memory, applies\nthe given regex substitution one match at a time, and uses the\n[diff](https://github.com/utkarshkukreti/diff.rs) crate to present the\nresulting changes as patches for human review.\n\n## Full documentation\n\nSee `fastmod --help`.\n\n## License\n`fastmod` is Apache-2.0-licensed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebookincubator%2Ffastmod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffacebookincubator%2Ffastmod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebookincubator%2Ffastmod/lists"}