-
Notifications
You must be signed in to change notification settings - Fork 153
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
AC-1156: Move custom eslint tests to magento-coding-standard repo #262
AC-1156: Move custom eslint tests to magento-coding-standard repo #262
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a new GitHub actions workflow to run these eslint tests on top of this repo, similar to phpcs?
Pls not forget moving the following changes |
@ihor-sviziev Thanks for your comments! will take care of the proposed changes magento/magento2@f0f779a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @loginesta ! Please see my comments
eslint/Tests/EslintUnitTest.php
Outdated
$result | ||
); | ||
|
||
assertStringContainsString($expectedMessage, $output[2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the inherited methods instead of importing a function
assertStringContainsString($expectedMessage, $output[2]); | |
$this->assertStringContainsString($expectedMessage, $output[2]); |
eslint/Tests/EslintUnitTest.php
Outdated
assertStringContainsString($expectedMessage, $output[2]); | ||
} | ||
|
||
public function testBindUnbind() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to extract the abstract testcase with common functionality and introduce a child testcase class for each rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about defining everything in an array and loop in?
foreach ($this->rules as $rule) {
exec(self::command . __DIR__ . '/' . $rule['path'], $output, $result);
$this->assertStringContainsString($rule['message'], $output[2]);
}
eslint/Tests/EslintUnitTest.php
Outdated
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\User\Block\Role\Tab; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the unit tests to correct the Magento2/Tests/Eslint
folder and correct the namespace
eslint/Tests/EslintUnitTest.php
Outdated
|
||
class EslintUnitTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
const command = '../node_modules/.bin/eslint -c eslint/.eslintrc --rulesdir eslint/rules '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not forget to specify access level
const command = '../node_modules/.bin/eslint -c eslint/.eslintrc --rulesdir eslint/rules '; | |
private const command = '../node_modules/.bin/eslint -c eslint/.eslintrc --rulesdir eslint/rules '; |
.github/workflows/php.yml
Outdated
@@ -48,3 +48,6 @@ jobs: | |||
|
|||
- name: Run code style suite | |||
run: vendor/bin/phpcs --standard=Magento2 Magento2/Helpers/ Magento2/Sniffs | |||
|
|||
- name: Run ESLint | |||
run: ../node_modules/.bin/eslint -c eslint/.eslintrc --rulesdir eslint/rules eslint/rules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs additional step(s) to install eslint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
eslint/rules/jquery-no-trim.js
Outdated
type: 'suggestion', | ||
docs: { | ||
description: 'Disallow the use of the deprecated `trim` function', | ||
category: 'Possible Errors', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use custom categorization?
category: 'Possible Errors', | |
category: 'jQuery deprecated functions', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually thinking of a more customised name for category
.
But, not sure about it since I found this: https://eslint.org/docs/rules/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed offline. proceeding to update with proposed changes
.github/workflows/php.yml
Outdated
@@ -50,4 +50,5 @@ jobs: | |||
run: vendor/bin/phpcs --standard=Magento2 Magento2/Helpers/ Magento2/Sniffs | |||
|
|||
- name: Run ESLint | |||
run: ../node_modules/.bin/eslint -c eslint/.eslintrc --rulesdir eslint/rules eslint/rules | |||
uses: stefanoeb/eslint-action@1.0.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like that's not the right choice
https://github.com/stefanoeb/eslint-action#%EF%B8%8F%EF%B8%8F%EF%B8%8F-you-dont-need-this-action-%EF%B8%8F%EF%B8%8F%EF%B8%8F
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And one more - it doesn't make any sense running it on different PHP versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I need the line that is referring to yarn
since it's something external to the project.
Or maybe npm install
because we are actually using node_modules...
Anyway, I'm going to try to see if any of these work. Thanks @ihor-sviziev
@ihor-sviziev do you refer to changes on this file right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the updates @loginesta !
Can you please update the readme with instructions on how to run the eslint tests.
Also, can you please squash the changes in this pull request to a single commit
|
||
abstract class AbstractEslintTestCase extends TestCase | ||
{ | ||
protected function assertFileContainsError(string $testFile, array $expectedMessages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add strict types and phpdocs to the added tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be done, please check it out!
* @param string $testFile | ||
* @param array $expectedMessages | ||
*/ | ||
protected function assertFileContainsError(string $testFile, array $expectedMessages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected function assertFileContainsError(string $testFile, array $expectedMessages) | |
protected function assertFileContainsError(string $testFile, array $expectedMessages): void |
*/ | ||
class AndSelfTest extends AbstractEslintTestCase | ||
{ | ||
public function testExecute() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And remaining functions as well
public function testExecute() | |
public function testExecute(): void |
… repo - Fix typo in README and add missing 'void' on unit tests
@magento import pr to magento-commerce/magento-coding-standard |
@loginesta an error occurred during the Pull Request import. |
@magento import pr to magento-commerce/magento-coding-standard |
@loginesta an error occurred during the Pull Request import. |
@magento import pr to magento-commerce/magento-coding-standard |
@loginesta the Pull Request is successfully imported. |
- name: Install dependencies | ||
run: npm install | ||
- name: Run ESLint | ||
run: npm run eslint -- eslint/rules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be separated into a different workflow to run the tests on different nodejs versions, also I don't think we should run eslint tests on different PHP versions
@@ -25,6 +25,9 @@ jobs: | |||
name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies | |||
|
|||
steps: | |||
- name: Setup node | |||
uses: actions/setup-node@v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From readme file:
https://github.com/actions/setup-node
https://jira.corp.magento.com/browse/AC-1156 Move custom eslint tests to magento-coding-standard repo