Comments (6)
My particular use case can be solved by:
[tool.tomlsort]
all = true
overrides."tool.coverage.paths.source".inline_arrays = false
😁 cheers!
from toml-sort.
I've thought about doing something like this by allowing config overrides either per key or per table.
Something like this might work for config file syntax:
[tool.tomlsort.overrides]
tool.coverage.sort_inline_arrays = false
Where sort_inline_arrays
could be any of the configuration options currently available.
I think that would provide a lot of flexibility when specific tables need different sort options.
from toml-sort.
I like the idea of a comment and I'm planning on working on #42. Using a configuration item seems like it would be hard to specify what the rule applies to, while a comment is very clear and a well established pattern for Python tools (flake8, mypy, etc.).
What do you think of using
# toml-sort: pin
for the comment?With the comment, you could write:
[tool.coverage] paths.source = [ "src", # toml-sort: pin ".tox*/*/lib/python*/site-packages", ]And in my case:
[tool.poetry.dependencies] python = "^3.11" # toml-sort: pin antigravity = "^0.1"The relative order of pins to eachother would be preserved and they would always be moved to the top:
[tool.coverage] paths.source = [ ".tox*/*/lib/python*/site-packages", "src", # toml-sort: pin "another", # toml-sort: pin ]Where
another
is pinned aftersrc
, so that after sorting, this would be the end result:[tool.coverage] paths.source = [ "src", # toml-sort: pin "another", # toml-sort: pin ".tox*/*/lib/python*/site-packages", ]vs. without the comments:
[tool.coverage] paths.source = [ ".tox*/*/lib/python*/site-packages", "another", "src", ]To selectively ignore an entire array, maybe we could add another type of comment code:
[tool.coverage] paths.source = [ # toml-sort: no-sort ".tox*/*/lib/python*/site-packages", "src", "another", ]Any opinions on this approach? Is this the desired behavior?
This looks like a great solution!
from toml-sort.
I almost think we might want both options:
- Config: one source of truth for how files should be sorted, but requires a configuration file because specifying by CLI would be cumbersome
- Comments: easy to specify per file, but repetitive, especially for defaults like
tool.poetry.dependencies.python
and will stop working if the array is moved inline
Maybe the new logic in toml-sort
could:
- Scan the file for comments
- Merge the comment overrides with the config overrides
- Sort
- Apply the overrides
Maybe we could borrow the concept of known_first_party
from isort
with sort_first
and expand the sort_inline_arrays
to be a more general no_sort
. If so, the configuration file could look something like:
[tool.tomlsort.overrides]
no_sort = ["tool.coverage.paths.source"]
[tool.tomlsort.overrides.sort_first]
tool.poetry.dependencies = ["python"]
The benefit of a more general no_sort
is that it could also apply to tables. For example, if you didn't want the poetry dependencies to be sorted at all (maybe you already use poetry-sort
plugin)
[tool.tomlsort.overrides]
no_sort = ["tool.poetry.dependencies"]
And with sort_first
, you could also specify multiple ordered values:
[tool.tomlsort.sort_first]
tool.coverage.paths.source = ["src", "another"]
from toml-sort.
I like the idea of a comment and I'm planning on working on #42. Using a configuration item seems like it would be hard to specify what the rule applies to, while a comment is very clear and a well established pattern for Python tools (flake8, mypy, etc.).
What do you think of using # toml-sort: pin
for the comment?
With the comment, you could write:
[tool.coverage]
paths.source = [
"src", # toml-sort: pin
".tox*/*/lib/python*/site-packages",
]
And in my case:
[tool.poetry.dependencies]
python = "^3.11" # toml-sort: pin
antigravity = "^0.1"
The relative order of pins to eachother would be preserved and they would always be moved to the top:
[tool.coverage]
paths.source = [
".tox*/*/lib/python*/site-packages",
"src", # toml-sort: pin
"another", # toml-sort: pin
]
Where another
is pinned after src
, so that after sorting, this would be the end result:
[tool.coverage]
paths.source = [
"src", # toml-sort: pin
"another", # toml-sort: pin
".tox*/*/lib/python*/site-packages",
]
vs. without the comments:
[tool.coverage]
paths.source = [
".tox*/*/lib/python*/site-packages",
"another",
"src",
]
To selectively ignore an entire array, maybe we could add another type of comment code:
[tool.coverage]
paths.source = [ # toml-sort: no-sort
".tox*/*/lib/python*/site-packages",
"src",
"another",
]
Any opinions on this approach? Is this the desired behavior?
from toml-sort.
I've thought about doing something like this by allowing config overrides either per key or per table.
Something like this might work for config file syntax:
[tool.tomlsort.overrides] tool.coverage.sort_inline_arrays = falseWhere
sort_inline_arrays
could be any of the configuration options currently available.I think that would provide a lot of flexibility when specific tables need different sort options.
That would be really cool, but I sense a bit harder to implement than the comment option? I guess in my case I'd really be looking for tool.coverage.paths.source.sort_inline_arrays = false
but that might be even harder to implement.
from toml-sort.
Related Issues (20)
- Option to not sort array contents HOT 2
- in_place = true doesn't work in pre-commit HOT 4
- Not compatible with tomlkit 0.8.0 HOT 1
- Python as first item in "tool.poetry.dependencies" HOT 1
- Better error message for not using tables. HOT 2
- Files that only contain comments are doubled HOT 1
- Trailing whitespace is added to blank comment lines
- Doesn't recognise new lines in inline tables
- Is it possible to silence `jinja2` templating warning?
- Option to prevent deletion of orphan comments HOT 2
- Newlines are always converted to platform default
- Leading spaces in comments should be preserved
- Don't write file if nothing was changed
- Docs request: "default" config
- more line spacing (optional)?
- How to exclude/skip a file (e.g. `poetry.lock`)? HOT 2
- Is it possible to configure with a non-`pyproject.toml` file?
- Bug: toml-sort moves and entries to different groups
- toml-sort breaks ruff config by removing tool.ruff. prefix from sections HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from toml-sort.