Coder Social home page Coder Social logo

Comments (10)

di-repo avatar di-repo commented on August 30, 2024 1

At the moment I am testing with the following hook setup:

 "action": "vendor/bin/phpcs $(git diff --cached --name-only --diff-filter=ACMR -z | xargs -0)",

I totally agree with @heiglandreas that it's better to verify before pushing, but the script will be far more complex.

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

This could get quite big, it should not, but it could.
So providing this placeholder upfront maybe is not the best idea.

To solve this we could improve our placeholder system.
We would have to allow placeholder that can be computed only if they where used in an action configuration.

If you don't want to wait, you can have a look at the linting action and create your own code sniffer action accordingly.

But I will look into the placeholder thing

from captainhook.

heiglandreas avatar heiglandreas commented on August 30, 2024

The other thing is that you will still get notices about parts of your chamged files that you never touched but that where broken beforehand. IMO it would be best to always have a clean codesniffer run before you start. And then only your changes will cause codesniffer to complain. If you are worried about the speed: I wouldn't run CS on every commit but only on push to be able to commit fast and also probably unclean code and then have a cleanup before I push. Or think about running such tests (perhaps with an autocleaner) in CI.

Git Hooks are no replacement for CI!

from captainhook.

heiglandreas avatar heiglandreas commented on August 30, 2024

And you probably want to have a look at https://github.com/exussum12/coverageChecker

from captainhook.

fuess avatar fuess commented on August 30, 2024

Thanks for all responses. I agree we should do a codesniffer run on whole codebase, but I thought it would be nice to 'grow' into this, without a big task beforehand. Thanks @dimitar-ivanov-tryzens for the suggestion. Will try it out.

from captainhook.

heiglandreas avatar heiglandreas commented on August 30, 2024

That's what coverageChecker does. 😉

from captainhook.

fuess avatar fuess commented on August 30, 2024

Ah, missed that one, thanks!

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

In version 5 this is available for pre-commit hooks.

"pre-commit": {
    "enabled": true,
    "actions": [
      {
        "action": "tools/phpcs.phar --standard=psr12 {$STAGED_FILES|of-type:php}"
      }
    ]
  }
}

{$STAGED_FILES} will get replaced by the list of changed or added files. You can filter the list by using the {$STAGED_FILES|of-type:php} modifier or change the glue between files with {$STAGED_FILES|separated-by:, } and of course you can combine both modifiers.

from captainhook.

torhoehn avatar torhoehn commented on August 30, 2024

@sebastianfeldmann If there is no staged PHP file e.g. the phpcs command will result in

ERROR: You must supply at least one file or directory to process.
Run "phpcs --help" for usage information

Is usage of https://github.com/exussum12/coverageChecker the only way to handle this? Or would it be possible to skip the wohl action?

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

You can configure a Condition like this

{
  "action": "...",
  "options": {},
  "conditions": [
    {
      "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType",
      "args": ["php"]
    }
  ]
}

With this Condition the Action will only get executed if PHP files are included in this commit.
For a more detailed explanation have a look at the documentation

from captainhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.