@pragmatiks/lint 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/semgrep-rules/pra_exists_gated_read.yml +14 -0
- package/src/semgrep-rules/pra_if_chain_else_continue.yml +14 -0
- package/src/semgrep-rules/pra_multi_underscore_unpack.yml +6 -0
- package/src/semgrep-rules/pra_optional_tuple_index.yml +23 -0
- package/src/semgrep-rules/pra_parsed_result_index.yml +15 -0
- package/src/semgrep-rules/pra_pure_call_result_dropped.yml +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## js-v0.10.1 (2026-11-08)
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- **rules**: flag pure-prefix results bound only to _ in pra-pure-call-result-dropped (PRA-733)
|
|
8
|
+
|
|
9
|
+
## js-v0.10.0 (2026-11-08)
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
- **rules**: add Python shape rules from the PRA-703 reviews (PRA-733)
|
|
14
|
+
|
|
3
15
|
## js-v0.9.0 (2026-11-08)
|
|
4
16
|
|
|
5
17
|
### Features
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
- id: pra-exists-gated-read
|
|
3
|
+
patterns:
|
|
4
|
+
- pattern: $READ if $PATH.exists() else None
|
|
5
|
+
- metavariable-pattern:
|
|
6
|
+
metavariable: $READ
|
|
7
|
+
pattern-either:
|
|
8
|
+
- pattern: <... $FILE.read_text(...) ...>
|
|
9
|
+
- pattern: <... $FILE.read_bytes(...) ...>
|
|
10
|
+
- pattern: <... $FILE.open(...) ...>
|
|
11
|
+
- pattern: <... open(...) ...>
|
|
12
|
+
message: "principle #9 an existence check folded into a read ternary hides the absent case. Return None in a guard clause first, then read."
|
|
13
|
+
severity: WARNING
|
|
14
|
+
languages: [python]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
- id: pra-if-chain-else-continue
|
|
3
|
+
pattern: |
|
|
4
|
+
if $FIRST:
|
|
5
|
+
$NAME = $FIRST_VALUE
|
|
6
|
+
elif $SECOND:
|
|
7
|
+
$NAME = $SECOND_VALUE
|
|
8
|
+
else:
|
|
9
|
+
continue
|
|
10
|
+
message: "principle #9 an if/elif chain that assigns one name in every branch and ends in else: continue hides a value lookup in the loop body. Move the chain into a helper that returns the value or None, and continue on None."
|
|
11
|
+
severity: WARNING
|
|
12
|
+
languages: [python]
|
|
13
|
+
metadata:
|
|
14
|
+
note: "The pattern matches the last two assigning branches, so a chain of any length is reported once at its final elif."
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
- id: pra-multi-underscore-unpack
|
|
3
|
+
pattern: "..., _, ..., _, ... = $VALUE[$KEY]"
|
|
4
|
+
message: "principle #9 unpacking a subscript into two or more _ placeholders hides the shape of the record. Read the parts by name: a named record, a dataclass or attribute access."
|
|
5
|
+
severity: WARNING
|
|
6
|
+
languages: [python]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
- id: pra-optional-tuple-index
|
|
3
|
+
pattern-either:
|
|
4
|
+
- pattern: $FIRST, $SECOND = $CALL(...) or ($FIRST_DEFAULT, $SECOND_DEFAULT)
|
|
5
|
+
- patterns:
|
|
6
|
+
- pattern-either:
|
|
7
|
+
- pattern: $TUPLE is None or <... $TUPLE[$INDEX] ...>
|
|
8
|
+
- pattern: $TUPLE is not None and <... $TUPLE[$INDEX] ...>
|
|
9
|
+
- patterns:
|
|
10
|
+
- pattern-inside: |
|
|
11
|
+
def $FUNCTION(...):
|
|
12
|
+
...
|
|
13
|
+
<... $TUPLE[$FIRST_INDEX] if $TUPLE else $FIRST_DEFAULT ...>
|
|
14
|
+
...
|
|
15
|
+
<... $TUPLE[$SECOND_INDEX] if $TUPLE else $SECOND_DEFAULT ...>
|
|
16
|
+
...
|
|
17
|
+
- pattern: $TUPLE[$INDEX] if $TUPLE else $DEFAULT
|
|
18
|
+
- metavariable-regex:
|
|
19
|
+
metavariable: $INDEX
|
|
20
|
+
regex: '^-?\d+$'
|
|
21
|
+
message: "principle #9 indexing an optional tuple under a None test mixes the absent case with positional access. Return on None in a guard clause, then unpack once into named locals."
|
|
22
|
+
severity: WARNING
|
|
23
|
+
languages: [python]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
- id: pra-parsed-result-index
|
|
3
|
+
patterns:
|
|
4
|
+
- pattern-either:
|
|
5
|
+
- pattern: $FUNCTION(...)[$INDEX]
|
|
6
|
+
- pattern: $OBJECT.$FUNCTION(...)[$INDEX]
|
|
7
|
+
- metavariable-regex:
|
|
8
|
+
metavariable: $FUNCTION
|
|
9
|
+
regex: '^(parse|extract)_\w+$'
|
|
10
|
+
- metavariable-regex:
|
|
11
|
+
metavariable: $INDEX
|
|
12
|
+
regex: '^-?\d+$'
|
|
13
|
+
message: "principle #9 a literal index into a parse or extract result hides which part is meant. Unpack the result into named locals, or return a named record."
|
|
14
|
+
severity: WARNING
|
|
15
|
+
languages: [python]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
- id: pra-pure-call-result-dropped
|
|
3
|
+
pattern-either:
|
|
4
|
+
- patterns:
|
|
5
|
+
- pattern-either:
|
|
6
|
+
- pattern: _ = $FUNCTION(...)
|
|
7
|
+
- pattern: _ = await $FUNCTION(...)
|
|
8
|
+
- pattern: _ = self.$FUNCTION(...)
|
|
9
|
+
- pattern: _ = await self.$FUNCTION(...)
|
|
10
|
+
- pattern: _ = cls.$FUNCTION(...)
|
|
11
|
+
- pattern: _ = await cls.$FUNCTION(...)
|
|
12
|
+
- metavariable-regex:
|
|
13
|
+
metavariable: $FUNCTION
|
|
14
|
+
regex: '^(compute|build|derive|format|parse|extract)_\w+$'
|
|
15
|
+
- patterns:
|
|
16
|
+
- pattern-regex: '(?m)^[ \t]*(?:await[ \t]+)?(?:(?:self|cls)\.)?(?:compute|build|derive|format|parse|extract)_\w+\((?![^\n]*\)[ \t]*[.\[])(?:[^\n]*[(),])?[ \t]*$'
|
|
17
|
+
- pattern-not-inside: $CALL(...)
|
|
18
|
+
- pattern-not-inside: "[...]"
|
|
19
|
+
- pattern-not-inside: "{...}"
|
|
20
|
+
- pattern-not-inside: "(...)"
|
|
21
|
+
- pattern-not-inside: '"..."'
|
|
22
|
+
- pattern-not-inside: $TARGET = $VALUE
|
|
23
|
+
- pattern-not-inside: "$TARGET: $TYPE = $VALUE"
|
|
24
|
+
message: "principle #7 a compute, build, derive, format, parse or extract function is pure, so a call whose result is dropped does nothing. Use the result, or call the function that performs the side effect."
|
|
25
|
+
severity: WARNING
|
|
26
|
+
languages: [python]
|
|
27
|
+
metadata:
|
|
28
|
+
note: "Matches a call statement that opens its own line, or a call bound to _ alone, so a call used as an argument, element, assignment value or chained receiver is not flagged. Principle #7 makes these prefixes pure; a result consumed only to raise on bad input belongs in a validate function that says so."
|