Giter Site home page Giter Site logo

Comments (13)

aik099 avatar aik099 commented on May 7, 2024

Are you sure? There are a lot of build-in sniffs available.

from php_codesniffer.

bweston92 avatar bweston92 commented on May 7, 2024

As far as a generator that I use goes.

http://edorian.github.io/php-coding-standard-generator/

On 13 October 2014 11:14, Alexander Obuhovich [email protected]
wrote:

Are you sure? There are a lot of build-in sniffs available.


Reply to this email directly or view it on GitHub
#287 (comment)
.

from php_codesniffer.

aik099 avatar aik099 commented on May 7, 2024

I've checked and you're right. There are none. But it's not a big deal to create any custom sniff from scratch or extend existing one. There are quite a few custom coding standards composed from build-in and custom-made sniffs out there. Mine for example: https://github.com/aik099/CodingStandard

To make standard self-sufficient I've copied over sniffs that I liked from other standards (not from build-in ones) to my standard and that's basically it.

I admit, that for starters writing own sniff or even extending existing one is a tough task especially if you haven't had any experience with PHP tokenizers in past. It also requires vast knowledge of all possible variations of PHP syntax (between different versions) to ensure that sniff only does what it is supposed to do and not some extra unwanted bit.

from php_codesniffer.

bweston92 avatar bweston92 commented on May 7, 2024

In other words I'm screwed aha :)

On 13 October 2014 11:22, Alexander Obuhovich [email protected]
wrote:

I've checked and you're right. There are none. But it's not a big deal to
create any custom sniff from scratch or extend existing one. There are
quite a few custom coding standards composed from build-in and custom-made
sniffs out there. Mine for example:
https://github.com/aik099/CodingStandard

To make standard self-sufficient I've copied over sniffs that I liked from
other standards (not from build-in ones) to my standard and that's
basically it.

I admit, that for starters writing own sniff or even extending existing
one is a tough task especially if you haven't had any experience with PHP
tokenizers in past. It also requires vast knowledge of all possible
variations of PHP syntax (between different versions) to ensure that sniff
only does what it is supposed to do and not some extra unwanted bit.


Reply to this email directly or view it on GitHub
#287 (comment)
.

from php_codesniffer.

aik099 avatar aik099 commented on May 7, 2024

If we're talking about Laravel standard in general, then there is ticket about it: laravel/framework#5933

If you just need that coding standard to validate your own code, not on the CI server, then you might setup required configuration in PhpStorm coding standard and when doing code reformat it will automatically place brace on correct line.

from php_codesniffer.

aik099 avatar aik099 commented on May 7, 2024

But I recommend going for PHP_CodeSniffer option, because in 2.x version it also can auto-fix stuff. Compared to PhpStorm auto-fixing it's more advanced because you can write in sniff's PHP code what you need to be found and what needs to be fixed and how.

from php_codesniffer.

bweston92 avatar bweston92 commented on May 7, 2024

It will be for CI, to make sure my colleagues don't make my code look a
mess. I took a look at an example of PSR-2 class sniff and looked awful and
wasn't read-able to be honest.

On 13 October 2014 11:37, Alexander Obuhovich [email protected]
wrote:

But I recommend going for PHP_CodeSniffer option, because in 2.x version
it also can auto-fix stuff. Compared to PhpStorm auto-fixing it's more
advanced because you can write in sniff's PHP code what you need to be
found and what needs to be fixed and how.


Reply to this email directly or view it on GitHub
#287 (comment)
.

from php_codesniffer.

aik099 avatar aik099 commented on May 7, 2024

CI + PHP_CodeSniffer is a huge win. In my team I've configured PHP_CodeSniffer on each developer PhpStorm and on CI server as well. This way even if they miss an error locally CI server will still find it and e-mail them.

For now you can assemble your standard from existing sniffs and note somewhere what sniffs are missing. If after googling you are unable to find a particular sniffs, then maybe I can help you out by writing them for some $ of course.

from php_codesniffer.

bweston92 avatar bweston92 commented on May 7, 2024

I've Googled and not found anything. Will have to read into the sniffs more and get a good idea of it. Thanks for your time.

from php_codesniffer.

bweston92 avatar bweston92 commented on May 7, 2024

I've found where the code for the current standard is (PEAR_Sniffs_Classes_ClassDeclarationSniff), but my ruleset.xml which means I don't know how to turn it of or even overwrite it with my modified version. Any ideas?

from php_codesniffer.

aik099 avatar aik099 commented on May 7, 2024

I don't know how to turn it off

Turning off particular error from a sniff is quite easy in fact. Just add following to your ruleset.xml:

<rule ref="PEAR.Classes.ClassDeclaration.ShortNotCapital">
    <severity>0</severity>
</rule>

In code above replace ShortNotCapital with actual error code that is supplied to ->addError call in the sniff's PHP code.

... even overwrite it with my modified version ...

It's PHP. Overwriting is done by creating your own sniff that extends that sniff and replacing required parts of PHP code with what you need.

from php_codesniffer.

bweston92 avatar bweston92 commented on May 7, 2024

When on about over-writing I mean so that is would use mine rather then theirs, if you extend something you still need a different class name how will it know to use my version? I have in fact created a fix but I don't know yet how to make it use mine.

from php_codesniffer.

aik099 avatar aik099 commented on May 7, 2024

In the ruleset.xml you say from which sniffs your ruleset consists. You can either:

  • include whole PEAR standard
  • include all PEAR standard but not the specific sniffs you don't want
  • manually cherry-pick sniffs you want only

Then, as long as you don't include sniff you extended the your sniff version will be used automatically.

Here you can find more about format of ruleset.xml file: http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php

from php_codesniffer.

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.