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

Add tab width option #6848

Merged
merged 1 commit into from
Aug 26, 2023
Merged

Add tab width option #6848

merged 1 commit into from
Aug 26, 2023

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Aug 24, 2023

Summary

This adds a new tab_width option that gets passed to the Printer. The tab_width option specifies the visual width of a tab character.

Test Plan

I added a new test. The fact that I had to add options not to regress tests that assumed a tab width of 8 proves that it works :)

@MichaReiser
Copy link
Member Author

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

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

How does this interact with docstring formatting where we have "pad to the next multiple of 8" hardcoded?

crates/ruff_formatter/src/lib.rs Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2023

PR Check Results

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      4.1±0.03ms    10.0 MB/sec    1.01      4.1±0.04ms     9.9 MB/sec
formatter/numpy/ctypeslib.py               1.00    852.0±2.84µs    19.5 MB/sec    1.01    861.2±2.70µs    19.3 MB/sec
formatter/numpy/globals.py                 1.00     82.0±0.65µs    36.0 MB/sec    1.01     83.1±0.38µs    35.5 MB/sec
formatter/pydantic/types.py                1.00   1673.9±9.84µs    15.2 MB/sec    1.01   1689.5±9.87µs    15.1 MB/sec
linter/all-rules/large/dataset.py          1.01     10.3±0.11ms     3.9 MB/sec    1.00     10.2±0.07ms     4.0 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      2.7±0.01ms     6.1 MB/sec    1.00      2.7±0.01ms     6.1 MB/sec
linter/all-rules/numpy/globals.py          1.00    387.0±1.15µs     7.6 MB/sec    1.01    390.0±2.88µs     7.6 MB/sec
linter/all-rules/pydantic/types.py         1.00      5.3±0.04ms     4.8 MB/sec    1.00      5.3±0.03ms     4.8 MB/sec
linter/default-rules/large/dataset.py      1.00      5.4±0.02ms     7.5 MB/sec    1.00      5.4±0.03ms     7.5 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1205.6±5.41µs    13.8 MB/sec    1.00  1210.3±15.90µs    13.8 MB/sec
linter/default-rules/numpy/globals.py      1.00    141.1±0.33µs    20.9 MB/sec    1.00    141.2±0.72µs    20.9 MB/sec
linter/default-rules/pydantic/types.py     1.00      2.5±0.00ms    10.3 MB/sec    1.00      2.5±0.02ms    10.3 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      4.6±0.07ms     8.9 MB/sec    1.00      4.6±0.03ms     8.9 MB/sec
formatter/numpy/ctypeslib.py               1.00    912.4±8.05µs    18.3 MB/sec    1.02   926.5±21.45µs    18.0 MB/sec
formatter/numpy/globals.py                 1.00     85.8±1.04µs    34.4 MB/sec    1.02     87.4±1.22µs    33.7 MB/sec
formatter/pydantic/types.py                1.00  1864.7±22.29µs    13.7 MB/sec    1.00  1868.2±14.92µs    13.7 MB/sec
linter/all-rules/large/dataset.py          1.00     12.5±0.09ms     3.3 MB/sec    1.01     12.6±0.13ms     3.2 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.5±0.02ms     4.7 MB/sec    1.00      3.5±0.02ms     4.7 MB/sec
linter/all-rules/numpy/globals.py          1.00    361.1±4.94µs     8.2 MB/sec    1.02    367.0±7.12µs     8.0 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.5±0.06ms     3.9 MB/sec    1.01      6.6±0.05ms     3.9 MB/sec
linter/default-rules/large/dataset.py      1.00      7.0±0.04ms     5.8 MB/sec    1.01      7.0±0.09ms     5.8 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1457.6±14.37µs    11.4 MB/sec    1.01  1478.2±15.93µs    11.3 MB/sec
linter/default-rules/numpy/globals.py      1.00    151.9±1.55µs    19.4 MB/sec    1.00    152.1±1.64µs    19.4 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.1±0.02ms     8.1 MB/sec    1.00      3.1±0.03ms     8.1 MB/sec

@MichaReiser MichaReiser force-pushed the tab-width-option branch 2 times, most recently from bdd79f3 to b81f4a7 Compare August 24, 2023 11:13
@MichaReiser MichaReiser added the formatter Related to the formatter label Aug 24, 2023
@MichaReiser
Copy link
Member Author

MichaReiser commented Aug 24, 2023

How does this interact with docstring formatting where we have "pad to the next multiple of 8" hardcoded?

Thanks for pointing this out. I changed the docstring padding to use the value from the options. Deviating here isn't an issue because a) people chan change the option b) this is only relevant for not blacked projects (adoption)

@MichaReiser MichaReiser marked this pull request as ready for review August 24, 2023 11:21
Base automatically changed from best-fits-call-expr to main August 24, 2023 12:09
@MichaReiser MichaReiser changed the title Add tabwidth option Add tab width option Aug 24, 2023
@cnpryer cnpryer mentioned this pull request Aug 24, 2023
3 tasks
@MichaReiser
Copy link
Member Author

Merging because it is a simple enough change and there's other work that depends on it.

@MichaReiser MichaReiser merged commit 9d77552 into main Aug 26, 2023
17 checks passed
@MichaReiser MichaReiser deleted the tab-width-option branch August 26, 2023 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants