add-trailing-comma


Nameadd-trailing-comma JSON
Version 3.1.0 PyPI version JSON
download
home_pagehttps://github.com/asottile/add-trailing-comma
SummaryAutomatically add trailing commas to calls and literals
upload_time2023-08-30 17:27:39
maintainer
docs_urlNone
authorAnthony Sottile
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![build status](https://github.com/asottile/add-trailing-comma/actions/workflows/main.yml/badge.svg)](https://github.com/asottile/add-trailing-comma/actions/workflows/main.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/asottile/add-trailing-comma/main.svg)](https://results.pre-commit.ci/latest/github/asottile/add-trailing-comma/main)

add-trailing-comma
==================

A tool (and pre-commit hook) to automatically add trailing commas to calls and
literals.

## Installation

```bash
pip install add-trailing-comma
```

## As a pre-commit hook

See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions

Sample `.pre-commit-config.yaml`:

```yaml
-   repo: https://github.com/asottile/add-trailing-comma
    rev: v3.1.0
    hooks:
    -   id: add-trailing-comma
```

## multi-line method invocation style -- why?

```python
# Sample of *ideal* syntax
function_call(
    argument,
    5 ** 5,
    kwarg=foo,
)
```

- the initial paren is at the end of the line
- each argument is indented one level further than the function name
- the last parameter (unless the call contains an unpacking
  (`*args` / `**kwargs`)) has a trailing comma

This has the following benefits:

- arbitrary indentation is avoided:

    ```python
    # I hear you like 15 space indents
    # oh your function name changed? guess you get to reindent :)
    very_long_call(arg,
                   arg,
                   arg)
    ```
- adding / removing a parameter preserves `git blame` and is a minimal diff:

    ```diff
     # with no trailing commas
     x(
    -    arg
    +    arg,
    +    arg2
     )
    ```

    ```diff
     # with trailing commas
     x(
         arg,
    +    arg2,
     )
    ```


## Implemented features

### trailing commas for function calls

```diff
 x(
     arg,
-    arg
+    arg,
 )
```

### trailing commas for tuple / list / dict / set literals

```diff
 x = [
-    1, 2, 3
+    1, 2, 3,
 ]
```

### trailing commas for function definitions

```diff
 def func(
         arg1,
-        arg2
+        arg2,
 ):
```

```diff
 async def func(
         arg1,
-        arg2
+        arg2,
 ):
```

### trailing commas for `from` imports

```diff
 from os import (
     path,
-    makedirs
+    makedirs,
 )
```

### trailing comma for class definitions

```diff
 class C(
     Base1,
-    Base2
+    Base2,
 ):
     pass
```

### trailing comma for with statement

```diff
 with (
         open('f1', 'r') as f1,
-        open('f2', 'w') as f2
+        open('f2', 'w') as f2,
 ):
     pass
```

### trailing comma for match statement

```diff
 match x:
     case A(
        1,
-       2
+       2,
     ):
        pass
     case (
        1,
-       2
+       2,
     ):
        pass
     case [
        1,
-       2
+       2,
     ]:
        pass
     case {
        'x': 1,
-       'y': 2
+       'y': 2,
     }:
        pass
```


### trailling comma for PEP-695 type aliases

```diff
 def f[
-    T
+    T,
 ](x: T) -> T:
     return x
```

```diff
 class A[
-    K
+    K,
 ]:
     def __init__(self, x: T) -> None:
         self.x = x
```

```diff
 type ListOrSet[
-     T
+     T,
] = list[T] | set[T]
```

### unhug trailing paren

```diff
 x(
     arg1,
-    arg2)
+    arg2,
+)
```

### unhug leading paren

```diff
-function_name(arg1,
-              arg2)
+function_name(
+    arg1,
+    arg2,
+)
```

### match closing brace indentation

```diff
 x = [
     1,
     2,
     3,
-    ]
+]
```

### remove unnecessary commas

yes yes, I realize the tool is called `add-trailing-comma` :laughing:

```diff
-[1, 2, 3,]
-[1, 2, 3, ]
+[1, 2, 3]
+[1, 2, 3]
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/asottile/add-trailing-comma",
    "name": "add-trailing-comma",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Anthony Sottile",
    "author_email": "asottile@umich.edu",
    "download_url": "https://files.pythonhosted.org/packages/71/10/d101f4fe0b90dac7b79deaf4c809a8af495d31697b666461daec055b05a0/add_trailing_comma-3.1.0.tar.gz",
    "platform": null,
    "description": "[![build status](https://github.com/asottile/add-trailing-comma/actions/workflows/main.yml/badge.svg)](https://github.com/asottile/add-trailing-comma/actions/workflows/main.yml)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/asottile/add-trailing-comma/main.svg)](https://results.pre-commit.ci/latest/github/asottile/add-trailing-comma/main)\n\nadd-trailing-comma\n==================\n\nA tool (and pre-commit hook) to automatically add trailing commas to calls and\nliterals.\n\n## Installation\n\n```bash\npip install add-trailing-comma\n```\n\n## As a pre-commit hook\n\nSee [pre-commit](https://github.com/pre-commit/pre-commit) for instructions\n\nSample `.pre-commit-config.yaml`:\n\n```yaml\n-   repo: https://github.com/asottile/add-trailing-comma\n    rev: v3.1.0\n    hooks:\n    -   id: add-trailing-comma\n```\n\n## multi-line method invocation style -- why?\n\n```python\n# Sample of *ideal* syntax\nfunction_call(\n    argument,\n    5 ** 5,\n    kwarg=foo,\n)\n```\n\n- the initial paren is at the end of the line\n- each argument is indented one level further than the function name\n- the last parameter (unless the call contains an unpacking\n  (`*args` / `**kwargs`)) has a trailing comma\n\nThis has the following benefits:\n\n- arbitrary indentation is avoided:\n\n    ```python\n    # I hear you like 15 space indents\n    # oh your function name changed? guess you get to reindent :)\n    very_long_call(arg,\n                   arg,\n                   arg)\n    ```\n- adding / removing a parameter preserves `git blame` and is a minimal diff:\n\n    ```diff\n     # with no trailing commas\n     x(\n    -    arg\n    +    arg,\n    +    arg2\n     )\n    ```\n\n    ```diff\n     # with trailing commas\n     x(\n         arg,\n    +    arg2,\n     )\n    ```\n\n\n## Implemented features\n\n### trailing commas for function calls\n\n```diff\n x(\n     arg,\n-    arg\n+    arg,\n )\n```\n\n### trailing commas for tuple / list / dict / set literals\n\n```diff\n x = [\n-    1, 2, 3\n+    1, 2, 3,\n ]\n```\n\n### trailing commas for function definitions\n\n```diff\n def func(\n         arg1,\n-        arg2\n+        arg2,\n ):\n```\n\n```diff\n async def func(\n         arg1,\n-        arg2\n+        arg2,\n ):\n```\n\n### trailing commas for `from` imports\n\n```diff\n from os import (\n     path,\n-    makedirs\n+    makedirs,\n )\n```\n\n### trailing comma for class definitions\n\n```diff\n class C(\n     Base1,\n-    Base2\n+    Base2,\n ):\n     pass\n```\n\n### trailing comma for with statement\n\n```diff\n with (\n         open('f1', 'r') as f1,\n-        open('f2', 'w') as f2\n+        open('f2', 'w') as f2,\n ):\n     pass\n```\n\n### trailing comma for match statement\n\n```diff\n match x:\n     case A(\n        1,\n-       2\n+       2,\n     ):\n        pass\n     case (\n        1,\n-       2\n+       2,\n     ):\n        pass\n     case [\n        1,\n-       2\n+       2,\n     ]:\n        pass\n     case {\n        'x': 1,\n-       'y': 2\n+       'y': 2,\n     }:\n        pass\n```\n\n\n### trailling comma for PEP-695 type aliases\n\n```diff\n def f[\n-    T\n+    T,\n ](x: T) -> T:\n     return x\n```\n\n```diff\n class A[\n-    K\n+    K,\n ]:\n     def __init__(self, x: T) -> None:\n         self.x = x\n```\n\n```diff\n type ListOrSet[\n-     T\n+     T,\n] = list[T] | set[T]\n```\n\n### unhug trailing paren\n\n```diff\n x(\n     arg1,\n-    arg2)\n+    arg2,\n+)\n```\n\n### unhug leading paren\n\n```diff\n-function_name(arg1,\n-              arg2)\n+function_name(\n+    arg1,\n+    arg2,\n+)\n```\n\n### match closing brace indentation\n\n```diff\n x = [\n     1,\n     2,\n     3,\n-    ]\n+]\n```\n\n### remove unnecessary commas\n\nyes yes, I realize the tool is called `add-trailing-comma` :laughing:\n\n```diff\n-[1, 2, 3,]\n-[1, 2, 3, ]\n+[1, 2, 3]\n+[1, 2, 3]\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Automatically add trailing commas to calls and literals",
    "version": "3.1.0",
    "project_urls": {
        "Homepage": "https://github.com/asottile/add-trailing-comma"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab44d54465acb1c929314408044d5f65dc7f420c6022e8f2027033dc9bb6b7f7",
                "md5": "0d2364c2aaa9b6268532f8b7971d4a27",
                "sha256": "160207e2ac414a841a71f4f5095f7350f87af460aab3dfe36cfa037992530e5c"
            },
            "downloads": -1,
            "filename": "add_trailing_comma-3.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0d2364c2aaa9b6268532f8b7971d4a27",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 15413,
            "upload_time": "2023-08-30T17:27:37",
            "upload_time_iso_8601": "2023-08-30T17:27:37.983262Z",
            "url": "https://files.pythonhosted.org/packages/ab/44/d54465acb1c929314408044d5f65dc7f420c6022e8f2027033dc9bb6b7f7/add_trailing_comma-3.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7110d101f4fe0b90dac7b79deaf4c809a8af495d31697b666461daec055b05a0",
                "md5": "8f3b0d4bdb37bb830211182b40f4447b",
                "sha256": "b255319d7ef6dca308b051ffd80fccf98c018879744c7c7e03083b2eee079c45"
            },
            "downloads": -1,
            "filename": "add_trailing_comma-3.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8f3b0d4bdb37bb830211182b40f4447b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11163,
            "upload_time": "2023-08-30T17:27:39",
            "upload_time_iso_8601": "2023-08-30T17:27:39.553408Z",
            "url": "https://files.pythonhosted.org/packages/71/10/d101f4fe0b90dac7b79deaf4c809a8af495d31697b666461daec055b05a0/add_trailing_comma-3.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-30 17:27:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "asottile",
    "github_project": "add-trailing-comma",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "add-trailing-comma"
}
        
Elapsed time: 0.24138s