laravel / pint

Laravel Pint is an opinionated PHP code style fixer for minimalists.

Home Page:https://laravel.com/docs/pint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Centralized Code Style Management with HTTP Presets

maantje opened this issue · comments

User Story:
As a user managing multiple Laravel projects, I want a centralized way to handle custom code styles across all projects, while retaining the flexibility to customize styles on a per-project basis.

Problem:
Currently, the only way to load a different configuration is either from a local path or via HTTP, as demonstrated in the documentation:

pint --config vendor/my-company/coding-style/pint.json
pint --config https://my.site.com/pint.json (undocumented but seems to work)

However, this approach has limitations. For instance, certain configurations like 'exclude' and 'notName' are defined in the pint.json file, potentially varying between projects. Consequently, users may need to manually copy and edit the pint.json file for each project. This becomes problematic when the code style updates, necessitating manual adjustments once again. Additionally, enabling or disabling a rule on a project level requires the same manual process.

Proposed Solution:
Enable the loading of presets over HTTP. This would allow users to manage all rules in one central location, such as a URL (e.g., https://pastebin.com/raw/N5TfqWZw), while still allowing for project-specific adjustments.

Example Configuration:

{
    "preset": "https://pastebin.com/raw/N5TfqWZw",
    "rules": {
        "no_spaces_after_function_name": false
    },
    "exclude": [
        "my/path"
    ]
}

In this example, all rules from the specified URL would be loaded, with the additional capability to disable specific rules and exclude paths on a per-project basis.

Benefits:
With this approach, all rules are centrally managed at a designated URL (e.g., https://pastebin.com/raw/N5TfqWZw), simplifying updates and maintenance. Simultaneously, users retain the ability to fine-tune configurations for individual projects.

Additional Information:

Related Issues:

Issue #247: Enables third-party hosting of presets.
Issue #199: Allows users to "pin" presets, for example, with a URL like https://raw.githubusercontent.com/laravel/pint/v1.13.4/resources/presets/laravel.json.

Proposed Code Changes:

To implement this feature, two changes are required. First, presets should be in JSON format. Secondly, the ConfigurationResolverFactory should be enhanced to load presets over HTTP.

View the proposed changes in the fork at maantje@6ed0ca9