Skip to content
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

Merged
merged 2 commits into from
Sep 20, 2021

Conversation

loginesta
Copy link
Contributor

https://jira.corp.magento.com/browse/AC-1156 Move custom eslint tests to magento-coding-standard repo

Copy link
Collaborator

@ihor-sviziev ihor-sviziev left a 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?

@ihor-sviziev
Copy link
Collaborator

Pls not forget moving the following changes

magento/magento2@f0f779a

@loginesta
Copy link
Contributor Author

@ihor-sviziev Thanks for your comments! will take care of the proposed changes magento/magento2@f0f779a
Also, please note this is still WIP

@loginesta loginesta marked this pull request as ready for review September 14, 2021 11:59
Copy link
Member

@sivaschenko sivaschenko left a 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

$result
);

assertStringContainsString($expectedMessage, $output[2]);
Copy link
Member

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

Suggested change
assertStringContainsString($expectedMessage, $output[2]);
$this->assertStringContainsString($expectedMessage, $output[2]);

assertStringContainsString($expectedMessage, $output[2]);
}

public function testBindUnbind()
Copy link
Member

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

Copy link
Contributor Author

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]);
}

* See COPYING.txt for license details.
*/

namespace Magento\User\Block\Role\Tab;
Copy link
Member

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


class EslintUnitTest extends \PHPUnit\Framework\TestCase
{
const command = '../node_modules/.bin/eslint -c eslint/.eslintrc --rulesdir eslint/rules ';
Copy link
Member

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

Suggested change
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 ';

@@ -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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

type: 'suggestion',
docs: {
description: 'Disallow the use of the deprecated `trim` function',
category: 'Possible Errors',
Copy link
Member

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?

Suggested change
category: 'Possible Errors',
category: 'jQuery deprecated functions',

Copy link
Contributor Author

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/

Copy link
Contributor Author

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

@@ -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
Copy link
Collaborator

@ihor-sviziev ihor-sviziev Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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

Copy link
Contributor Author

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

@loginesta
Copy link
Contributor Author

magento/magento2@f0f779a

@ihor-sviziev do you refer to changes on this file right?
dev/tests/static/testsuite/Magento/Test/Js/_files/eslint/.eslintrc
In order to use ./.eslintrc-misc instead of ./.eslintrc-tinymce

Copy link
Member

@sivaschenko sivaschenko left a 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)
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function assertFileContainsError(string $testFile, array $expectedMessages)
protected function assertFileContainsError(string $testFile, array $expectedMessages): void

*/
class AndSelfTest extends AbstractEslintTestCase
{
public function testExecute()
Copy link
Member

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

Suggested change
public function testExecute()
public function testExecute(): void

sivaschenko
sivaschenko previously approved these changes Sep 17, 2021
… repo

- Fix typo in README and add missing 'void' on unit tests
@loginesta
Copy link
Contributor Author

@magento import pr to magento-commerce/magento-coding-standard

@m2-github-services
Copy link
Contributor

@loginesta an error occurred during the Pull Request import.

@loginesta
Copy link
Contributor Author

@magento import pr to magento-commerce/magento-coding-standard

@m2-github-services
Copy link
Contributor

@loginesta an error occurred during the Pull Request import.

@loginesta
Copy link
Contributor Author

@magento import pr to magento-commerce/magento-coding-standard

@m2-github-services
Copy link
Contributor

@loginesta the Pull Request is successfully imported.

Comment on lines +40 to +43
- name: Install dependencies
run: npm install
- name: Run ESLint
run: npm run eslint -- eslint/rules
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants