overtrue / phplint

:bug: A tool that can speed up linting of php files by running several lint processes at once.
MIT License
984 stars 118 forks source link

composer config vendor-dir is ignored, hardcoded path `vendor/` #202

Closed Ragzid closed 8 months ago

Ragzid commented 8 months ago

New Feature

Diagnose

If you use a Composer installation, please specify:

Output of `composer show` command ``` overtrue/phplint 9.1.1 `phplint` is a tool that can speed up linting of php files by running several lint processes at once. psr/cache 3.0.0 Common interface for caching libraries psr/container 2.0.2 Common Container Interface (PHP FIG PSR-11) psr/event-dispatcher 1.0.0 Standard interfaces for event handling. psr/log 3.0.0 Common interface for logging libraries symfony/cache v7.0.3 Provides extended PSR-6, PSR-16 (and tags) implementations symfony/cache-contracts v3.4.0 Generic abstractions related to caching symfony/console v7.0.3 Eases the creation of beautiful and testable command line interfaces symfony/deprecation-contracts v3.4.0 A generic function and convention to trigger deprecation notices symfony/event-dispatcher v7.0.3 Provides tools that allow your application components to communicate with each other by dispatching events and listening to them symfony/event-dispatcher-contracts v3.4.0 Generic abstractions related to dispatching event symfony/finder v7.0.0 Finds files and directories via an intuitive fluent interface symfony/options-resolver v7.0.0 Provides an improved replacement for the array_replace PHP function symfony/polyfill-ctype v1.29.0 Symfony polyfill for ctype functions symfony/polyfill-intl-grapheme v1.29.0 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-normalizer v1.29.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.29.0 Symfony polyfill for the Mbstring extension symfony/process v7.0.3 Executes commands in sub-processes symfony/service-contracts v3.4.1 Generic abstractions related to writing services symfony/string v7.0.3 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way symfony/var-exporter v7.0.3 Allows exporting any serializable PHP data structure to plain PHP code symfony/yaml v7.0.3 Loads and dumps YAML files ```

Summary

Version 9.1 keeps looking for vendor/ directory and ignores composer.json config.

Create empty project with following:

{
    "config": {
        "vendor-dir": "vendors"
    }
}

Install latest phplint

composer require overtrue/phplint --dev

Run phplint

php8.2 vendors/bin/phplint

Expected behaviour

Code linting is performed.

Actual behaviour

PHP Fatal error:  Uncaught RuntimeException: Unable to find "vendor/autoload.php" in tmp/vendors/overtrue/phplint", "tmp" paths. in tmp/vendors/overtrue/phplint/config/bootstrap.php:44
Stack trace:
#0 tmp/vendors/overtrue/phplint/bin/phplint(6): require_once()
#1 tmp/vendors/bin/phplint(120): include('...')
#2 {main}
  thrown in tmp/vendors/overtrue/phplint/config/bootstrap.php on line 44
llaville commented 8 months ago

Even if PHPLint did not run in such context, this feature was never implemented since first version (/cc @overtrue : tell me if you're agree). So I consider it as an enhancement rather than a bug (regression)

llaville commented 8 months ago

Anyway, I've already found a solution to fix this context See https://getcomposer.org/doc/articles/vendor-binaries.md#finding-the-composer-autoloader-from-a-binary

Ragzid commented 8 months ago

Thank you @llaville . I forgot to mention that latest 9.0.x version (9.0.8) works as expected and honors the configured dir (basically all versions since 3.4 as I just saw in one obsolete project).

llaville commented 8 months ago

@Ragzid I've already given an answer that will explains the issue context (splitting autoloader in its own config/bootstrap.php file)

llaville commented 8 months ago

Just finished my tests. Here are the plan !

Tested with following composer.json contents (and a local clone copy of main PHPLint repo) :

{
  "config": {
    "vendor-dir": "vendors"
  },
  "repositories": [
    {
      "type": "path",
      "url": "../github/phplint"
    }
  ],
  "require": {
    "overtrue/phplint": "9.1.x-dev"
  },
  "minimum-stability": "dev"
}

Install PHPLint as configured

composer update
Loading composer repositories with package information
Updating dependencies
Lock file operations: 22 installs, 0 updates, 0 removals
  - Locking overtrue/phplint (dev-main)
  - Locking psr/cache (dev-master 0a7c67d)
  - Locking psr/container (dev-master 7079847)
  - Locking psr/event-dispatcher (dev-master 977ffcf)
  - Locking psr/log (dev-master fe5ea30)
  - Locking symfony/cache (7.1.x-dev 5460647)
  - Locking symfony/cache-contracts (dev-main a9fe419)
  - Locking symfony/console (7.1.x-dev 82efc31)
  - Locking symfony/deprecation-contracts (dev-main 2c438b9)
  - Locking symfony/event-dispatcher (7.1.x-dev 5bb99ba)
  - Locking symfony/event-dispatcher-contracts (dev-main 4d4ea14)
  - Locking symfony/finder (7.1.x-dev beeac2b)
  - Locking symfony/options-resolver (7.1.x-dev 700ff40)
  - Locking symfony/polyfill-ctype (1.x-dev ef4d7e4)
  - Locking symfony/polyfill-intl-grapheme (1.x-dev 32a9da8)
  - Locking symfony/polyfill-intl-normalizer (1.x-dev bc45c39)
  - Locking symfony/polyfill-mbstring (1.x-dev 9773676)
  - Locking symfony/process (7.1.x-dev bf2a95a)
  - Locking symfony/service-contracts (dev-main cea2ecc)
  - Locking symfony/string (7.1.x-dev 3d0a988)
  - Locking symfony/var-exporter (7.1.x-dev 1fb7930)
  - Locking symfony/yaml (7.1.x-dev 6bd0f04)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 22 installs, 0 updates, 0 removals
  - Downloading symfony/yaml (7.1.x-dev 6bd0f04)
  - Downloading symfony/process (7.1.x-dev bf2a95a)
  - Downloading symfony/deprecation-contracts (dev-main 2c438b9)
  - Downloading symfony/finder (7.1.x-dev beeac2b)
  - Downloading psr/event-dispatcher (dev-master 977ffcf)
  - Downloading symfony/event-dispatcher-contracts (dev-main 4d4ea14)
  - Downloading symfony/event-dispatcher (7.1.x-dev 5bb99ba)
  - Downloading symfony/string (7.1.x-dev 3d0a988)
  - Downloading psr/container (dev-master 7079847)
  - Downloading symfony/service-contracts (dev-main cea2ecc)
  - Downloading symfony/console (7.1.x-dev 82efc31)
  - Downloading psr/cache (dev-master 0a7c67d)
  - Downloading symfony/cache-contracts (dev-main a9fe419)
  - Downloading symfony/cache (7.1.x-dev 5460647)
  - Installing symfony/polyfill-ctype (1.x-dev ef4d7e4): Extracting archive
  - Installing symfony/yaml (7.1.x-dev 6bd0f04): Extracting archive
  - Installing symfony/process (7.1.x-dev bf2a95a): Extracting archive
  - Installing symfony/deprecation-contracts (dev-main 2c438b9): Extracting archive
  - Installing symfony/options-resolver (7.1.x-dev 700ff40): Extracting archive
  - Installing symfony/finder (7.1.x-dev beeac2b): Extracting archive
  - Installing psr/event-dispatcher (dev-master 977ffcf): Extracting archive
  - Installing symfony/event-dispatcher-contracts (dev-main 4d4ea14): Extracting archive
  - Installing symfony/event-dispatcher (7.1.x-dev 5bb99ba): Extracting archive
  - Installing symfony/polyfill-mbstring (1.x-dev 9773676): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (1.x-dev bc45c39): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (1.x-dev 32a9da8): Extracting archive
  - Installing symfony/string (7.1.x-dev 3d0a988): Extracting archive
  - Installing psr/container (dev-master 7079847): Extracting archive
  - Installing symfony/service-contracts (dev-main cea2ecc): Extracting archive
  - Installing symfony/console (7.1.x-dev 82efc31): Extracting archive
  - Installing symfony/var-exporter (7.1.x-dev 1fb7930): Extracting archive
  - Installing psr/cache (dev-master 0a7c67d): Extracting archive
  - Installing symfony/cache-contracts (dev-main a9fe419): Extracting archive
  - Installing psr/log (dev-master fe5ea30): Extracting archive
  - Installing symfony/cache (7.1.x-dev 5460647): Extracting archive
  - Installing overtrue/phplint (dev-main): Symlinking from ../github/phplint
2 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
17 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.

With upcoming release 9.1.2 :

vendors/bin/phplint
phplint 9.1.2 by overtrue and contributors.

Runtime       : PHP 8.2.15
Configuration : No config file loaded

........................................................................................
Time: 1 sec, Memory: 8.0 MiB, Cache: 276 hits, 88 misses, Processes: 88

 [OK] 364 files

After building the PHAR version with BOX v4.6.1, run

../github/phplint/bin/phplint.phar

Still gave results

phplint 9.1.2 by overtrue and contributors.

Runtime       : PHP 8.2.15
Configuration : No config file loaded

................................................................................................ 97 / 364 ( 26%)
.................................................................................................194 / 364 ( 53%)
.................................................................................................291 / 364 ( 79%)
..........................................................................

Time: 5 secs, Memory: 10.0 MiB, Cache: 0 hit, 364 misses, Processes: 364

 [OK] 364 files
llaville commented 8 months ago

@Ragzid main branch of PHPLint repo is already updated. So you can test it, following plan I've provided, if you want.

Ragzid commented 8 months ago

rev da61584 works as expected, thank you very much

llaville commented 8 months ago

Version 9.1.2 is available