PHP_CodeSniffer: phpcs reads from stdin which requires a terminal, and hangs if there are none.

With version 2.6.0, phpcs now tries to read content from stdin.

This of course either requires a terminal or an incoming stream from another process. When running phpcs as part of a git pre-commit hook in git gui or any other GUI around git which doesn’t allocate a terminal, this completely blocks the pre-commit process and and the GUI itself, the process is stuck in T state on linux or osx.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 23 (10 by maintainers)

Commits related to this issue

Most upvoted comments

For us as a solution was these lines in ruleset file

<rule ref="Internal.NoCodeFound">
        <severity>0</severity>
</rule>

Just want to share my case

I recently update phpcs to 2.6 and I’ve started to have the same problem with STDIN. I’ve never had it before.

I’m using phing to automate some build steps, and I’m running it from pre-push hook like this

#!/bin/bash

vendor/bin/phing verify-dev

I’ve following problem

FILE: STDIN
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 1 | WARNING | No PHP code was found in this file and short open tags
   |         | are not allowed by this install of PHP. This file may
   |         | be using short open tags but PHP does not allow them.
----------------------------------------------------------------------

Meanwhile if I’m running phpcs or with help phing vendor/bin/phing verify-dev from terminal it works fine

here is my phpcs-dev target which I have in build.xml

        <target name="phpcs-dev"
                description="Generate CodeSniffer report for Developer"
                depends="init">
            <exec spawn="false" executable="${php.bin.path}/phpcs" checkreturn="true" passthru="true">
                <arg line="--report=full" />
                <arg line="--standard=${project.basedir}/phpcs-ruleset.xml" />
                <arg line="${project.basedir}/App" />
            </exec>
        </target>

and it seems that chnages in my build.xml like this spawn="true" - solves the problem