Skip to content

Documentation for Magento2.Templates.ThisInTemplate rule #108

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

Closed
ihor-sviziev opened this issue Jun 5, 2019 · 5 comments
Closed

Documentation for Magento2.Templates.ThisInTemplate rule #108

ihor-sviziev opened this issue Jun 5, 2019 · 5 comments
Assignees
Labels
documentation Rule documentation update enhancement Improvements to existing rules Progress: good first issue Issues is easy to get started with

Comments

@ihor-sviziev
Copy link
Collaborator

Description

Right now the only one option to use helpers inside blocks - is following code:
$this->helper(<helper_class>), but this Magento2.Templates.ThisInTemplate rule complains against it. As result - we have to add to ignore Magento2.Templates.ThisInTemplate in many view files.

Examples:
Try to find "Magento2.Templates.ThisInTemplate" in following commit:
magento/magento2@514e3d0

Expected behavior

We should not have any complains from static tests when running valid code

Benefits

We will not have useless disabling of this rule

Additional information

Option 1: this code example should be added to exception list
Option 2: there should be developed or provided recommended solution how to avoid it

@ihor-sviziev ihor-sviziev added the enhancement Improvements to existing rules label Jun 5, 2019
@lenaorobei
Copy link
Contributor

lenaorobei commented Jun 5, 2019

@ihor-sviziev thanks raising this question.

First of all we need to define correct recommendation here. On the one hand the use of helpers is in general discouraged, on the other hand we have legacy code that requires significant refactoring in order to archive this.

Do we want to change sniff behavior and allow $this->helper(<helper_class>) or we want to suppress such line for now and refactor in future?

Would you be interested in raising this question during the next architecture discussion?

@lenaorobei lenaorobei added the need to discuss Rule requires discussion label Jun 5, 2019
@ihor-sviziev
Copy link
Collaborator Author

Hi @lenaorobei,
Unfortunately I'll not be able present on next architecture discussion. Could you raise this question instead of me?
Thank you

@lenaorobei
Copy link
Contributor

Sure, I'll do that.

@lenaorobei
Copy link
Contributor

lenaorobei commented Jun 19, 2019

This issue was discussed during architecture discussion magento/architecture#183. Notes:

  • The use of helpers is in general discouraged.
  • Magento2.Templates.ThisInTemplate rule should remain the same.
  • $this->helper(<helper_class>) code should be refactored, blocks should contain all necessary dependencies.
  • ViewModel should be used.

I suggest adding documentation forThisInTemplateSniff.md like ForeachArrayMergeSniff.md and describe this recommendation.

I'm going to change purpose of this ticket to adding .md page with How to Fix section.
Extended message can be added to the rule output as well.

@lenaorobei lenaorobei added documentation Rule documentation update and removed enhancement Improvements to existing rules need to discuss Rule requires discussion labels Jun 19, 2019
@lenaorobei lenaorobei changed the title Improve/replace Magento2.Templates.ThisInTemplate rule Documentation for Magento2.Templates.ThisInTemplate rule Jun 19, 2019
@lenaorobei lenaorobei added enhancement Improvements to existing rules Progress: good first issue Issues is easy to get started with labels Jun 19, 2019
lenaorobei referenced this issue Jul 17, 2019
…MEQP2 sniffs

- Decoupled MEQP2 sniffs from MEQP coding standard
- Skipped false-positive and dynamic sniffs for now
@diazwatson diazwatson self-assigned this Jul 25, 2019
diazwatson added a commit to diazwatson/magento-coding-standard that referenced this issue Jul 28, 2019
lenaorobei added a commit that referenced this issue Jul 29, 2019
…ateDoc

#108 Enhance doc for ThisInTemplate rule
@lenaorobei
Copy link
Contributor

#119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Rule documentation update enhancement Improvements to existing rules Progress: good first issue Issues is easy to get started with
Projects
None yet
Development

No branches or pull requests

3 participants