Skip to content

Commit

Permalink
Add no_comments option to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
pappasam committed Dec 29, 2022
1 parent 9d1f0c5 commit c1f5420
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ Options:
command.

--no-header Deprecated. See --no-header-comments.
--no-comments Remove all comments. Implies no header, footer, inline,

--no-comments Remove all comments. Implies no header, footer, inline,
or block comments.

--no-header-comments Remove a document's leading comments.

--no-footer-comments Remove a document's trailing comments.

--no-inline-comments Remove a document's inline comments.

--no-block-comments Remove a document's block comments.


--spaces-before-comment {1,2,3,4}
The number of spaces before an end of line comment. (default: 1)

--check Check if an original file is changed by the formatter.
Return code 0 means it would not change. Return code 1
means it would change.
Expand All @@ -103,6 +103,7 @@ Please note, that only the below options are supported:
[tool.tomlsort]
all = true
in_place = true
no_comments = true
no_header_comments = true
no_footer_comments = true
no_inline_comments = true
Expand All @@ -114,15 +115,15 @@ ignore_case = true

## Comments

Due to the free form nature of comments, it is hard to include them in a sort in
a generic way that will work for everyone. `toml-sort` deals with four different
Due to the free form nature of comments, it is hard to include them in a sort in
a generic way that will work for everyone. `toml-sort` deals with four different
types of comments. They are all enabled by default, but can be disabled using CLI
switches, in which case comments of that type will be removed from the output.

### Header

The first comments in a document, that are followed by a blank line, are treated
as a header, and will always remain at the top of the document. If there is no
as a header, and will always remain at the top of the document. If there is no
blank line, the comment will be treated as a block comment instead.

```toml
Expand All @@ -135,7 +136,7 @@ title = "The example"

### Footer

Any comments at the end of the document, after the last item in the toml, will be
Any comments at the end of the document, after the last item in the toml, will be
treated as a footer, and will always remain at the bottom of the document.

```toml
Expand All @@ -146,7 +147,7 @@ title = "The example"

### Inline

Inline comments are comments that are at the end of a line where the start of the
Inline comments are comments that are at the end of a line where the start of the
line is a toml item.

```toml
Expand All @@ -155,16 +156,16 @@ title = "The example" # This is a inline comment

### Block

Block comments, are any comments that are on their own line. These comments are treated
as *attached* to the item in the toml that is directly below them, not seperated by whitespace.
Block comments, are any comments that are on their own line. These comments are treated
as _attached_ to the item in the toml that is directly below them, not seperated by whitespace.
These comments can be multiple lines. Inline comments will appear in the sorted output above the
item they were attached to in the input toml.

```toml
# Comment attached to title
title = "The example"

# This comment is an orphan because it
# This comment is an orphan because it
# is seperated from a-section by whitespace

# This comment is attached to a-section
Expand All @@ -187,7 +188,7 @@ from the output document.

title = "The example"

# This comment is an orphan because it
# This comment is an orphan because it
# is seperated from a-section by whitespace

# This comment is attached to a-section
Expand Down
1 change: 1 addition & 0 deletions toml_sort/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def load_config_file() -> Dict[str, Any]:
validate_and_copy(config, clean_config, "all", bool)
validate_and_copy(config, clean_config, "in_place", bool)
validate_and_copy(config, clean_config, "no_header", bool)
validate_and_copy(config, clean_config, "no_comments", bool)
validate_and_copy(config, clean_config, "no_header_comments", bool)
validate_and_copy(config, clean_config, "no_footer_comments", bool)
validate_and_copy(config, clean_config, "no_inline_comments", bool)
Expand Down

0 comments on commit c1f5420

Please sign in to comment.