mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-25 07:58:59 -06:00
Utilities/ast-grep: add rules for cmHasLiteral{Suf,Pre}fix with char needles
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
id: cmhasliteralprefix-char
|
||||
snapshots:
|
||||
cmHasLiteralPrefix(haystack, "'"):
|
||||
fixed: cmHasPrefix(haystack, '\'')
|
||||
labels:
|
||||
- source: cmHasLiteralPrefix(haystack, "'")
|
||||
style: primary
|
||||
start: 0
|
||||
end: 33
|
||||
cmHasLiteralPrefix(haystack, "\n"):
|
||||
fixed: cmHasPrefix(haystack, '\n')
|
||||
labels:
|
||||
- source: cmHasLiteralPrefix(haystack, "\n")
|
||||
style: primary
|
||||
start: 0
|
||||
end: 34
|
||||
cmHasLiteralPrefix(haystack, "a"):
|
||||
fixed: cmHasPrefix(haystack, 'a')
|
||||
labels:
|
||||
- source: cmHasLiteralPrefix(haystack, "a")
|
||||
style: primary
|
||||
start: 0
|
||||
end: 33
|
||||
@@ -0,0 +1,23 @@
|
||||
id: cmhasliteralsuffix-char
|
||||
snapshots:
|
||||
cmHasLiteralSuffix(haystack, "'"):
|
||||
fixed: cmHasSuffix(haystack, '\'')
|
||||
labels:
|
||||
- source: cmHasLiteralSuffix(haystack, "'")
|
||||
style: primary
|
||||
start: 0
|
||||
end: 33
|
||||
cmHasLiteralSuffix(haystack, "\n"):
|
||||
fixed: cmHasSuffix(haystack, '\n')
|
||||
labels:
|
||||
- source: cmHasLiteralSuffix(haystack, "\n")
|
||||
style: primary
|
||||
start: 0
|
||||
end: 34
|
||||
cmHasLiteralSuffix(haystack, "a"):
|
||||
fixed: cmHasSuffix(haystack, 'a')
|
||||
labels:
|
||||
- source: cmHasLiteralSuffix(haystack, "a")
|
||||
style: primary
|
||||
start: 0
|
||||
end: 33
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: cmhasliteralprefix-char
|
||||
valid:
|
||||
- 'cmHasLiteralPrefix(haystack, "foo")'
|
||||
invalid:
|
||||
- 'cmHasLiteralPrefix(haystack, "a")'
|
||||
- 'cmHasLiteralPrefix(haystack, "\n")'
|
||||
- "cmHasLiteralPrefix(haystack, \"'\")"
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: cmhasliteralsuffix-char
|
||||
valid:
|
||||
- 'cmHasLiteralSuffix(haystack, "foo")'
|
||||
invalid:
|
||||
- 'cmHasLiteralSuffix(haystack, "a")'
|
||||
- 'cmHasLiteralSuffix(haystack, "\n")'
|
||||
- "cmHasLiteralSuffix(haystack, \"'\")"
|
||||
27
Utilities/ast-grep/rules/cmhasliteralprefix-char.yml
Normal file
27
Utilities/ast-grep/rules/cmhasliteralprefix-char.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
id: cmhasliteralprefix-char
|
||||
language: Cpp
|
||||
severity: warning
|
||||
message: "`cmHasLiteralPrefix` with a one-char prefix search should use `cmHasPrefix`"
|
||||
rule:
|
||||
pattern: cmHasLiteralPrefix($HAYSTACK, $NEEDLE)
|
||||
constraints:
|
||||
NEEDLE:
|
||||
regex: '^"(.|\\.)"$'
|
||||
transform:
|
||||
NEEDLE_CHANGE_QUOTE:
|
||||
replace:
|
||||
source: $NEEDLE
|
||||
replace: '(^"|"$)'
|
||||
by: "'"
|
||||
NEEDLE_ESCAPE_SINGLE_QUOTE:
|
||||
replace:
|
||||
source: $NEEDLE_CHANGE_QUOTE
|
||||
replace: "'''"
|
||||
by: "'\\''"
|
||||
NEEDLE_OUT:
|
||||
replace:
|
||||
source: $NEEDLE_ESCAPE_SINGLE_QUOTE
|
||||
replace: '\\"'
|
||||
by: '"'
|
||||
fix: cmHasPrefix($HAYSTACK, $NEEDLE_OUT)
|
||||
27
Utilities/ast-grep/rules/cmhasliteralsuffix-char.yml
Normal file
27
Utilities/ast-grep/rules/cmhasliteralsuffix-char.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
id: cmhasliteralsuffix-char
|
||||
language: Cpp
|
||||
severity: warning
|
||||
message: "`cmHasLiteralSuffix` with a one-char suffix search should use `cmHasSuffix`"
|
||||
rule:
|
||||
pattern: cmHasLiteralSuffix($HAYSTACK, $NEEDLE)
|
||||
constraints:
|
||||
NEEDLE:
|
||||
regex: '^"(.|\\.)"$'
|
||||
transform:
|
||||
NEEDLE_CHANGE_QUOTE:
|
||||
replace:
|
||||
source: $NEEDLE
|
||||
replace: '(^"|"$)'
|
||||
by: "'"
|
||||
NEEDLE_ESCAPE_SINGLE_QUOTE:
|
||||
replace:
|
||||
source: $NEEDLE_CHANGE_QUOTE
|
||||
replace: "'''"
|
||||
by: "'\\''"
|
||||
NEEDLE_OUT:
|
||||
replace:
|
||||
source: $NEEDLE_ESCAPE_SINGLE_QUOTE
|
||||
replace: '\\"'
|
||||
by: '"'
|
||||
fix: cmHasSuffix($HAYSTACK, $NEEDLE_OUT)
|
||||
Reference in New Issue
Block a user