Title: Implement `usethis tool ruff` · Issue #27 · usethis-python/usethis-python · GitHub
Open Graph Title: Implement `usethis tool ruff` · Issue #27 · usethis-python/usethis-python
X Title: Implement `usethis tool ruff` · Issue #27 · usethis-python/usethis-python
Description: Motivation ruff is probably the most popular linter as of late (for good reason) so it's essential we include it in usethis. Summary of desired feature Support the addition of ruff to a project using the usethis tool ruff command Design ...
Open Graph Description: Motivation ruff is probably the most popular linter as of late (for good reason) so it's essential we include it in usethis. Summary of desired feature Support the addition of ruff to a project usi...
X Description: Motivation ruff is probably the most popular linter as of late (for good reason) so it's essential we include it in usethis. Summary of desired feature Support the addition of ruff to a project...
Opengraph URL: https://github.com/usethis-python/usethis-python/issues/27
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Implement `usethis tool ruff`","articleBody":"**Motivation**\r\n`ruff` is probably the most popular linter as of late (for good reason) so it's essential we include it in `usethis`.\r\n\r\n**Summary of desired feature**\r\nSupport the addition of `ruff` to a project using the `usethis tool ruff` command\r\n\r\n**Design**\r\nBasically, the tool would be handled identically to `deptry` but there are some additional complications from needing `pyproject.toml` config. In particular, there needs to be some logic to add the new configuration sections to the `pyproject.toml`, if they don't already exist. This should be inserted alphabetically within the `tool` section - in cases where the order is not already alphabetical, place it as low as possible while still retaining order in terms of the subsequent sections.\r\n\r\nThere will be two hooks corresponding to formatting and checks, which is also different to the `deptry` case where there is only one hook.\r\n\r\nWe need to decide which rules to enable. To simplify things, we can just use `ruff`'s defaults, i.e. `[\"E4\", \"E7\", \"E9\", \"F\"]`, plus a collection of others which are mostly autofixable and relatively uncontroversial:\r\n`[\"I\", \"UP\", \"C4\", \"SIM\", \"PLE\", \"PLR\", \"FURB\", \"RUF\"]`\r\n\r\nLater, the user could opt-in to a more aggressive approach with a `--strict` command which tries to enable as many rules as is reasonable (perhaps avoiding the especially controversial ones or ones with too many false positives). For now, we won't implement the `--strict` flag, so there would be minimal `ruff` configuration to add in `pyproject.toml`.\r\n\r\nAlso, later, for tools managed by `usethis`, we could ensure particular rules are enabled, e.g. `\"PT\"` when the user is using `pytest`.\r\n\r\nWhen making the strict flag later, here are some thoughts for reference:\r\n- Some rules are \"under-specified\" without further configuration, e.g. docstring checking. We should adopt an opinionated default even for controversial points like docstring format. Later, deviations from the defaults could be handled `usethis` interfaces.\r\n- We should name each rule family explicitly. We can keep track of new rules added to ruff via the `ruff rule --all --output-format json`, and have a version test which ensures we haven't missed anything. It is tempting to use `\"ALL\"` but this obscures which rules are actually being used. In my view, it is better to name each rule family explicitly, even if this makes the config section longer. This also means we can manually go through each family of rules systematically and not just uncritically adopt new additions.\r\n- We could include rules conditionally based on whether the framework is being used; for example, `NPY` rules could be enabled only when `numpy` is a dependency. The issue with this is that dependencies might change. Even if the framework isn't being used, it doesn't hurt to have the rule enabled. So it's probably not a good idea.\r\n\r\n**Describe alternatives you've considered**\r\nRather than having a strict flag, we could have the strict behaviour by default. The issue with this is that it is probably too much of a departure from people's expectations and might have too many false positives. Compliance with too many rules is burdensome for users who are not familiar with linters, especially if there is not autofix. It is also potentially very controversial regaring which rules to enable, and a maintenance burden. A strict mode would need a good philosophy on rule inclusion/exclusion so it's not just a fully manual process of constantly reviewing new rules and changes to rules.\r\n\r\nI considered the possibility of just using the `ruff` defaults only without any extra rules, but there are just too many useful linters and it seems a shame not to enable them by default, especially when they are mostly autofix and relatively uncontroversial.\r\n\r\n**Testing Strategy**\r\nSame as for `deptry` but also include tests relating to the `pyproject.toml` file contents:\r\n- checking the contents are correct\r\n- checking that `ruff` is able to run in a way that proves it is using the file contents\r\n- checking the associated messages\r\n\r\nAny functions which add/remove contents to/from the `pyproject.toml` file should be tested too.\r\n\r\n**Steps**\r\n- Copy `deptry`'s Tool definition, mutatis mutandis.\r\n- Also copy the `deptry` CLI function, but add a new call to create `pyproject.toml` sections, testing along the way.\r\n\r\n**Acceptance Criteria**\r\nNew `usethis tool ruff` CLI interface is available to add `ruff` including configuration.\r\n","author":{"url":"https://github.com/nathanjmcdougall","@type":"Person","name":"nathanjmcdougall"},"datePublished":"2024-10-18T05:30:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/27/usethis-python/issues/27"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b1357987-491e-0f1a-bc0d-9c7883ac6f99 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F28:418ED:5AED0DF:7ED7028:6A4F95E0 |
| html-safe-nonce | 05d418842571132b886b8197ac1bf1006744207490ca6acb50fc49524c82029f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjI4OjQxOEVEOjVBRUQwREY6N0VENzAyODo2QTRGOTVFMCIsInZpc2l0b3JfaWQiOiI0MjY1NzExMjY5MDUzNDM3NDA4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2ddc61a7616d1450276f2a456167b7f851abf8c9a01bcef7c577931b6db21d4f |
| hovercard-subject-tag | issue:2596457056 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/usethis-python/usethis-python/27/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a8b587c42ce56d29b1462912b4e6e583b9b05dbbb3cec998d11734b3e18821b8/usethis-python/usethis-python/issues/27 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a8b587c42ce56d29b1462912b4e6e583b9b05dbbb3cec998d11734b3e18821b8/usethis-python/usethis-python/issues/27 |
| og:image:alt | Motivation ruff is probably the most popular linter as of late (for good reason) so it's essential we include it in usethis. Summary of desired feature Support the addition of ruff to a project usi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nathanjmcdougall |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/usethis-python/usethis-python git https://github.com/usethis-python/usethis-python.git |
| octolytics-dimension-user_id | 216362695 |
| octolytics-dimension-user_login | usethis-python |
| octolytics-dimension-repository_id | 842189705 |
| octolytics-dimension-repository_nwo | usethis-python/usethis-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 842189705 |
| octolytics-dimension-repository_network_root_nwo | usethis-python/usethis-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width