Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
- run:
pip install flake8 flake8-import-order sphinx sphinx_rtd_theme
pip install flake8 flake8-import-order ruff sphinx sphinx_rtd_theme
rstcheck[sphinx] doc8
- run: pip install .
- run: flake8 .
- run: ruff check --output-format=github
- run: doc8 $(git ls-files '*.rst')
- run: rstcheck --ignore-directives automodule $(git ls-files '*.rst')
- run: yamllint --strict $(git ls-files '*.yaml' '*.yml')
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from unittest.mock import MagicMock

sys.path.insert(0, os.path.abspath('..'))
from yamllint import __copyright__, APP_NAME, APP_VERSION # noqa: E402
from yamllint import APP_NAME, APP_VERSION, __copyright__ # noqa: E402

# -- General configuration ------------------------------------------------

Expand Down
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dev = [
"flake8",
"flake8-import-order",
"rstcheck[sphinx]",
"ruff",
"sphinx",
]

Expand All @@ -51,3 +52,49 @@ yamllint = ["conf/*.yaml"]

[tool.setuptools.dynamic]
version = {attr = "yamllint.__version__"}

[tool.ruff]
line-length = 79

[tool.ruff.lint]
extend-select = [
"B",
"C4",
"EXE",
"FA",
"ISC",
"LOG",
"G",
"PIE",
"PYI",
"SIM",
"FLY",
"I",
"PERF",
"W",
"PGH",
"PLC",
"PLE",
"UP",
"FURB",
"RUF",
]
ignore = [
"B028", # No explicit `stacklevel` keyword argument found
"SIM102", # Use a single `if` statement instead of nested `if` statements
"SIM103", # Return the negated condition directly
"SIM105", # Use `contextlib.suppress(KeyError)` instead of `try`-`except`-`pass`
"SIM108", # Use ternary operator instead of `if`-`else`-block
"SIM114", # Combine `if` branches using logical `or` operator
"SIM117", # Use a single `with` statement with multiple contexts
"FURB105", # Unnecessary empty string passed to `print`
"RUF001", # String contains ambiguous Unicode characters
"RUF002", # Docstring contains ambiguous Unicode characters
"RUF003", # Comment contains ambiguous Unicode characters
"RUF005", # Consider unpacking instead of concatenation
"RUF100", # Unused `noqa` directive
]

[tool.ruff.lint.isort]
force-sort-within-sections = true
known-third-party = ["tests"]
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
for name in env_vars_that_could_interfere_with_tests:
try:
del os.environ[name]
except KeyError:
except KeyError: # noqa: PERF203
pass
3 changes: 1 addition & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import codecs
from codecs import CodecInfo
import contextlib
from io import StringIO
import os
Expand All @@ -23,14 +24,12 @@
import tempfile
import unittest
import warnings
from codecs import CodecInfo

import yaml

from yamllint import linter
from yamllint.config import YamlLintConfig


# Encoding related stuff:
UTF_CODECS = (
'utf_32_be',
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/test_line_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def test_non_breakable_word(self):
conf, problem=(2, 21))

def test_non_breakable_inline_mappings(self):
conf = 'line-length: {max: 20, ' \
'allow-non-breakable-inline-mappings: true}'
conf = ('line-length: {max: 20, '
'allow-non-breakable-inline-mappings: true}')
self.check('---\n'
'long_line: http://localhost/very/very/long/url\n'
'long line: http://localhost/very/very/long/url\n', conf)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
register_test_codecs,
temp_workspace,
temp_workspace_with_files_in_many_codecs,
unregister_test_codecs
unregister_test_codecs,
)

from yamllint import cli, config
Expand Down Expand Up @@ -624,7 +624,7 @@ def test_run_read_from_stdin(self):
file.write(
'I am a string\n'
'therefore: I am an error\n')
with open(stdin_file_path, mode='r', encoding='utf-8') as file:
with open(stdin_file_path, encoding='utf-8') as file:
# prepares stdin with an invalid yaml string so that we can
# check for its specific error, and be assured that stdin was
# read
Expand Down Expand Up @@ -844,7 +844,7 @@ def valid_encodings_stdin_test_helper(
# We purposely choose the wrong text encoding here because the text
# encoding shouldn’t matter. yamllint should completely ignore the
# text encoding of stdin.
with open(path, mode="r", encoding="cp037") as file:
with open(path, encoding="cp037") as file:
sys.stdin = file
with RunContext(self) as ctx:
cli.run(('-c', config_path, '-'))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from io import StringIO
import itertools
import os
import shutil
import sys
import tempfile
import unittest
from io import StringIO

from tests.common import (
RunContext,
build_temp_workspace,
register_test_codecs,
RunContext,
unregister_test_codecs,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def test_auto_decode_with_strings_encoded_at_runtime(self):
codec,
string
)
except UnicodeDecodeError:
except UnicodeDecodeError: # noqa: PERF203
at_least_one_decode_error = True
self.assertTrue(
at_least_one_decode_error,
Expand Down
6 changes: 3 additions & 3 deletions yamllint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def standard_color(problem, filename):

@staticmethod
def github(problem, filename):
line = f'::{problem.level} file={filename},' \
f'line={problem.line},col={problem.column}' \
f'::{problem.line}:{problem.column} '
line = (f'::{problem.level} file={filename},'
f'line={problem.line},col={problem.column}'
f'::{problem.line}:{problem.column} ')
if problem.rule:
line += f'[{problem.rule}] '
line += problem.desc
Expand Down
2 changes: 1 addition & 1 deletion yamllint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import pathspec
import yaml

import yamllint.rules
from yamllint import decoder
import yamllint.rules


class YamlLintConfigError(Exception):
Expand Down
8 changes: 4 additions & 4 deletions yamllint/rules/indentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ def detect_indent(base_indent, next):

if found_indentation != expected:
if expected < 0:
message = f'wrong indentation: expected at least ' \
f'{found_indentation + 1}'
message = (f'wrong indentation: expected at least '
f'{found_indentation + 1}')
else:
message = f'wrong indentation: expected {expected} but ' \
f'found {found_indentation}'
message = (f'wrong indentation: expected {expected} but '
f'found {found_indentation}')
yield LintProblem(token.start_mark.line + 1,
found_indentation + 1, message)

Expand Down
2 changes: 1 addition & 1 deletion yamllint/rules/key_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
d:
"""

import re
from locale import strcoll
import re

import yaml

Expand Down
10 changes: 6 additions & 4 deletions yamllint/rules/line_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ def check_inline_mapping(line):


def check(conf, line):
if line.end - line.start > conf['max']:
max_length = conf['max']
length = line.end - line.start
if length > max_length:
conf['allow-non-breakable-words'] |= \
conf['allow-non-breakable-inline-mappings']
if conf['allow-non-breakable-words']:
Expand All @@ -152,6 +154,6 @@ def check(conf, line):
check_inline_mapping(line)):
return

yield LintProblem(line.line_no, conf['max'] + 1,
'line too long (%d > %d characters)' %
(line.end - line.start, conf['max']))
yield LintProblem(line.line_no, max_length + 1,
f'line too long'
f' ({length} > {max_length} characters)')
4 changes: 2 additions & 2 deletions yamllint/rules/quoted_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def check(conf, token, prev, next, nextnext, context):
is_extra_allowed = any(re.search(r, token.value)
for r in conf['extra-allowed'])
if not (is_extra_required or is_extra_allowed):
msg = f"string {node} is redundantly quoted with " \
f"{quote_type} quotes"
msg = (f"string {node} is redundantly quoted with "
f"{quote_type} quotes")

# But when used need to match config
elif (token.style and
Expand Down
2 changes: 1 addition & 1 deletion yamllint/rules/trailing_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
this document contains """ """
trailing spaces
on lines 1 and 3 """ """
"""
""" # noqa: ISC001


import string
Expand Down
Loading