Code Monkey home page Code Monkey logo

Comments (9)

jrfnl avatar jrfnl commented on August 22, 2024

Some libraries expect some keys to be string and others to not be set, and since it's an external library I cannot change how it accepts the array.

Any array item without an explicit key, automatically gets assigned an integer key. You can fix the issue by using explicit integer keys yourself, like so:

array(
'relation' => 'AND',
0 => array( 'key' => 'foo' ),
1 => array( 'key' => 'bar' ),
)

No need for disables/ignores. Either fix the issue or don't use this sniff.

from phpcsextra.

kkmuffme avatar kkmuffme commented on August 22, 2024

Adding the default numeric keys just makes it harder to maintain. Some months later, I add an array at position 2 - then I have to manually change all following 20 elements too.
This makes it a pain to work with and also the git diffs are less clear.

from phpcsextra.

jrfnl avatar jrfnl commented on August 22, 2024

@kkmuffme Again, in that case, this is just not a suitable sniff for your usecase.

from phpcsextra.

kkmuffme avatar kkmuffme commented on August 22, 2024

I know I can phpcs:disable, but for 90% of my code this sniff works perfectly fine and makes sense.
But in 10% I have some external libs, that have the above issue - I can of course phpcs:disable each and every time, but an ignore option would be much better, as I'd only have to set this in the config once.

from phpcsextra.

jrfnl avatar jrfnl commented on August 22, 2024

Another way to still use the sniff, but avoid this particular issue is as follows:

$array = array(
array( 'key' => 'foo' ),
array( 'key' => 'bar' ),
);
$array['relation'] = 'AND';

I don't particularly like that code pattern, but it would avoid the sniff flagging the array.

an ignore option would be much better, as I'd only have to set this in the config once.

An ignore option will not be accepted for this sniff as you then get the next request: "this key should only be ignored in combination with that key", "this key should only be ignored in file x.php" etc. This is a road to maintainer pain which I'm not willing to take.

from phpcsextra.

kkmuffme avatar kkmuffme commented on August 22, 2024

Another way to still use the sniff, but avoid this particular issue is as follows:

I have a nested config array, so this won't work without massively bloating the code.

"this key should only be ignored in combination with that key"

Well, let's cross the bridge when we come to it :-) and start with a simple ignore. Anything further can then be discussed IF anybody really needs that.

"this key should only be ignored in file x.php"

This is already supported by this rule, since this is a native feature of phpcs.


Would you accept a PR for a simple "ignore" case, where all keys in the ignore array are treated as if they're not part of the array at all? (ignored)

from phpcsextra.

jrfnl avatar jrfnl commented on August 22, 2024

This is already supported by this rule, since this is a native feature of phpcs.

It is not, as properties are per sniff and not configurable per file.

Would you accept a PR for a simple "ignore" case, where all keys in the ignore array are treated as if they're not part of the array at all? (ignored)

As I've stated three times now: no, I would not.

from phpcsextra.

kkmuffme avatar kkmuffme commented on August 22, 2024

It is not, as properties are per sniff and not configurable per file.

phpcs:disable in the file comment, does precisely this though?

from phpcsextra.

jrfnl avatar jrfnl commented on August 22, 2024

It is not, as properties are per sniff and not configurable per file.

phpcs:disable in the file comment, does precisely this though?

No it does not. It disables the complete sniff for a file. Not apply a specific property exclusively to a specific file.

from phpcsextra.

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.