-
Notifications
You must be signed in to change notification settings - Fork 283
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
Automatically detect character encoding of YAML files and ignore files #630
Open
Jayman2000
wants to merge
6
commits into
adrienverge:master
Choose a base branch
from
Jayman2000:auto-detect-encoding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f5cf29
tests: Use correct encoding for path
Jayman2000 806d79f
tests: Restore stdout
Jayman2000 d0fc380
decoder: Autodetect encoding of YAML files
Jayman2000 65d1347
decoder: Autodetect encoding for ignore-from-file
Jayman2000 7a7fa27
tests: Stop using open()’s default encoding
Jayman2000 e14f401
CI: Fail when open()’s default encoding is used
Jayman2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Character Encoding Override | ||
=========================== | ||
|
||
When yamllint reads a file, it will try to automatically detect that file’s | ||
character encoding. In order for the automatic detection to work properly, | ||
files must follow these two rules (see `this section of the YAML specification | ||
for details <https://yaml.org/spec/1.2.2/#52-character-encodings>`_): | ||
|
||
* The file must be encoded in UTF-8, UTF-16 or UTF-32. | ||
|
||
* The file must begin with either a byte order mark or an ASCII character. | ||
|
||
Previous versions of yamllint did not try to autodetect the character encoding | ||
of files. Previous versions of yamllint assumed that files used the current | ||
locale’s character encoding. This meant that older versions of yamllint would | ||
sometimes correctly decode files that didn’t follow those two rules. For the | ||
sake of backwards compatibility, the current version of yamllint allows you to | ||
disable automatic character encoding detection by setting the | ||
``YAMLLINT_FILE_ENCODING`` environment variable. If you set the | ||
``YAMLLINT_FILE_ENCODING`` environment variable to the `the name of one of | ||
Python’s standard character encodings | ||
<https://docs.python.org/3/library/codecs.html#standard-encodings>`_, then | ||
yamllint will use that character encoding instead of trying to autodetect the | ||
character encoding. | ||
|
||
The ``YAMLLINT_FILE_ENCODING`` environment variable should only be used as a | ||
stopgap solution. If you need to use ``YAMLLINT_FILE_ENCODING``, then you | ||
should really update your YAML files so that their character encoding can | ||
automatically be detected, or else you may run into compatibility problems. | ||
Future versions of yamllint may remove support for the | ||
``YAMLLINT_FILE_ENCODING`` environment variable, and other YAML processors may | ||
misinterpret your YAML files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,21 @@ or: | |
|
||
.. note:: However, this is mutually exclusive with the ``ignore`` key. | ||
|
||
.. note:: Files on the ``ignore-from-file`` list should use either UTF-8, | ||
UTF-16 or UTF-32. Additionally, they should start with either an ASCII | ||
character or a byte order mark. | ||
|
||
If you have an ignore file that doesn’t follow those two rules, then you can | ||
set the ``YAMLLINT_FILE_ENCODING`` environment variable to the name of the | ||
character encoding that you want yamllint to use for ignore files. | ||
Specifically, ``YAMLLINT_FILE_ENCODING`` should be set to `the name of one | ||
of Python’s standard character encodings | ||
<https://docs.python.org/3/library/codecs.html#standard-encodings>`_. Please | ||
note, this should only be used as a temporary solution in order to make it | ||
easier to migrate from older versions of yamllint to newer versions of | ||
yamllint. See :doc:`Character Encoding Override | ||
<character_encoding_override>` for details. | ||
|
||
Comment on lines
+231
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth mentioning here? Why not, you decide! If you keep it, maybe we can simplify it like this? .. note:: Files on the ``ignore-from-file`` list should use either UTF-8, UTF-16
or UTF-32. See :doc:`Character Encoding Override
<character_encoding_override>` for details and wordarounds. |
||
If you need to know the exact list of files that yamllint would process, | ||
without really linting them, you can use ``--list-files``: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ Table of contents | |
development | ||
text_editors | ||
integration | ||
character_encoding_override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea:
(this goes along with my next comment ↓)