From 05fad343d0f2a2404fc2e509e994695703fb025d Mon Sep 17 00:00:00 2001 From: Sourya Vatsyayan Date: Thu, 7 Oct 2021 15:45:03 +0530 Subject: [PATCH] Add rulename to error messages Signed-off-by: Sourya Vatsyayan --- .deepsource.toml | 9 + .github/workflows/build.yml | 451 ++++++++++++++++++++++ phpstan.neon.dist => phpstan.neon.dist.bk | 0 src/Analyser/FileAnalyser.php | 6 + 4 files changed, 466 insertions(+) create mode 100644 .deepsource.toml create mode 100644 .github/workflows/build.yml rename phpstan.neon.dist => phpstan.neon.dist.bk (100%) diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000000..a11fd15068 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,9 @@ +version = 1 + +[[analyzers]] +name = "php" +enabled = true + +[[analyzers]] +name = "test-coverage" +enabled = true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..f55a063197 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,451 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +name: "Build" + +on: + pull_request: + push: + branches: + - "master" + +env: + COMPOSER_ROOT_VERSION: "0.12.x-dev" + +jobs: + lint: + name: "Lint" + runs-on: "ubuntu-latest" + if: ${{ false }} + + strategy: + matrix: + php-version: + - "7.1" + - "7.2" + - "7.3" + - "7.4" + - "8.0" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Validate Composer" + run: "composer validate" + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Transform source code" + if: matrix.php-version != '7.4' && matrix.php-version != '8.0' + run: php bin/transform-source.php + + - name: "Lint" + run: "make lint" + + coding-standards: + name: "Coding Standard" + + runs-on: "ubuntu-latest" + if: ${{ false }} + + strategy: + matrix: + php-version: + - "8.0" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Validate Composer" + run: "composer validate" + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Lint" + run: "make lint" + + - name: "Coding Standard" + run: "make cs" + + dependency-analysis: + name: "Dependency Analysis" + + runs-on: "ubuntu-latest" + if: ${{ false }} + + strategy: + matrix: + php-version: + - "8.0" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Composer Require Checker" + run: "make composer-require-checker" + + tests: + name: "Tests" + runs-on: ${{ matrix.operating-system }} + if: ${{ false }} + + strategy: + fail-fast: false + matrix: + php-version: + - "7.3" + - "7.4" + - "8.0" + operating-system: [ubuntu-latest, windows-latest] + script: + - "make tests" + - "make tests-static-reflection" + - "make tests-integration" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: pecl + extensions: ds,mbstring + ini-values: memory_limit=640M + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Transform source code" + if: matrix.php-version != '7.4' && matrix.php-version != '8.0' + run: php bin/transform-source.php + + - name: "Tests" + run: "${{ matrix.script }}" + + tests-old-phpunit: + name: "Tests with old PHPUnit" + runs-on: ${{ matrix.operating-system }} + if: ${{ false }} + + strategy: + fail-fast: false + matrix: + php-version: + - "7.1" + - "7.2" + operating-system: [ubuntu-latest, windows-latest] + script: + - "make tests-coverage" + - "make tests-static-reflection-coverage" + - "make tests-integration-coverage" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: pecl + extensions: ds,mbstring + ini-values: memory_limit=640M + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Downgrade PHPUnit" + run: "composer require --dev phpunit/phpunit:^7.5.20 brianium/paratest:^4.0 --update-with-dependencies" + + - name: "Transform source code" + run: php bin/transform-source.php + + - name: "Tests" + run: "${{ matrix.script }}" + + tests-code-coverage: + name: "Tests with code coverage" + + runs-on: "ubuntu-latest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "7.4" + tools: pecl + extensions: ds + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Tests" + continue-on-error: true + run: | + php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude="~vendor~" vendor/bin/phpunit + + - name: "Coveralls" + if: ${{ false }} + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + composer require twinh/php-coveralls --dev && \ + vendor/bin/php-coveralls --verbose --coverage_clover=tests/tmp/clover.xml --json_path=tests/tmp/coveralls-upload.json + - name: "DeepSource" + env: + DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }} + run: | + curl https://deepsource.io/cli | sh && \ + ./bin/deepsource report --analyzer test-coverage --key php --value-file tests/tmp/clover.xml + + static-analysis: + name: "PHPStan" + runs-on: ${{ matrix.operating-system }} + if: ${{ false }} + + strategy: + fail-fast: false + matrix: + php-version: + - "7.1" + - "7.2" + - "7.3" + - "7.4" + - "8.0" + operating-system: [ubuntu-latest, windows-latest] + script: + - "make phpstan" + - "make phpstan-static-reflection" + - "make phpstan-validate-stub-files" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + extensions: mbstring + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Downgrade PHPUnit" + if: matrix.php-version == '7.1' || matrix.php-version == '7.2' + run: "composer require --dev phpunit/phpunit:^7.5.20 brianium/paratest:^4.0 --update-with-dependencies" + + - name: "Transform source code" + if: matrix.php-version != '7.4' && matrix.php-version != '8.0' + run: php bin/transform-source.php + + - name: "PHPStan" + run: ${{ matrix.script }} + + static-analysis-with-result-cache: + name: "PHPStan with result cache" + if: ${{ false }} + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + extensions: mbstring + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Cache Result cache" + uses: actions/cache@v2 + with: + path: ./tmp + key: "result-cache-v4" + + - name: "PHPStan with result cache" + run: | + make phpstan-result-cache + bin/phpstan clear-result-cache -c build/phpstan.neon + make phpstan-result-cache + echo -e "\n\n" >> src/TrinaryLogic.php + make phpstan-result-cache + make phpstan-result-cache + + - name: "Upload result cache artifact" + uses: actions/upload-artifact@v2 + with: + name: resultCache-ubuntu-latest.php + path: tmp/resultCache.php + + result-cache-e2e-tests: + name: "Result cache E2E tests" + + runs-on: ${{ matrix.operating-system }} + if: ${{ false }} + + strategy: + matrix: + php-version: + - "7.4" + operating-system: [ubuntu-latest, windows-latest] + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + extensions: mbstring + ini-values: memory_limit=256M + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Tests" + run: | + git clone https://github.com/nikic/PHP-Parser.git tests/e2e/PHP-Parser && git -C tests/e2e/PHP-Parser checkout v3.1.5 && composer install --working-dir tests/e2e/PHP-Parser && vendor/bin/phpunit tests/e2e/ResultCacheEndToEndTest.php + + compiler-tests: + name: "Compiler Tests" + if: ${{ false }} + + runs-on: "ubuntu-latest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "7.3" + + - name: "Install dependencies" + run: "composer install --no-dev --no-interaction --no-progress --no-suggest" + + - name: "Transform source code" + run: php bin/transform-source.php + + - name: "Tests" + run: | + cd compiler && \ + composer install --no-interaction && \ + vendor/bin/phpunit -c tests/phpunit.xml tests && \ + ../bin/phpstan analyse -l 8 src tests && \ + php bin/compile && \ + ../tmp/phpstan.phar list + + generate-baseline: + name: "Generate baseline" + if: ${{ false }} + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Generate baseline" + run: | + cp phpstan-baseline.neon phpstan-baseline-orig.neon && \ + make phpstan-generate-baseline && \ + diff phpstan-baseline.neon phpstan-baseline-orig.neon + + e2e-tests: + name: "E2E tests" + runs-on: "ubuntu-latest" + if: ${{ false }} + + strategy: + matrix: + include: + - script: "bin/phpstan analyse -l 8 -a tests/e2e/data/timecop.php tests/e2e/data/timecop.php" + tools: "pecl" + extensions: "timecop-beta" + - script: "bin/phpstan analyse -l 8 -a tests/e2e/data/soap.php tests/e2e/data/soap.php" + extensions: "soap" + - script: "bin/phpstan analyse -l 8 -a tests/e2e/data/soap.php tests/e2e/data/soap.php" + extensions: "" + - script: "bin/phpstan analyse -l 8 tests/e2e/anon-class/Granularity.php" + extensions: "" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "7.4" + tools: ${{ matrix.tools }} + extensions: ${{ matrix.extensions }} + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Test" + run: ${{ matrix.script }} diff --git a/phpstan.neon.dist b/phpstan.neon.dist.bk similarity index 100% rename from phpstan.neon.dist rename to phpstan.neon.dist.bk diff --git a/src/Analyser/FileAnalyser.php b/src/Analyser/FileAnalyser.php index c13f5429b3..f57c628fbc 100644 --- a/src/Analyser/FileAnalyser.php +++ b/src/Analyser/FileAnalyser.php @@ -78,6 +78,9 @@ public function analyseFile( $uniquedAnalysedCodeExceptionMessages = []; $nodeType = get_class($node); foreach ($registry->getRules($nodeType) as $rule) { + // We need to identify unique rules to assign an issue code + $ruleName = get_class($rule); + try { $ruleErrors = $rule->processNode($node, $scope); } catch (\PHPStan\AnalysedCodeException $e) { @@ -147,6 +150,9 @@ public function analyseFile( $canBeIgnored = false; } } + + $message = "{$ruleName}:::{$message}"; + $temporaryFileErrors[] = new Error( $message, $fileName,