{"id":13414192,"url":"https://github.com/cpojer/js-codemod","last_synced_at":"2025-05-15T03:06:01.684Z","repository":{"id":29180641,"uuid":"32711479","full_name":"cpojer/js-codemod","owner":"cpojer","description":"Codemod scripts to transform code to next generation JS","archived":false,"fork":false,"pushed_at":"2022-12-07T09:44:43.000Z","size":343,"stargazers_count":1227,"open_issues_count":4,"forks_count":109,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-14T03:00:01.311Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cpojer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-23T04:45:13.000Z","updated_at":"2025-03-14T16:23:53.000Z","dependencies_parsed_at":"2023-01-14T14:30:31.769Z","dependency_job_id":null,"html_url":"https://github.com/cpojer/js-codemod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpojer%2Fjs-codemod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpojer%2Fjs-codemod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpojer%2Fjs-codemod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpojer%2Fjs-codemod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cpojer","download_url":"https://codeload.github.com/cpojer/js-codemod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249176,"owners_count":22039027,"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":[],"created_at":"2024-07-30T21:00:16.297Z","updated_at":"2025-05-15T03:06:01.665Z","avatar_url":"https://github.com/cpojer.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others","Language Analysis"],"sub_categories":["TypeScript / JavaScript"],"readme":"## js-codemod [![Build Status](https://travis-ci.org/cpojer/js-codemod.svg)](https://travis-ci.org/cpojer/js-codemod)\n\nThis repository contains a collection of codemod scripts for use with\n[JSCodeshift](https://github.com/facebook/jscodeshift).\n\n### Setup \u0026 Run\n\n```sh\nnpm install -g jscodeshift\ngit clone https://github.com/cpojer/js-codemod.git\njscodeshift -t \u003ccodemod-script\u003e \u003cfile\u003e\n```\n\nUse the `-d` option for a dry-run and use `-p` to print the output for\ncomparison.\n\n### Included Scripts\n\n#### `arrow-function-arguments`\n\n```sh\njscodeshift -t js-codemod/transforms/arrow-function-arguments.js \u003cfile\u003e\n```\n\n#### `arrow-function`\n\nTransforms callbacks only when it can guarantee it won't break `this` context in the function. Also transforms `function() { }.bind(this)` calls to `() =\u003e {}`.\n\n```sh\njscodeshift -t js-codemod/transforms/arrow-function.js \u003cfile\u003e\n```\n\n##### Options:\n\n`--inline-single-expressions=true`: If you are feeling lucky and you know that returning the value of single-expression functions will not affect the behavior of your application you can specify the option and it will transform `function() { relay(); }` to `() =\u003e relay()` instead of `() =\u003e { relay(); }`.\n\n`--max-width=120`: Try the best it can to keep line lengths under the specified length.\n\n#### `invalid-requires`\n\n```sh\njscodeshift -t js-codemod/transforms/invalid-requires.js \u003cfile\u003e\n```\n\n#### `jest-update`\n\n```sh\njscodeshift -t js-codemod/transforms/jest-update.js \u003cfile\u003e\n```\n\n#### `no-reassign-params`\n\nConverts functions to not reassign to parameters. This is useful to turn on in conjunction with [Flow's const_params](https://flow.org/en/docs/config/options/#toc-experimental-const-params-boolean) option.\n\n```sh\njscodeshift -t js-codemod/transforms/no-reassign-params.js \u003cfile\u003e\n```\n\n#### `no-vars`\n\nConservatively converts `var` to `const` or `let`.\n\n```sh\njscodeshift -t js-codemod/transforms/no-vars.js \u003cfile\u003e\n```\n\n#### `object-shorthand`\n\nTransforms object literals to use [ES6 shorthand](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015)\nfor properties and methods.\n\n```sh\njscodeshift -t js-codemod/transforms/object-shorthand.js \u003cfile\u003e\n```\n\n#### `outline-require`\n\n```sh\njscodeshift -t js-codemod/transforms/outline-require.js \u003cfile\u003e\n```\n\n#### `rm-copyProperties`\n\n```sh\njscodeshift -t js-codemod/transforms/rm-copyProperties.js \u003cfile\u003e\n```\n\n#### `rm-merge`\n\n```sh\njscodeshift -t js-codemod/transforms/rm-merge.js \u003cfile\u003e\n```\n\n#### `rm-object-assign`\n\n```sh\njscodeshift -t js-codemod/transforms/rm-object-assign.js \u003cfile\u003e\n```\n\n#### `rm-requires`\n\nRemoves any requires where the imported value is not referenced. Additionally\nif any module is required more than once the two requires will be merged.\n\n```sh\njscodeshift -t js-codemod/transforms/rm-requires.js \u003cfile\u003e\n```\n\n#### `template-literals`\n\nReplaces string concatenation with template literals.\n\n```sh\njscodeshift -t js-codemod/transforms/template-literals.js \u003cfile\u003e\n```\n\nAdapted from [\"How to write a codemod\" by Ramana Venkata](https://vramana.github.io/blog/2015/12/21/codemod-tutorial/).\n\nAreas of improvement:\n\n- Comments in the middle of string concatenation are currently added before the\n  string but after the assignment. Perhaps in these situations, the string\n  concatenation should be preserved as-is.\n\n- Nested concatenation inside template literals is not currently simplified.\n  Currently, a + `b${'c' + d}` becomes `${a}b${'c' + d}` but it would ideally\n  become ``${a}b${`c${d}`}``.\n\n- Unnecessary escaping of quotes from the resulting template literals is\n  currently not removed. This is possibly the domain of a different transform.\n\n- Unicode escape sequences are converted to unicode characters when the\n  simplified concatenation results in a string literal instead of a template\n  literal. It would be nice to perserve the original--whether it be a unicode\n  escape sequence or a unicode character.\n\n#### `touchable`\n\n```sh\njscodeshift -t js-codemod/transforms/touchable.js \u003cfile\u003e\n```\n\n#### `trailing-commas`\n\nAdds trailing commas to array and object literals.\n\n```sh\njscodeshift -t js-codemod/transforms/trailing-commas.js \u003cfile\u003e\n```\n\n#### `unchain-variables`\n\nUnchains chained variable declarations.\n\n```sh\njscodeshift -t js-codemod/transforms/unchain-variables.js \u003cfile\u003e\n```\n\n#### `underscore-to-lodash-native`\n\nReplaces underscore (or lodash) to ES6 + lodash, preferring native ES6 array methods. Member imports are used by default to allow tree-shaking, but the `--split-imports=true` option will split each lodash import into its own `lodash/\u003cmethod\u003e` import.\n\n```sh\njscodeshift -t js-codemod/transforms/underscore-to-lodash-native.js \u003cfile\u003e\n```\n\n#### `unquote-properties`\n\nRemoves quotes from object properties whose keys are strings which are valid\nidentifiers.\n\n```sh\njscodeshift -t js-codemod/transforms/unquote-properties.js \u003cfile\u003e\n```\n\n#### `updated-computed-props`\n\n```sh\njscodeshift -t js-codemod/transforms/updated-computed-props.js \u003cfile\u003e\n```\n\n#### `use-strict`\n\nAdds a top-level `'use strict'` statement to JavaScript files\n\n```sh\njscodeshift -t js-codemod/transforms/use-strict.js \u003cfile\u003e\n```\n\n\n### Included extensions\n\n`jscodeshift-imports` helpers for modifying `import` and `require` statements,\n[see docs](extensions/imports/).\n\n### Recast Options\n\n[Options to recast's printer](https://github.com/benjamn/recast/blob/master/lib/options.ts) can be provided\nthrough the `printOptions` command line argument\n\n```sh\njscodeshift -t transform.js \u003cfile\u003e --printOptions='{\"quote\":\"double\"}'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpojer%2Fjs-codemod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcpojer%2Fjs-codemod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpojer%2Fjs-codemod/lists"}