Problem/Motivation

We added Prettier, but are not currently using it.

Proposed resolution

Lets now format all our existing code according to the Prettier ruleset.

Remaining tasks

yarn run prettier

Comments

drpal created an issue. See original summary.

GrandmaGlassesRopeMan’s picture

corbacho’s picture

StatusFileSize
new90.91 KB

DO IT

alexpott’s picture

Doing this results in a linting issue...

$ node ./node_modules/eslint/bin/eslint.js --quiet --config=.eslintrc.passing.json .

/Volumes/devdisk/dev/sites/drupal8alt.dev/core/modules/editor/js/editor.admin.es6.js
  294:13  error  'findPropertyValuesOnTag' was used before it was defined  no-use-before-define

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.

:(

ApacheEx’s picture

Status: Active » Needs review
StatusFileSize
new1.13 MB

This patch includes only files which were changed by prettier (#2978964: Use Prettier for formatting core JavaScript).
No lint issues so far :)

yarn run v1.7.0
$ node ./node_modules/eslint/bin/eslint.js --quiet --config=.eslintrc.passing.json .
✨  Done in 12.35s.

Status: Needs review » Needs work

The last submitted patch, 5: 2981652-5.patch, failed testing. View results

ApacheEx’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 MB
new3.71 KB

I think we need to ignore prettier formatting in this file (locale_test.es6.js), because some test cases won't work (prettier reformats double quote to single quote or vise versa):

Before prettier:

Drupal.t('Single Quote t');
Drupal.t('Single Quote \'Escaped\' t');
Drupal.t('Single Quote ' + 'Concat ' + 'strings ' + 't');

Drupal.t("Double Quote t");
Drupal.t("Double Quote \"Escaped\" t");
Drupal.t("Double Quote " + "Concat " + "strings " + "t");

After prettier:

Drupal.t('Single Quote t');
Drupal.t("Single Quote 'Escaped' t");
Drupal.t('Single Quote ' + 'Concat ' + 'strings ' + 't');

Drupal.t('Double Quote t');
Drupal.t('Double Quote "Escaped" t');
Drupal.t('Double Quote ' + 'Concat ' + 'strings ' + 't');

Of course we need to have these test cases - because not everyone uses prettier for custom code :)

So, I've reverted ./core/modules/locale/tests/locale_test.es6.js and added it to .prettierignore

dawehner’s picture

Mhh, doesn't this effects basically every kind of Drupal.t string in core?

ApacheEx’s picture

I've found out,
we have 8 usages which start with Drupal.t("

1) 7 occurrences in locale_test.es6.js - now, it's ignored by prettier.
2) 1 occurrence in content_types.es6.js - no changes after reformat by prettier

so, we are safe.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @ApacheEx, that sounds sensible. In the future we can avoid changes, as we use prettier for new things.

The last submitted patch, 7: 2981652-7.patch, failed testing. View results

ApacheEx’s picture

StatusFileSize
new1.13 MB

Rerolled with the latest 8.6.x changes.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: 2981652-12.patch, failed testing. View results

ApacheEx’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 MB

Forgot to run yarn run build:js.
Should be good now.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xjm’s picture

Title: Format core JavaScript using recently add Prettier » [~Aug. 6 2018] Format core JavaScript using recently add Prettier
Issue tags: +beta target

This is the sort of change we generally schedule in advance for during the beta phase of a minor, to minimize disruption to development and keep the minor branches from diverging in a way that adds merge conflicts. If #2978964: Use Prettier for formatting core JavaScript is completed in time to be backported prior to the beta (week of July 30th) then I would recommend scheduling this issue for ~Aug. 6.

ApacheEx’s picture

StatusFileSize
new1.16 MB

Here we go (what was done in this patch):
1. Rerolled with this task: #2978964: Use Prettier for formatting core JavaScript
2. Included #2978964-38: Use Prettier for formatting core JavaScript to avoid failure tests.
3. Applied #2978964-36: Use Prettier for formatting core JavaScript (see 2978964-36-apply-after-prettier.txt) after run prettier.

now eslint rules are passed.

lauriii’s picture

Title: [~Aug. 6 2018] Format core JavaScript using recently add Prettier » [Aug. 9 2018] Format core JavaScript using recently add Prettier

I'm planning to commit this on Thursday 9th. Let's try to make sure we have a patch that is committable tomorrow around 2 pm UTC.

xjm’s picture

ApacheEx’s picture

@xjm - yes, yes.
I've added ./core/modules/locale/tests/locale_test.es6.js to the .prettierignore

GrandmaGlassesRopeMan’s picture

Status: Needs review » Reviewed & tested by the community

- deleted node_modules directory
- install dependencies
- yarn run lint:core-js-passing
- no errors reported.
- 🎉

The last submitted patch, 14: 2981652-14.patch, failed testing. View results

  • lauriii committed e742590 on 8.7.x
    Issue #2981652 by ApacheEx, corbacho, drpal, dawehner, xjm, alexpott,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Confirmed the same steps and skimmed through the patch quickly to see that it looks correct. Committed to 8.7.x and backported to 8.6.x. Thank you for everyone involved!

corbacho’s picture

StatusFileSize
new918.27 KB

Happy

xjm’s picture

Version: 8.7.x-dev » 8.6.x-dev

Status: Fixed » Closed (fixed)

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