Commit Graph

526 Commits

Author SHA1 Message Date
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
Adrien Vergé
1f79e62a98 docs: Fix new rstcheck errors
Some YAML snippets from the examples were actually invalid.
2023-11-21 22:27:44 +01:00
Adrien Vergé
8713140e99 yamllint version 1.33.0 2023-11-09 10:32:20 +01:00
Éric Almeida
a26dd0084c
empty-values: Add forbid-in-block-sequences option
Implement forbid-in-block-sequences option for detecting empty list items.
2023-11-09 10:29:01 +01:00
Dimitri Papadopoulos
e1d45c3ae5 CI: Add support for Python 3.12 2023-11-06 10:10:38 +01:00
Dimitri Papadopoulos
f63e56fd98 style: Use f-strings wherever possible
They're faster.
2023-10-06 09:17:33 +02:00
Dimitri Papadopoulos Orfanos
816d575228
style: Apply a couple refurb suggestions
I kept only those improving readability.
2023-09-23 20:46:50 +02:00
Dimitri Papadopoulos
3e643724ce tests: Apply pyupgrade suggestions
* Simplify super() calls
  https://github.com/asottile/pyupgrade#super-calls
* UTF-8 is the default for encode()
  https://github.com/asottile/pyupgrade#encodeutf-8
2023-09-14 12:36:46 +02:00
Dimitri Papadopoulos
41ec303df7 ci: Update GitHub Actions
https://github.com/actions/checkout
2023-09-14 12:36:27 +02:00
Caleb P. Burns
40ce4c21df
Drop support for Python 3.7
Remove support for EoL Python 3.7.

Closes #592.
2023-09-07 15:15:44 +02:00
Dimitri Papadopoulos
a68c3aa69e document-end: Fix spurious "missing document end"
DocumentStartToken is preceded by DirectiveToken.
2023-06-27 11:08:34 +02:00
Nick Cao
7f2c071545
build: Fix license identifier according to license notice in source files 2023-06-22 16:43:36 +02:00
Adrien Vergé
b05e028c58 yamllint version 1.32.0 2023-05-22 18:01:58 +02:00
Georgi Georgiev
e636848ddc
config: Look for configuration file in parent directories
Inspired be ESLint's search, it looks for configuration files in all
parent directories up until it reaches the user's home or root.

closes #571
2023-05-22 17:59:56 +02:00
Adrien Vergé
019c87d36d anchors: Update code style to use single quotes
Like the rest of the project does.
2023-05-10 06:56:11 +02:00
Adrien Vergé
977f4908b5 anchors: Add missing quotes in unused anchor error message
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)
2023-05-10 06:56:11 +02:00
amimas
f874b6607c anchors: Add new option to detect unused 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
2023-05-10 06:42:58 +02:00