542 Commits

Author SHA1 Message Date
Adrien Vergé
e427005b52 cli: Fix TTY test failing on Python 3.14
Since I don't have Python 3.14 on my system (yet), here are the steps I
used to reproduce:

    sudo dnf install python3.14
    python3.14 -m venv /tmp/py3.14
    source /tmp/py3.14/bin/activate
    pip install yaml pathspec
    python3.14 -m unittest discover
    # or
    python3.14 -m unittest tests.test_cli.CommandLineTestCase.test_run_default_format_output_in_tty

This commit fixes that by piping *only* `sys.stdout`, not `sys.stderr`
too. I'm not sure why I wrote this code in 2016 (see commit a2c68fdf),
but the new one makes more sense to me now.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2336947
2025-01-14 08:06:39 +01:00
Adrien Vergé
728656c937 cli: Refactor old test to avoid fcntl
This is a simple preparation for the next commit, to get rid of
low-level `fcntl.fcntl()` calls, since `os.set_blocking()` now exists
(since Python 3.5).
2025-01-14 08:06:39 +01:00
Adrien Vergé
c20f191bc1 CI: Add support for Python 3.13
And drop support for Python 3.8 (end-of-life since 2024-10-07).
2025-01-13 19:21:33 +01:00
Dimitri Papadopoulos
e1182968d2 style: Apply ruff rule RUF039
RUF039 First argument to `re.compile()` is not raw string
2024-12-18 01:54:01 +01:00
Adrien Vergé
8513d9b97d docs: Import 'yamllint.config' rather than 'yamllint'
Since yamllint version 0.5.2 (in 2016, just after yamllint was created)
this example in documentation doesn't work. Indeed, commit dbbecb5
(which aimed to solve another problem) removed the ability to import
yamllint submodules directly.

This commit makes it clearer inside documentation.

Fixes https://github.com/adrienverge/yamllint/issues/698
2024-11-20 18:27:38 +01:00
hituzi no sippo
95e17b33dc float-values: Fix indentation in documentation 2024-10-01 20:43:50 +02:00
hituzi no sippo
f0c0c7586b docs: fix position of backquotes 2024-09-18 08:35:53 +02:00
Dimitri Papadopoulos
99fb29aead build: remove unused noqa 2024-07-08 17:36:12 +02:00
Adrien Vergé
81e9f98ffd yamllint version 1.35.1 v1.35.1 2024-02-16 11:48:35 +01:00
Adrien Vergé
9235c68496 cli: Restore ignoration of files passed as command-line arguments
Commit 2344380 "Cleanly skip broken symlinks that are ignored" fixed a
problem on symbolic links but also introduced a change on how ignored
files should be treated, depending on whether they're explicitely passed
as command-line arguments or not [^1].

This change is annoying for users that dynamically build the list of
files to pass as arguments, e.g. [^2]:

    find -name '*\.yaml' | xargs yamllint

The present commit adds unit tests for `yamllint [FILES]...` and
`yamllint --list-files [FILES]...`, that passed with previous version
1.34.0, and restore the behavior of this version.

As a result it also reverts the API change of commit 2344380 on
`yamllint.linter.run(stream, config)`.

[^1]: https://github.com/adrienverge/yamllint/issues/657#issuecomment-1948009315
[^2]: https://github.com/adrienverge/yamllint/issues/657#issuecomment-1948093680
2024-02-16 11:48:22 +01:00
Adrien Vergé
3a13803fb0 yamllint version 1.35.0 v1.35.0 2024-02-15 09:59:18 +01:00
Adrien Vergé
2344380353 cli: Cleanly skip broken symlinks that are ignored
Before this commit, yamllint would output "[Errno 2] No such file or
directory" when running on a directory which contained a broken symbolic
link, even if the file is set to be ignored in yamllint configuration.

This commit fixes that, and adds corresponding tests.

As a side effect this changes `yamllint.linter.run(stream, config)`, so
tools that would use this API need to filter ignored files beforehand.

Fixes https://github.com/adrienverge/yamllint/issues/399
2024-02-15 09:54:11 +01:00
Adrien Vergé
f66855bf2d build: Restore official Read the Docs theme
https://yamllint.readthedocs.io/en/v1.34.0/ was rendered differently
than previous versions, very probably due to change of commit ca7f8b9
"Migrate to use .readthedocs.yaml for docs generation".

Let's restore the `sphinx_rtd_theme` theme.
2024-02-06 15:54:53 +01:00
Adrien Vergé
dd99a1c965 yamllint version 1.34.0 v1.34.0 2024-02-06 09:54:04 +01:00
Adrien Vergé
01df5bf038 truthy: Adapt forbidden values based on YAML version
Specification of YAML ≤ 1.1 has 22 boolean values:

    y     | Y            | n     | N
    yes   | Yes   | YES  | no    | No    | NO
    true  | True  | TRUE | false | False | FALSE
    on    | On    | ON   | off   | Off   | OFF

Whereas YAML 1.2 spec recognizes only 6 [^1]:

    true  | True  | TRUE | false | False | FALSE

For documents that explicit state their YAML spec version at the top of
the document, let's adapt the list of forbidden values.

In the future, we should:
- implement a configuration option to declare the default YAML spec
  version, e.g. `default-yaml-spec-version: 1.2`,
- consider making 1.2 the default in a future release (this would be a
  slight breaking change, but yamllint always tried to be
  1.2-compatible).
- consider adapting yamllint to other 1.1 vs. 1.2 differences [^2].

Solves: https://github.com/adrienverge/yamllint/issues/587

Related to: #559 #540 #430 #344 #247 #232 #158

[^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution
[^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
2024-02-06 09:45:33 +01:00
Dimitri Papadopoulos
9931ad699c Undo ruff changes that conflict with flake8 2024-02-02 10:05:14 +01:00
Dimitri Papadopoulos
57d2691713 Revert replacement of flake8 with ruff
Start with reverting parts of commit 26be794 in #629 related to config
and CI jobs.
2024-02-02 10:05:14 +01:00
Dimitri Papadopoulos
3cb3a20385 build: enable pygrep-hooks in ruff 2024-01-20 08:58:55 +01:00
Dimitri Papadopoulos
024b5367b6 style: silence pygrep-hooks warnings
PGH004 Use specific rule codes when using `noqa`
2024-01-20 08:58:55 +01:00
Dimitri Papadopoulos
329500a1bc build: enable tryceratops rules in ruff
Ignore this rule for now:
TRY003 Avoid specifying long messages outside the exception class
2024-01-20 08:54:25 +01:00
Dimitri Papadopoulos
f68cae3f1e style: silence tryceratops warning
TRY300 Consider moving this statement to an `else` block
2024-01-20 08:54:25 +01:00
Dimitri Papadopoulos
47bbb26b42 style: apply flake8-copyright rules
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
2024-01-20 08:54:00 +01:00
gardar
0d7ae7bf6b style: fix section heading
Signed-off-by: gardar <gardar@users.noreply.github.com>
2024-01-13 07:19:00 +01:00
gardar
10d6cb3a2c fix: nicer line splits
Co-authored-by: Adrien Vergé <adrienverge@gmail.com>
2024-01-13 07:19:00 +01:00
gardar
0cce1a7b14 fix: code example indents
Signed-off-by: gardar <gardar@users.noreply.github.com>
2024-01-13 07:19:00 +01:00
gardar
7b26148217 fix: use correct GitLab name
Signed-off-by: gardar <gardar@users.noreply.github.com>
2024-01-13 07:19:00 +01:00
gardar
1c1569554e fix: typo
Signed-off-by: gardar <gardar@users.noreply.github.com>
2024-01-13 07:19:00 +01:00
gardar
a03d4a0c4e fix: line-length
Co-authored-by: Adrien Vergé <adrienverge@gmail.com>
2024-01-13 07:19:00 +01:00
gardar
420c814ed9 fix: line-length lint
Signed-off-by: gardar <gardar@users.noreply.github.com>
2024-01-13 07:19:00 +01:00
gardar
06581793b3 docs: add GitLab CI / Code Climate example
Signed-off-by: gardar <gardar@users.noreply.github.com>
2024-01-13 07:19:00 +01:00
Dimitri Papadopoulos
fd8ddeef8b build: enable pyupgrade rules in ruff 2024-01-09 07:53:22 +01:00
Dimitri Papadopoulos
d20aa6d302 build: enable flake8-bugbear rules in ruff 2024-01-08 07:57:06 +01:00
Dimitri Papadopoulos
5969b4f29e style: silence bugbear warning
B904 Within an `except` clause, raise exceptions with
     `raise ... from err` or `raise ... from None` to
     distinguish them from errors in exception handling
2024-01-08 07:57:06 +01:00
Dimitri Papadopoulos
3e126942e9 style: silence bugbear warning
B007 Loop control variable `dirnames` not used within loop body
2024-01-08 07:57:06 +01:00
Dimitri Papadopoulos
254a218782 style: Apply new isort (I) rules to existing code 2024-01-08 07:27:06 +01:00
Dimitri Papadopoulos
d1b0eeacb6 build: Replace flake8 with ruff
Add isort (I) rules to the default set of ruff rules, as a replacement
for flake8-import-order.
2024-01-08 07:27:06 +01:00
Dimitri Papadopoulos
1d65ab62cb style: apply ruff suggestion
Fixes the only error reported by ruff using default settings:
	E721 Do not compare types, use `isinstance()`
2024-01-04 17:15:33 +01:00
Dimitri Papadopoulos
ef61384491 CI: Update GitHub Actions
https://github.com/actions/setup-python
2024-01-04 17:15:07 +01:00
Dimitri Papadopoulos
f977ae25bf style: Use f-strings wherever possible 2024-01-04 17:14:11 +01:00
Dimitri Papadopoulos
cebc9c1fcc cli: remove format() left over in f63e56f
- The format() call was missing in the first place for `filename`.
- Other format() calls are obviously useless now that f-strings
  perform string interpolation.
2024-01-04 17:13:45 +01:00
Jason Yundt
3513ec175d CI: Don’t skip test_run_with_user_global_config_file
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.
2024-01-04 17:13:23 +01:00
Jason Yundt
92688d2bb0 tests: Delete env vars that could interfere
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)>
2024-01-04 17:13:23 +01:00
Jason Yundt
f3adc585d2 tests: Don’t bother restoring HOME
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>
2024-01-04 17:13:23 +01:00
Jason Yundt
152ba20f33 tests: Prevent “unittest --buffer” from crashing
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)>
2023-12-30 19:34:28 +01:00
Adrien Vergé
52b40c8153 tests: Remove test skipping for Python < 3.7
Yamllint dropped support for Python 3.6 in september 2022.
2023-12-30 18:28:25 +01:00
Henry Gessau
3288d0596e quoted-strings: Add check-keys option 2023-12-11 14:23:23 +01:00
Travis Bale
e5fdfd2ae5 key-duplicates: Add forbid-duplicated-merge-keys option 2023-12-10 18:54:15 +01:00
Rob Herring
0dcf5f4175 quoted-strings: Fix only-when-needed in flow maps and sequences
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
2023-11-22 22:04:25 +01:00
Adrien Vergé
ca7f8b972c build: Migrate to use .readthedocs.yaml for docs generation
As explained on https://readthedocs.org/projects/yamllint/:
> Your builds will stop working soon!
> Configuration files will soon be required by projects, and will no
> longer be optional. Read our blog post to create one and ensure your
> project continues building successfully.

https://blog.readthedocs.com/migrate-configuration-v2/
2023-11-21 22:39:14 +01:00
ndrwnaguib
ec153761dc config: validate ignore-from-file in validate_rule_conf
This fixes commit 2f8ad70 "config: Implement for `ignore-from-file`
option" that lacked rule config validation.

Closes https://github.com/adrienverge/yamllint/issues/542.
2023-11-21 22:30:18 +01:00