grep with regex in pre-commit git hook

杀马特。学长 韩版系。学妹 提交于 2019-12-24 06:35:36

问题


I'm writing a little pre-commit hook to check for debug code this works well when using:

FORBIDDEN='console.log'

but when I change to:

FORBIDDEN='die(|console.log(|print_r('

it fails to catch anything.

FULL CODE:

FILES_PATTERN='(\..+)?$'
FORBIDDEN='die(|console.log(|print_r('

git diff --cached --name-only | \
    grep -E $FILES_PATTERN | \
    xargs grep -E --with-filename -n $FORBIDDEN | \
    grep -v '//';

Not sure if its regex or something else


回答1:


Try escaping your parenthesis:

FORBIDDEN='die\(|console.log\(|print_r\('


来源:https://stackoverflow.com/questions/21589285/grep-with-regex-in-pre-commit-git-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!