Problem/Motivation

GitLab CI is reporting several eslint errors. Let's fix these.

*****************************************************************************************************************************
These are the current ESLINT errors and warnings 
*****************************************************************************************************************************
$ $CI_PROJECT_DIR/$_WEB_ROOT/core/node_modules/.bin/eslint --no-error-on-unmatched-pattern --ignore-pattern="*.es6.js" --resolve-plugins-relative-to=$CI_PROJECT_DIR/$_WEB_ROOT/core --ext=.js,.yml $_ESLINT_EXTRA . || true
/builds/project/json_field/web/modules/custom/json_field/assets/js/json_field.js
   7:3   error  'use strict' is unnecessary inside of modules  strict
   9:3   error  Unexpected var, use let or const instead       no-var
   9:26  error  Insert `⏎····`                                 prettier/prettier
  13:42  error  Insert `,`                                     prettier/prettier
  14:8   error  Insert `,`                                     prettier/prettier
  15:6   error  Insert `,`                                     prettier/prettier
  24:5   error  Expected method shorthand                      object-shorthand
  27:35  error  Prefer textContent to $.text                   jquery/no-text
  29:6   error  Insert `,`                                     prettier/prettier
  30:5   error  Delete `⏎`                                     prettier/prettier
/builds/project/json_field/web/modules/custom/json_field/modules/json_field_widget/assets/js/json_widget.js
   7:3   error  'use strict' is unnecessary inside of modules                                                                                                                                                                                                         strict
  12:6   error  Delete `⏎···`                                                                                                                                                                                                                                         prettier/prettier
  25:60  error  Insert `.each(`                                                                                                                                                                                                                                       prettier/prettier
  26:9   error  Delete `.each(`                                                                                                                                                                                                                                       prettier/prettier
  27:11  error  Unexpected var, use let or const instead                                                                                                                                                                                                              no-var
  28:11  error  Unexpected var, use let or const instead                                                                                                                                                                                                              no-var
  29:11  error  Unexpected var, use let or const instead                                                                                                                                                                                                              no-var
  30:11  error  Unexpected var, use let or const instead                                                                                                                                                                                                              no-var
  30:22  error  Prefer value to $.val                                                                                                                                                                                                                                 jquery/no-val
  31:11  error  Unexpected var, use let or const instead                                                                                                                                                                                                              no-var
  34:13  error  All 'var' declarations must be at the top of the function scope                                                                                                                                                                                       vars-on-top
  34:13  error  Unexpected var, use let or const instead                                                                                                                                                                                                              no-var
  34:29  error  Replace `Drupal.theme('jsonEditorWrapper',·'json-editor-'·+·$textarea.attr('name'))` with `⏎··············Drupal.theme(⏎················'jsonEditorWrapper',⏎················'json-editor-'·+·$textarea.attr('name'),⏎··············),⏎············`  prettier/prettier
  34:63  error  Unexpected string concatenation                                                                                                                                                                                                                       prefer-template
  38:13  error  All 'var' declarations must be at the top of the function scope                                                                                                                                                                                       vars-on-top
  38:13  error  Unexpected var, use let or const instead                                                                                                                                                                                                              no-var
  41:15  error  Expected method shorthand                                                                                                                                                                                                                             object-shorthand
  42:17  error  Prefer textContent to $.text                                                                                                                                                                                                                          jquery/no-text
  42:32  error  'jsonEditor' was used before it was defined                                                                                                                                                                                                           no-use-before-define
  43:16  error  Insert `,`                                                                                                                                                                                                                                            prettier/prettier
  49:13  error  All 'var' declarations must be at the top of the function scope                                                                                                                                                                                       vars-on-top
  49:13  error  Unexpected var, use let or const instead                                                                                                                                                                                                              no-var
  49:34  error  'JSONEditor' is not defined                                                                                                                                                                                                                           no-undef
  49:45  error  Replace `$editor[0],·Object.assign({},·options,·instanceOptions)` with `⏎··············$editor[0],⏎··············Object.assign({},·options,·instanceOptions),⏎············`                                                                           prettier/prettier
  49:57  error  Use an object spread instead of `Object.assign` eg: `{ ...foo }`                                                                                                                                                                                      prefer-object-spread
  52:14  error  Delete `⏎···········`                                                                                                                                                                                                                                 prettier/prettier
  57:10  error  Insert `,⏎······`                                                                                                                                                                                                                                     prettier/prettier
  58:6   error  Insert `,`                                                                                                                                                                                                                                            prettier/prettier
  62:12  error  Unexpected string concatenation                                                                                                                                                                                                                       prefer-template
  63:4   error  Replace `⏎` with `;`                                                                                                                                                                                                                                  prettier/prettier
✖ 40 problems (40 errors, 0 warnings)

Issue fork json_field-3450116

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

ptmkenny created an issue. See original summary.

damienmckenna’s picture

Thank you.

ptmkenny’s picture

Status: Active » Needs work

Ok, four problems remain:

  26:35  error  Prefer textContent to $.text  jquery/no-text
/builds/issue/json_field-3450116/web/modules/custom/json_field-3450116/modules/json_field_widget/assets/js/json_widget.js
  44:17  error  Prefer textContent to $.text                 jquery/no-text
  44:32  error  'jsonEditor' was used before it was defined  no-use-before-define
  51:36  error  'JSONEditor' is not defined                  no-undef
✖ 4 problems (4 errors, 0 warnings)

I don't know how to fix these.

damienmckenna’s picture

I wonder if listing jsonEditor and JSONEditor in the open and closing parts of the wrapper function would help?

ptmkenny’s picture

Honestly I never really worked with JQuery so I don't understand what's going on here. All my work recently has been in React/TypeScript, so I'm lost about how to fix these issues.

damienmckenna’s picture

I wonder if we could load the JS library as a dev dependency via bowser or something?

damienmckenna’s picture

We're now down to these:

/builds/project/json_field/web/modules/custom/json_field/assets/js/json_field.js
  30:9  error  Insert `··`  prettier/prettier
  31:1  error  Insert `··`  prettier/prettier
/builds/project/json_field/web/modules/custom/json_field/modules/json_field_widget/assets/js/json_widget.js
  47:41  error  'jsonEditor' was used before it was defined  no-use-before-define
  75:36  error  'jsonEditor' is not defined                  no-undef
  75:48  error  'JSONEditor' is not defined                  no-undef
✖ 5 problems (5 errors, 0 warnings)

I don't know what the first two mean? I've never written JS like that.

ptmkenny’s picture

Prettier just does some basic automatic formatting; it wants you to add whitespace even though it shows the dots.

These kind of fixes can be annoying to do manually, but you can download the patch generated in the build artifacts for the eslint job and apply that, which will automatically fix the things flagged by prettier in most cases.

damienmckenna’s picture

Oh, I thought that meant to add a prefix of ".." in front of a line, not to just indent it. Thanks for the tip of checking the eslint artifacts, I applied the patch, will see what difference it makes.

damienmckenna’s picture

Ok, down to one error left:

/builds/project/json_field/web/modules/custom/json_field/modules/json_field_widget/assets/js/json_widget.js
  49:41  error  'jsonEditor' was used before it was defined  no-use-before-define
✖ 1 problem (1 error, 0 warnings)
damienmckenna’s picture

The tests now pass! Need to manually test it to make sure it still works properly.

ptmkenny’s picture

Status: Needs work » Needs review
damienmckenna’s picture

Status: Needs review » Needs work

In local testing this isn't working anymore - the onChange() callback isn't being called. I also had to revert one of the commits to make the editor load in the first place, so clearly the changes were going in the wrong direction.

damienmckenna’s picture

This was shared via Slack, it might be helpful: https://brianperry.dev/posts/2024/matching-drupal-eslint/

acbramley made their first commit to this issue’s fork.

acbramley’s picture

Status: Needs work » Needs review

I've fixed the last esllint issue, the problem was that onChange was being declared as a function, rather than a property with an anonymous function. That should be the last issue, although I don't know how to manually test all those changes I'm happy to do so to get this merged and unblock 8.x-1.4 (which blocks a stable D11 release)

acbramley’s picture

It still didn't like that... so instead what if we just pass the options directly into the constructor.

nicxvan’s picture

Status: Needs review » Needs work

Sorry I don't have the time to look into this, but I tried testing this locally.

I pulled this down to test and I get the following error in the console:

Uncaught ReferenceError: jsonEditor is not defined.

) (jQuery, Drupal, drupalSettings, jsonEditor, JSONEditor);

ptmkenny’s picture

@nicxvan Could you please provide the steps you took to get that error?

nicxvan’s picture

Install dev
Apply the patch
Change the form mode setting to the editor
Edit a page that has the json field
Check Console

I'm on my phone so I can't check the editor name.

acbramley’s picture

Do we really need this to block a stable release? If the module works on D11 it'd be great to get a stable release out ASAP and work on CI tweaks afterwards.

nicxvan’s picture

I'm ok with this not blocking d11, I don't actually use that feature of the module, but to be clear the code editor display doesn't work.

acbramley’s picture

@nicxvan I mean this issue is just about fixing CSS/JS linting errors. Are you saying that the editor doesn't work even without these changes?

nicxvan’s picture

I don't think the code editor works period. I only tested this issue because it seems to be blocking the d11 release and I saw that bit of js changed.

I think the code editor is a separate issue and would make sense as a follow up.

If you all agree I'm happy to rtbc based on my review let me know.

ptmkenny’s picture

If the code editor doesn't currently work, that needs to be opened as a separate issue, and this issue should be made dependent on that one. I don't think it makes sense to commit a code cleanup if the underlying code is broken.

nicxvan’s picture

There is no reason to make this dependent, if this gets in, then eslint will enforce the fix is formatted properly anyway.

Unless the maintainers feel differently.

nicxvan’s picture

Status: Needs work » Reviewed & tested by the community

I just came back to this, the changes do fix the eslint and I confirmed the issues I found are pre-existing.

RTBC and I'll open an issue for the other issue.

ptmkenny’s picture

Status: Reviewed & tested by the community » Postponed

I don't think this can be RTBC when the code that is "fixed" by this isn't working, because there's no way to test if these fixes are valid. Postponing on #3478943: JSON-specific WYSIWYG editor widget does not seem to work

nicxvan’s picture

Status: Postponed » Reviewed & tested by the community

Why would you postpone this, the code editor is broken even without these changes applied.

It has nothing to do with linting so this should be good to merge.

You can test that these "fixes" are valid by reviewing what they are aiming to fix, eslint.

Gonna put this back in rtbc so the maintainers can weigh in.

ptmkenny’s picture

@nicxvan My point is that for automated tests like eslint to "pass", it is not enough for the GitLab CI scan to show no errors. There should be some manual testing where we confirm that behaviors of the module influenced by the code work as expected.

It isn't possible to do such testing when the underlying behavior (the code editor) is broken, so I think this issue should be "postponed"-- otherwise you're committing changes to code that is still broken, and what's the point of that?

nicxvan’s picture

The other tests cover the functionality, and as I mentioned I confirmed the bug exists even without these changes.

You commit this one so it unblocks the issues that were depending on it and you resolve the bug in a dedicated issue.

If you merge this in then the issue resolving the code editor bug will also have eslint enforced.

You do not want to introduce new bugs or regressions in an issue, but that is not what is happening here the bug was not introduced with these changes.

ptmkenny’s picture

Ok, I'll just agree to disagree here.

In any case, it seems you want this committed for a stable D11 release, but if this issue is a release blocker, then almost certainly #3478943: JSON-specific WYSIWYG editor widget does not seem to work is also a release blocker because a core feature of the module is broken.

nicxvan’s picture

I'm happy to chat further on slack, I'm not sure this issue is where to have the discussion.

It's up to the maintainers to decide if it's a blocker to 1.4 release.

However, even core doesn't delay releasing a feature or bug fix because an unrelated bug was discovered.

The feature is broken in the current release, nothing is lost by releasing other features like d11 support. If it were a regression it would be different, but it's not a regression. It's an unrelated bug I discovered and opened an issue for.

damienmckenna’s picture

Title: Fix eslint test » Fix eslint tests

Thank you for the discussion and for opening the separate issue. Now that we have a good point to work from with the included JS, let's work to fix the other issue as part of this release - people who desperately need the D11 support will have to use the dev release for a little while longer.

damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you.

Status: Fixed » Closed (fixed)

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

nicxvan’s picture