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

Document how to list all available codemodders #27

Merged
merged 1 commit into from
May 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,44 @@ Should work nicely with [libCST codemods](https://libcst.readthedocs.io/en/lates
[as per the libCST docs](https://libcst.readthedocs.io/en/latest/codemods_tutorial.html?highlight=modules#setting-up-and-running-codemods):

```bash
python3 -m libcst.tool initialize .
> python3 -m libcst.tool initialize .
```

You may skip this step if the `.libcst.codemod.yaml` file is already present.

2. Edit the config to add the command from `django-codemod` to your modules:
2. Edit the config to add the commands from `django-codemod` to your modules:

```yaml
# .libcst.codemod.yaml
modules:
- 'django_codemod.commands'
```

This makes the codemodders from Djnago codecod discoverable by libCST

3. Run libCST with the command from `django-codemod` that you want to apply:

```bash
python3 -m libcst.tool codemod django_40.ForceTextToForceStrCommand .
> python3 -m libcst.tool codemod django_40.ForceTextToForceStrCommand .
```

This will apply to code modifications for all the code under `.` **in place**.
Make sure it's backed up in source control!

## List of codemodders

Codemodders are written as commands for libCST and are located in `django_codemod.commands`. They are organised by the version of Django where the feature is removed. Django has a [deprecation timeline page](https://docs.djangoproject.com/en/3.0/internals/deprecation/) which is listing all its deprecations. For instance, to fix a deprecation listed in the 4.0 section, the corresponding codemodder should be found in `django_codemod.commands.django_40`.
If everything is setup properly, the list of Django Codemods should appear when running libCST's `list` command:

```bash
> python3 -m libcst.tool list
django_30.RenderToResponseToRenderCommand - Replaces render_to_response() by render().
django_40.ForceTextToForceStrCommand - Replaces force_text() by force_str().
django_40.SmartTextToForceStrCommand - Replaces smart_text() by smart_str().
django_40.UGetTextLazyToGetTextLazyCommand - Replaces ugettext_lazy() by gettext_lazy().
django_40.UGetTextNoopToGetTextNoopCommand - Replaces ugettext_noop() by gettext_noop().
django_40.UGetTextToGetTextCommand - Replaces ugettext() by gettext().
django_40.UNGetTextLazyToNGetTextLazyCommand - Replaces ungettext_lazy() by ngettext_lazy().
django_40.UNGetTextToNGetTextCommand - Replaces ungettext() by ngettext().
```

Codemodders are organised by the version of Django where a feature is removed. Django has a [deprecation timeline page](https://docs.djangoproject.com/en/3.0/internals/deprecation/) which is listing all its deprecations. For instance, to fix a deprecation listed in the 4.0 section, the corresponding codemodder should be found under `django_40`.