timber / starter-theme

The "_s" for Timber: a dead-simple theme that you can build anything from
MIT License
818 stars 278 forks source link

chore: introduce phpcs and phpstan #159

Closed Levdbas closed 4 months ago

Levdbas commented 5 months ago

Related:

Issue

Since the creation of the starter theme a lot has happened in PHP, WordPress and Timber. I want to make the starter-theme a more modern starting point for custom theme development.

As mentioned by @szepeviktor in https://github.com/timber/starter-theme/issues/147#issuecomment-1805365281, it's a good idea to introduce a coding style.

I would like the help of you @szepeviktor and @gchtr to help me enhance the introduction of these two tools. This is my first time introducing them in a project, so any help/tips are welcome.

I want to start linting file and introduce taskrunners when we have the overhaul with all the other PRs in place. So linting would be a final step as I see it now.

Solution

Introduce phpcs and phpstan so we can start linting files.

Impact

A coding style to adhere to is always great.

Usage Changes

No

Considerations

I just plucked some configurations from the internet and that can be improved of course, please help out 🗡️

Testing

no

Levdbas commented 5 months ago

Hi @szepeviktor , especially looking for your feedback on this!

szepeviktor commented 5 months ago

@Levdbas What is the current error count?

Levdbas commented 5 months ago

@Levdbas What is the current error count?

Currently 30 PHPstan issues but most of them will be fixed by #152 by the correct use. I now also was able to scan the files in the root directory by changing the config a bit.

Levdbas commented 4 months ago

@szepeviktor , Lukas and I discussed the PHP cs rulesets. Could you advice in how to implement https://github.com/szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset while keep the possibility that users can add their own rules? I am pretty new to the whole ruleset creation thing so any help is appreciated!

szepeviktor commented 4 months ago

I am pretty new to the whole ruleset creation thing so any help is appreciated!

A ruleset is simply one XML file with rules listed in it.

szepeviktor commented 4 months ago

One can disable an existing rule or add a new one in the theme.

szepeviktor commented 4 months ago

Could you advice in how to implement

BTW This frankenstein is dangerous. It wears out your keyboard and your brain.

Levdbas commented 4 months ago

Updated the PHPCS ruleset base

gchtr commented 4 months ago

@Levdbas Thanks for the update. I think it’s good to use a standard like the 10up standard. It means less work for us. And the phpcs.xml.dist looks a bit more accessible now.

In my opinion, it’s easy to spot that we load in a standard through Composer which is then applied in phpcs.xml.dist. This also makes it easy to swap it out with another standard of your choice.