Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: authorize adding extra rules, no override allowed #21

Closed

Conversation

yannchabed
Copy link
Contributor

@yannchabed yannchabed commented Apr 28, 2023

Why?

As this config user
I want to be able to add custom rules
And make sure the standard rules are never overriden
In order to share the same cs-fixer rules with the company and, optionnaly, my team's more restrictive ones

TODO

  • code is tested
  • documentation is updated (if needed)

.github/workflows/ci.yml Outdated Show resolved Hide resolved
public function __construct()
/** @var array $customRules */
private $customRules;
public function __construct(array $customRules = [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the whole point of BedrockStreaming/php-cs-fixer-config was to share the exact same rules between all PHP teams at Bedrock... Isn't it weird to allow custom rules, then? 🤔

Copy link
Contributor Author

@yannchabed yannchabed Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. We do wish to keep sharing the exact same cs-fixer rules between the company PHP teams.
However, this has some limitations. In case of specific needs per team / project, then we happen to decide extra rules. For now we have no solution to apply them properly and automatically.
The correct wording is extra rules rather than custom rules (I changed it to prevent any confusion).
This feature quarantees that those extra rules do not override the ones defined at the Bedrock PHP teams level.

@yannchabed yannchabed force-pushed the feat/allow-for-adjustments-without-regression branch 2 times, most recently from dc9ce8e to f611379 Compare April 28, 2023 13:46
@yannchabed yannchabed self-assigned this Apr 28, 2023
@yannchabed yannchabed force-pushed the feat/allow-for-adjustments-without-regression branch 5 times, most recently from a73405d to e923e49 Compare April 28, 2023 14:35
@yannchabed yannchabed changed the title feat: authorize adding custom rules, no override of standard ones feat: authorize adding custom rules, no override allowed Apr 28, 2023
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@yannchabed yannchabed force-pushed the feat/allow-for-adjustments-without-regression branch 2 times, most recently from 98eda58 to ed42479 Compare April 28, 2023 16:04
@yannchabed yannchabed changed the title feat: authorize adding custom rules, no override allowed feat: authorize adding extra rules, no override allowed Apr 28, 2023
@yannchabed yannchabed force-pushed the feat/allow-for-adjustments-without-regression branch from ed42479 to 5f96668 Compare April 28, 2023 16:11
@yannchabed yannchabed marked this pull request as ready for review April 28, 2023 16:22
@yannchabed yannchabed requested a review from a team as a code owner April 28, 2023 16:22
@yannchabed yannchabed force-pushed the feat/allow-for-adjustments-without-regression branch from 5f96668 to 75c4a56 Compare May 2, 2023 08:05
Comment on lines +51 to +55
$newRules = \array_diff_key($this->extraRules, $standardRules);

return \array_merge($newRules, $standardRules);
Copy link
Member

@Oliboy50 Oliboy50 May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ adding a new item to the $standardRules will be a potential breaking change for those who uses $extraRules

example:

  1. Toto uses new BedrockStreaming(['explicit_string_variable' => true])
  2. 'explicit_string_variable' => false is added to the $standardRules
  3. Toto updates its dependencies and then he cries because its code does not work anymore... Will it pin its dependencies to the previous version? 👀

now, the question for this repository maintainers will be to define if they should bump a new major release each time they add an item to $standardRules or minor release like before

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can take the problem by another angle.
Why not, have an empty configuration and create a BR CS who decorate this empty config. And if a project or team want the same BR CS rules and add his own rule, they could just decorate the BR CS config. And why not add a overrideRules parameter that allow to override all decorated config.

Some pseudocode:
empty config

class EmptyConfig {
    contructor () {
        this->rules = []
    }
}
config = new Config()

BR CS config

class BRCS {
    constructor(config Config, array extraRule, bool overrideRules) {
        this->rule = ["rule1" => true]
        merge rules with override or not
    }
}
config = new BRCS(new Config)

project1 of BR config

class Project1BR {
    constructor(config Config, array extraRule, bool overrideRules) {
        this->rule = ["rule2" => false]
        merge rules with override or not
    }
}
config = new Project1BR(new BRConfig(new Config), ["rule1" => false], true)

It's just pseudocode, and I miss certainly a lot of things, but the idea is here.
What to you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion!

I think I understand your suggestion. Technically, it looks ok (although, I think we must forbid overriding). Using decorators looks clean.

However, I think it's a bit overkill regarding the original proposition where we (my team) wish to add a few extra rules to the company rules.

Maybe you've got a more complex use case in mind?

@yannchabed yannchabed force-pushed the feat/allow-for-adjustments-without-regression branch from 75c4a56 to f64f227 Compare May 25, 2023 08:10
@yannchabed
Copy link
Contributor Author

yannchabed commented Jun 7, 2023

Choose another way: increase the README to exploin how to achieve the same goal on the project side ➡️ #25

@yannchabed yannchabed closed this Jun 7, 2023
@yannchabed yannchabed deleted the feat/allow-for-adjustments-without-regression branch June 7, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants