Skip to content

Commit 84bae0e

Browse files
committed
ruff format and zizmor in pre-commit
1 parent 7aeddc1 commit 84bae0e

31 files changed

Lines changed: 621 additions & 393 deletions

‎.pre-commit-config.yaml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ repos:
1616
args: [--fix, lf]
1717
- id: trailing-whitespace
1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.16.9
19+
rev: "v0.16.9"
2020
hooks:
21-
- id: ruff
21+
- id: ruff-check
2222
args: [--fix, --exit-non-zero-on-fix]
23+
- id: ruff-format
24+
- repo: https://github.com/zizmorcore/zizmor-pre-commit
25+
rev: v1.30.1
26+
hooks:
27+
- id: zizmor
28+
args: [--pedantic]

‎docs/conf.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ def _resolve_broken_refs(app, env, node, contnode):
5353
if node["reftarget"].startswith("referencing."): # :( :( :( :( :(
5454
node["reftype"] = "data"
5555
from sphinx.ext import intersphinx
56+
5657
return intersphinx.resolve_reference_in_inventory(
57-
env, "referencing", node, contnode,
58+
env,
59+
"referencing",
60+
node,
61+
contnode,
5862
)
5963

6064
kind, target = _TYPE_ALIASES.get(node["reftarget"], (None, None))

‎jsonschema/__init__.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
validate a given instance under a schema, and will create a validator
99
for you.
1010
"""
11+
1112
import warnings
1213

1314
from jsonschema._format import FormatChecker
@@ -35,9 +36,11 @@ def __getattr__(name):
3536
)
3637

3738
from importlib import metadata
39+
3840
return metadata.version("jsonschema")
3941
elif name == "RefResolver":
4042
from jsonschema.validators import _RefResolver
43+
4144
warnings.warn(
4245
_RefResolver._DEPRECATION_MESSAGE,
4346
DeprecationWarning,
@@ -53,6 +56,7 @@ def __getattr__(name):
5356
stacklevel=2,
5457
)
5558
from jsonschema.exceptions import ErrorTree
59+
5660
return ErrorTree
5761
elif name == "FormatError":
5862
warnings.warn(
@@ -63,6 +67,7 @@ def __getattr__(name):
6367
stacklevel=2,
6468
)
6569
from jsonschema.exceptions import FormatError
70+
6671
return FormatError
6772
elif name == "Validator":
6873
warnings.warn(
@@ -73,9 +78,11 @@ def __getattr__(name):
7378
stacklevel=2,
7479
)
7580
from jsonschema.protocols import Validator
81+
7682
return Validator
7783
elif name == "RefResolutionError":
7884
from jsonschema.exceptions import _RefResolutionError
85+
7986
warnings.warn(
8087
_RefResolutionError._DEPRECATION_MESSAGE,
8188
DeprecationWarning,

‎jsonschema/__main__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
The jsonschema CLI is now deprecated in favor of check-jsonschema.
33
"""
4+
45
from jsonschema.cli import main
56

67
main()

‎jsonschema/_format.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def __repr__(self):
5555
return f"<FormatChecker checkers={sorted(self.checkers)}>"
5656

5757
def checks[F: _FormatCheckCallable](
58-
self, format: str, raises: _RaisesType = (),
58+
self,
59+
format: str,
60+
raises: _RaisesType = (),
5961
) -> Callable[[F], F]:
6062
"""
6163
Register a decorated function as validating a new format.
@@ -85,7 +87,9 @@ def _checks(func: F) -> F:
8587

8688
@classmethod
8789
def cls_checks[F: _FormatCheckCallable](
88-
cls, format: str, raises: _RaisesType = (),
90+
cls,
91+
format: str,
92+
raises: _RaisesType = (),
8993
) -> Callable[[F], F]:
9094
warnings.warn(
9195
(
@@ -100,7 +104,9 @@ def cls_checks[F: _FormatCheckCallable](
100104

101105
@classmethod
102106
def _cls_checks[F: _FormatCheckCallable](
103-
cls, format: str, raises: _RaisesType = (),
107+
cls,
108+
format: str,
109+
raises: _RaisesType = (),
104110
) -> Callable[[F], F]:
105111
def _checks(func: F) -> F:
106112
cls.checkers[format] = (func, raises)
@@ -488,7 +494,7 @@ def is_relative_json_pointer(instance: object) -> bool:
488494
# A non-negative-integer prefix of ASCII digits (%x30-39), which is
489495
# either "0" or has no leading "0".
490496
rest = instance.lstrip(string.digits)
491-
prefix = instance[:len(instance) - len(rest)]
497+
prefix = instance[: len(instance) - len(rest)]
492498
if not prefix:
493499
return False
494500
if len(prefix) > 1 and prefix[0] == "0":

‎jsonschema/_keywords.py‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ def patternProperties(validator, patternProperties, instance, schema):
2121
for k, v in instance.items():
2222
if re.search(pattern, k):
2323
yield from validator.descend(
24-
v, subschema, path=k, schema_path=pattern,
24+
v,
25+
subschema,
26+
path=k,
27+
schema_path=pattern,
2528
)
2629

2730

@@ -204,18 +207,14 @@ def maxItems(validator, mI, instance, schema):
204207

205208

206209
def uniqueItems(validator, uI, instance, schema):
207-
if (
208-
uI
209-
and validator.is_type(instance, "array")
210-
and not uniq(instance)
211-
):
210+
if uI and validator.is_type(instance, "array") and not uniq(instance):
212211
yield ValidationError(f"{instance!r} has non-unique elements")
213212

214213

215214
def pattern(validator, patrn, instance, schema):
216-
if (
217-
validator.is_type(instance, "string")
218-
and not re.search(patrn, instance)
215+
if validator.is_type(instance, "string") and not re.search(
216+
patrn,
217+
instance,
219218
):
220219
yield ValidationError(f"{instance!r} does not match {patrn!r}")
221220

@@ -262,7 +261,9 @@ def dependentSchemas(validator, dependentSchemas, instance, schema):
262261
if property not in instance:
263262
continue
264263
yield from validator.descend(
265-
instance, dependency, schema_path=property,
264+
instance,
265+
dependency,
266+
schema_path=property,
266267
)
267268

268269

@@ -312,7 +313,8 @@ def required(validator, required, instance, schema):
312313
def minProperties(validator, mP, instance, schema):
313314
if validator.is_type(instance, "object") and len(instance) < mP:
314315
message = (
315-
"should be non-empty" if mP == 1
316+
"should be non-empty"
317+
if mP == 1
316318
else "does not have enough properties"
317319
)
318320
yield ValidationError(f"{instance!r} {message}")
@@ -323,8 +325,7 @@ def maxProperties(validator, mP, instance, schema):
323325
return
324326
if validator.is_type(instance, "object") and len(instance) > mP:
325327
message = (
326-
"is expected to be empty" if mP == 0
327-
else "has too many properties"
328+
"is expected to be empty" if mP == 0 else "has too many properties"
328329
)
329330
yield ValidationError(f"{instance!r} {message}")
330331

@@ -364,7 +365,8 @@ def oneOf(validator, oneOf, instance, schema):
364365
)
365366

366367
more_valid = [
367-
each for _, each in subschemas
368+
each
369+
for _, each in subschemas
368370
if validator.evolve(schema=each).is_valid(instance)
369371
]
370372
if more_valid:
@@ -393,10 +395,13 @@ def unevaluatedItems(validator, unevaluatedItems, instance, schema):
393395
if not validator.is_type(instance, "array"):
394396
return
395397
evaluated_item_indexes = find_evaluated_item_indexes_by_schema(
396-
validator, instance, schema,
398+
validator,
399+
instance,
400+
schema,
397401
)
398402
unevaluated_items = [
399-
item for index, item in enumerate(instance)
403+
item
404+
for index, item in enumerate(instance)
400405
if index not in evaluated_item_indexes
401406
]
402407
if unevaluated_items:
@@ -408,7 +413,9 @@ def unevaluatedProperties(validator, unevaluatedProperties, instance, schema):
408413
if not validator.is_type(instance, "object"):
409414
return
410415
evaluated_keys = find_evaluated_property_keys_by_schema(
411-
validator, instance, schema,
416+
validator,
417+
instance,
418+
schema,
412419
)
413420
unevaluated_keys = []
414421
for property in instance:

0 commit comments

Comments
 (0)