This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Adding static analysis topic from wiki #8547
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c11d415
Adding new topic from wiki
dobooth a49bd1f
Update src/guides/v2.3/test/static/static-analysis.md
dobooth 059ba8e
Update src/guides/v2.3/test/static/static-analysis.md
dobooth fb0ba9b
Update src/guides/v2.3/test/static/static-analysis.md
dobooth 86fc83e
Update src/guides/v2.3/test/static/static-analysis.md
dobooth 54f19e9
Merge branch 'master' into db_static_analysis
dobooth d9d579a
Apply suggestions from code review
dobooth 9beb6b8
Merge branch 'master' into db_static_analysis
dobooth 1621a8e
Update src/guides/v2.3/test/static/static-analysis.md
dobooth 70c4188
Adding spaces
dobooth 06cc252
Added correct spaces this time
dobooth a6f7fd5
Merge branch 'master' into db_static_analysis
dobooth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,80 @@ | ||||||
--- | ||||||
group: testing | ||||||
title: Setting up static analysis | ||||||
functional_areas: | ||||||
- Testing | ||||||
- test | ||||||
--- | ||||||
|
||||||
## Introduction | ||||||
|
||||||
This document provides setup steps to get most static analyzers that are used in our build pipeline working locally in PHPStorm. This guide is written specifically for those using PHPStorm on MacOS. | ||||||
|
||||||
## Before you begin | ||||||
|
||||||
If you haven't already, make sure that node and npm are installed. Then, in the Magento root directory, run `npm install`. After installation, ensure there is a `node_modules` directory in the root of your project before proceeding. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are generally accepted as lowercase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case (please add @hguthrie's suggestion for emphasis)
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
{:bs-callout-info} | ||||||
For all of the static configuration installations below involving the PHPStorm Preferences dialog, make sure you are clicking the "Apply" button before clicking "OK" to close the Preferences dialog. | ||||||
|
||||||
## Javascript Code Style check | ||||||
|
||||||
{:.bs-callout-info} | ||||||
JSCS is deprecated in PHPStorm 2020.2. It must be installed via a plugin. | ||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
1. Go to PHPStorm preferences > Languages & Frameworks > JavaScript > Code Quality Tools > JSCS. | ||||||
1. Check "Enable" if it is unchecked. | ||||||
1. Enter the path to your node binary (the result of outputting `which node` in your terminal). | ||||||
1. Enter the path to your JSCS package: `[magento_root]/node_modules/jscs` | ||||||
1. Click the "Configuration File" radio button and in the adjacent input field enter the path to the JSCS file Magento uses, which is located in `dev/tests/static/testsuite/Magento/Test/Js/_files/jscs/.jscsrc`. | ||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
 | ||||||
|
||||||
To verify it works, in any JS file add `snake_case: [],` to any object literal and you should see warning about object key not being camel cased. | ||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
## ESLint | ||||||
|
||||||
1. Go to PHPStorm preferences > Languages & Frameworks > JavaScript > Code Quality Tools > ESLint. | ||||||
1. Click the "Manual ESLint configuration" radio button. | ||||||
1. Fill in the adjacent input fields with the path to your node binary (the result of outputting `which node` in your terminal). | ||||||
1. Enter the path to your ESLint package: `[magento_root]/node_modules/eslint` | ||||||
1. Click the "Configuration File" radio button and in the adjacent input field enter the path to the ESLint file Magento uses, which is located in `dev/tests/static/testsuite/Magento/Test/Js/_files/eslint/.eslintrc-magento`. | ||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
See the image below for example configuration: | ||||||
|
||||||
 | ||||||
|
||||||
To verify it works, in any JS file add `/** Hello world */` as a doc comment to any method, you should see a warning about the comment being on one line. | ||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
## PHPCS | ||||||
|
||||||
1. Go to PHPStorm preferences > Languages & Frameworks > PHP > Quality Tools > PHP_CodeSniffer. | ||||||
1. Click the `...` button to bring up another configuration modal. | ||||||
1. Enter the PHP_CodeSniffer path: `[magento_root]/vendor/bin/phpcs` | ||||||
|
||||||
### Configuring for Magento Coding Standard | ||||||
|
||||||
1. Go to the [Magento Coding Standard GitHub Repository](https://github.com/magento/magento-coding-standard) | ||||||
1. Follow instructions within the README to install the Magento Coding Standard for PHPCS. Verify it is installed with `vendor/bin/phpcs -i`. You should see `Magento2` in the output. | ||||||
1. Go to PHPStorm preferences > Editor > Inspections, and in the adjacent window go to PHP > Quality Tools > PHP_CodeSniffer validation. | ||||||
1. Under Coding Standard dropdown, select `Magento2`. | ||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
See the image below for example configuration: | ||||||
|
||||||
 | ||||||
|
||||||
To verify it works, add the following PHP snippet: `$base = basename($_SERVER['SCRIPT_FILENAME']);`. It should give you a warning about use of `basename` being forbidden as well as use of superglobals. | ||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
## PHPMD | ||||||
|
||||||
1. Go to PHPStorm preferences > Languages & Frameworks > PHP > Quality Tools > Mess Detector. | ||||||
1. Click the `...` button to bring up another configuration modal. | ||||||
1. Enter the PHP Mess Detector path: `[magento_root]/vendor/phpmd/phpmd/src/bin/phpmd` | ||||||
1. Go to PHPStorm preferences > Editor > Inspections and in the adjacent window go to > PHP > Quality Tools > PHP Mess Detector validation. | ||||||
1. Under custom rulesets, add the path to the PHPMD ruleset Magento uses: `[magento_root]/dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml` | ||||||
|
||||||
See the image below for example configuration: | ||||||
|
||||||
 | ||||||
|
||||||
To verify it works, add an unused private method to a class and you should see a warning from PHPMD about it not being used. | ||||||
dobooth marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../v2.3/test/static/static-analysis.md |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.