Problem/Motivation

Part of #2571965: [meta] Fix PHP coding standards in core, stage 1.
Sniff for coding standard is not implemented.

<rule ref="Drupal.Semantics.FunctionT.NotLiteralString"/>

Steps to reproduce

Proposed resolution

Add <rule ref="Drupal.Semantics.FunctionT.NotLiteralString"/> to phpcs.xml.dist
Add ignore lines where it can't be changed to using only literals. That is currently 70 lines.

Remaining tasks

Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3123067

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jungle created an issue. See original summary.

longwave’s picture

Also a lot of false positives here, e.g. the definition of t() itself, a test of the TranslatableMarkup object, etc.

munish.kumar’s picture

Assigned: Unassigned » munish.kumar
munish.kumar’s picture

Assigned: munish.kumar » Unassigned

Version: 9.0.x-dev » 9.1.x-dev

Drupal 9.0.10 was released on December 3, 2020 and is the final full bugfix release for the Drupal 9.0.x series. Drupal 9.0.x will not receive any further development aside from security fixes. Sites should update to Drupal 9.1.0 to continue receiving regular bugfixes.

Drupal-9-only bug reports should be targeted for the 9.1.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.2.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Here are some examples of the lines identified by this sniff.

  • $translatable_label = new TranslatableMarkup($this->randomMachineName());
  • new TranslatableMarkup(new TranslatableMarkup('foo', [], [], $translation));
  • $label = $this->t($group, [], ['context' => 'breakpoint']);

Perhaps this sniff is one not to implement? Or does it need more work?

spokje’s picture

Issue tags: +Coding standards

Version: 9.1.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
quietone’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

This one seems straightforward as it's adding the ignore line.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs followup

When I read the issue title I was like uhoh I hope I agree with the implementation of this rule by coder as some of coder's opinions are highly debatable. So I reviewed all the places where we are adding skips and I think this shows the value of the rule. There are things we would not have done in core if this rule was present - so that is great. However that means I think we should add follow-ups to address all these places where we are skipping the rule and should not be.

quietone’s picture

Status: Needs work » Needs review

Made lots of followups and committed the suggestions made in the MR. Setting back to NR.

smustgrave’s picture

Should todos be placed next to the ignore comments?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs followup +Needs Review Queue Initiative

Removing the follow up tag as appears @quietone did all that.

Disregard my comment in #19 seeing other phpcs ignores I don't see todos.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

The MR has conflicts with changes in HEAD

quietone’s picture

Status: Needs work » Needs review

Rebased and added ignore for two recent changes.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems fine.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Another question on the MR.

smustgrave’s picture

Status: Needs review » Needs work

For the 1 suggestion from @catch in the MR.

quietone’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to be addressed.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Couple of questions on the MR

quietone’s picture

Status: Needs work » Needs review

I expanded the followup to include all three methods that raised questions, \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::label, \Drupal\breakpoint\BreakpointManager::getGroupLabel, and \Drupal\breakpoint\Breakpoint::getLabel. That will allow the sniff to be enabled, and prevent further violations, and leave the existing code as is.

smustgrave’s picture

Resolved most of the threads but the 3 could use some feedback on.

quietone’s picture

Rebased.

Resolved most of the threads but the 3 could use some feedback on.

Feedback on what? What are the questions that need to be answered?

smustgrave’s picture

Status: Needs review » Needs work

Needs manual rebase.

As mentioned there are a number of these floating around if you want to focus on one and ping that to me I'll prioritize it @quietone, so you don't have to keep rebasing a dozen of them.

quietone’s picture

Status: Needs work » Needs review

I have thought about that but I also like that the changes are less when rebasing frequently.

Rebase and add more ignore lines.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

No worries just made the offer to help. But if you don't mind rebasing I'll keep reviewing.

Latest rebase seems fine.

  • larowlan committed b49cc195 on 11.x
    Issue #3123067 by quietone, smustgrave, alexpott, catch, larowlan: Fix '...

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 11.x - fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.