Giter VIP home page Giter VIP logo

Comments (6)

paddyroddy avatar paddyroddy commented on August 12, 2024 2

My particular use case can be solved by:

[tool.tomlsort]
all = true
overrides."tool.coverage.paths.source".inline_arrays = false

😁 cheers!

from toml-sort.

jonathangreen avatar jonathangreen commented on August 12, 2024 1

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.

paddyroddy avatar paddyroddy commented on August 12, 2024 1

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?

This looks like a great solution!

from toml-sort.

KyleKing avatar KyleKing commented on August 12, 2024 1

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:

  1. Scan the file for comments
  2. Merge the comment overrides with the config overrides
  3. Sort
  4. 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.

KyleKing avatar KyleKing commented on August 12, 2024

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.

paddyroddy avatar paddyroddy commented on August 12, 2024

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.

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.