CPY001 Missing copyright notice at top of file
Do not apply this rule to empty files:
tests/rules/__init__.py
and to files generated by tools:
docs/conf.py
B904 Within an `except` clause, raise exceptions with
`raise ... from err` or `raise ... from None` to
distinguish them from errors in exception handling
- The format() call was missing in the first place for `filename`.
- Other format() calls are obviously useless now that f-strings
perform string interpolation.
Before this change one of yamllint’s tests wasn’t being run on GitHub
Actions Runners because the HOME environment variable couldn’t be
overridden. I just tested it, and it looks like the HOME variable can be
overridden now, so that test no longer needs to be skipped.
Several environment variables can influence which config file yamllint
chooses to use [1]. Before this change, if you set those environment
variables and ran “python -m unittest discover”, then you could cause
certain tests to use the wrong config file and fail.
Fixes#621.
[1]: <152ba20f33/yamllint/cli.py (L180-L188)>
Some unittests set environment variables, but then delete them as part
of their cleanup process. Deleting them is OK. Any test that needs an
environment variable should set that environment variable itself. Once
the test process stops, any changes made to the environment will be lost
[1].
Before this change, there was one location where an environment variable
was restored to its original value instead of deleted. Restoring that
variable was unnecessary.
This commit was created to prepare for a future commit which will delete
HOME before any of the tests even start. Without this change, that
future change would crash. You can’t restore a variable that’s been
deleted.
Fixes#605.
[1]: <https://stackoverflow.com/q/716011/7593853>
Before this change, if certain tests were failing in certain ways, then
running “python -m unittest --buffer” would cause an AttributeError in
the unittest module itself.
Here’s what unittest does when you use the --buffer argument:
1. It sets sys.stdout and sys.stderr to StringIOs [1].
2. It runs a test.
3. If the test failed, it runs getvalue() on sys.stdout and sys.stderr
to get data from its StringIOs.
tests/test_cli.py has its own RunContext class that does something
similar. Before this change, here’s what could happen:
1. unittest sets sys.stdout and sys.stderr to StringIOs.
2. unittest runs a test that uses RunContext.
3. A RunContext gets entered. It sets sys.stdout and sys.stderr to its
own StringIOs.
4. The RunContext gets exited. It sets sys.stdout and sys.stderr to
sys.__stdout__ and sys.__stderr__.
5. The test fails.
6. unittest assumes that sys.stdout is still set to one of its
StringIOs, and runs sys.stdout.getvalue().
7. unittest crashes with this error:
AttributeError: '_io.TextIOWrapper' object has no attribute 'getvalue'
[1]: <2305ca5144/Lib/unittest/result.py (L65)>
[2]: <2305ca5144/Lib/unittest/result.py (L87)>
Flow maps and sequences need quotes if the values contain any of the
flow tokens ({}, [], ','). However, yamllint generates false positives
in these cases:
$ yamllint -d 'rules: {quoted-strings: {required: only-when-needed}}' - <<<'field: ["string[bracket]"]'
1:9 error string value is redundantly quoted with any quotes (quoted-strings)
To fix this, track when inside a flow map/sequence and skip the quoting
checks except for the quoting type.
Closes#516
Existing `anchors` options use quotes around the anchor name:
2:3 error found undeclared alias "unknown" (anchors)
4:3 error found duplicated anchor "dup" (anchors)
Let's do the same in the newly-added option `forbid-unused-anchors`:
5:3 error found unused anchor "not used" (anchors)
According to the YAML specification [^1]:
- > An anchored node need not be referenced by any alias nodes
This means that it's OK to declare anchors but don't have any alias
referencing them. However users could want to avoid this, so a new
option (e.g. `forbid-unused-anchors`) is implemented in this change.
It is disabled by default.
[^1]: https://yaml.org/spec/1.2.2/#692-node-anchors