Fix eslint issues

Created on 9 May 2024, 10 months ago

Problem/Motivation

The GitLab CI template eslint scan identifies several issues:

****************************************************************************************************************************
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/issue/rrssb-3446285/web/modules/custom/rrssb-3446285/drupalci.yml
   4:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
   5:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
   6:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
   7:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
   8:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
  19:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
/builds/issue/rrssb-3446285/web/modules/custom/rrssb-3446285/rrssb.demo.js
   1:1   error  Expected an assignment or function call and instead saw an expression  no-unused-expressions
   1:11  error  Insert `·`                                                             prettier/prettier
   1:23  error  Shadowing of global property 'undefined'                               no-shadow-restricted-names
   2:3   error  'use strict' is unnecessary inside of modules                          strict
   4:3   error  $.ready is not allowed                                                 jquery/no-ready
   4:29  error  Insert `·`                                                             prettier/prettier
   5:5   error  Prefer dispatchEvent + form.submit() to $.submit                       jquery/no-submit
   6:7   error  Unexpected var, use let or const instead                               no-var
   7:38  error  Insert `·`                                                             prettier/prettier
   8:9   error  Unexpected var, use let or const instead                               no-var
  10:25  error  Expected '===' and instead saw '=='                                    eqeqeq
  11:34  error  Prefer matches to $.is                                                 jquery/no-is
  11:45  error  Replace `":checked"` with `':checked'`                                 prettier/prettier
  12:12  error  Delete `⏎·········`                                                    prettier/prettier
  14:34  error  Prefer value to $.val                                                  jquery/no-val
  19:7   error  Prefer getComputedStyle to $.css                                       jquery/no-css
  20:7   error  Prefer getComputedStyle to $.css                                       jquery/no-css
  21:7   error  'rrssbConfigAll' is not defined                                        no-undef
/builds/issue/rrssb-3446285/web/modules/custom/rrssb-3446285/rrssb.init.js
   7:3   error  'use strict' is unnecessary inside of modules                                                                                                                          strict
  10:5   error  Expected method shorthand                                                                                                                                              object-shorthand
  11:7   error  for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array  no-restricted-syntax
  11:7   error  The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype                                                             guard-for-in
  11:12  error  All 'var' declarations must be at the top of the function scope                                                                                                        vars-on-top
  11:12  error  Unexpected var, use let or const instead                                                                                                                               no-var
  12:11  error  Unexpected string concatenation                                                                                                                                        prefer-template
  12:42  error  Function declared in a loop contains unsafe references to variable(s) 'buttonSet'                                                                                      no-loop-func
  12:50  error  Replace `()` with `·()·`                                                                                                                                               prettier/prettier
  16:6   error  Insert `,`                                                                                                                                                             prettier/prettier
/builds/issue/rrssb-3446285/web/modules/custom/rrssb-3446285/rrssb.nodetype.js
   2:3   error  'use strict' is unnecessary inside of modules  strict
   5:5   error  Expected method shorthand                      object-shorthand
   6:7   error  Unexpected var, use let or const instead       no-var
   8:9   error  Unexpected var, use let or const instead       no-var
  11:19  error  Prefer textContent to $.text                   jquery/no-text
  15:6   error  Insert `,`                                     prettier/prettier
  16:5   error  Delete `⏎`                                     prettier/prettier
✖ 41 problems (41 errors, 0 warnings)
  19 errors and 0 warnings potentially fixable with the `--fix` option.
$ printf "$DIVIDER\nNow running ESLINT using the --fix option. Any errors shown below are not fixable automatically.$DIVIDER\n"
 
*****************************************************************************************************************************
Now running ESLINT using the --fix option. Any errors shown below are not fixable automatically. 
*****************************************************************************************************************************
$ $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 --fix . || EXIT_CODE_FIX=$?
/builds/issue/rrssb-3446285/web/modules/custom/rrssb-3446285/drupalci.yml
   4:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
   5:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
   6:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
   7:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
   8:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
  19:7  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
/builds/issue/rrssb-3446285/web/modules/custom/rrssb-3446285/rrssb.demo.js
   1:1   error  Expected an assignment or function call and instead saw an expression  no-unused-expressions
   1:24  error  Shadowing of global property 'undefined'                               no-shadow-restricted-names
   2:3   error  $.ready is not allowed                                                 jquery/no-ready
   3:5   error  Prefer dispatchEvent + form.submit() to $.submit                       jquery/no-submit
   8:25  error  Expected '===' and instead saw '=='                                    eqeqeq
   9:34  error  Prefer matches to $.is                                                 jquery/no-is
  11:34  error  Prefer value to $.val                                                  jquery/no-val
  16:7   error  Prefer getComputedStyle to $.css                                       jquery/no-css
  17:7   error  Prefer getComputedStyle to $.css                                       jquery/no-css
  18:7   error  'rrssbConfigAll' is not defined                                        no-undef
/builds/issue/rrssb-3446285/web/modules/custom/rrssb-3446285/rrssb.init.js
   9:7   error  for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array  no-restricted-syntax
   9:7   error  The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype                                                             guard-for-in
   9:12  error  All 'var' declarations must be at the top of the function scope                                                                                                        vars-on-top
   9:12  error  Unexpected var, use let or const instead                                                                                                                               no-var
  10:42  error  Function declared in a loop contains unsafe references to variable(s) 'buttonSet'                                                                                      no-loop-func
/builds/issue/rrssb-3446285/web/modules/custom/rrssb-3446285/rrssb.nodetype.js
  9:19  error  Prefer textContent to $.text  jquery/no-text
✖ 22 problems (22 errors, 0 warnings)

Let's fix these.

📌 Task
Status

Needs work

Version

2.0

Component

Code

Created by

🇯🇵Japan ptmkenny

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ptmkenny
  • Merge request !13eslint fixes → (Open) created by ptmkenny
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 10 months ago
    1 pass
  • Pipeline finished with Failed
    10 months ago
    Total: 139s
    #168850
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 10 months ago
    1 pass
  • 🇯🇵Japan ptmkenny

    Since eslint flags some issues related to drupalci.yml, I removed it and added Drupal 9 testing to the GitLab CI config instead.

  • Pipeline finished with Failed
    10 months ago
    Total: 170s
    #168855
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 10 months ago
    1 pass
  • Pipeline finished with Failed
    10 months ago
    Total: 142s
    #168873
  • Status changed to Needs work 10 months ago
  • 🇯🇵Japan ptmkenny

    The MR fixes many of the identified issues.

    The following remain:

    *****************************************************************************************************************************
    Now running ESLINT using the --fix option. Any errors shown below are not fixable automatically. 
    *****************************************************************************************************************************
    $ $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 --fix . || EXIT_CODE_FIX=$?
    /builds/issue/rrssb-3446297/web/modules/custom/rrssb-3446297/rrssb.demo.js
       1:1   error  Expected an assignment or function call and instead saw an expression  no-unused-expressions
       1:24  error  Shadowing of global property 'undefined'                               no-shadow-restricted-names
       2:3   error  $.ready is not allowed                                                 jquery/no-ready
       3:5   error  Prefer dispatchEvent + form.submit() to $.submit                       jquery/no-submit
       9:34  error  Prefer matches to $.is                                                 jquery/no-is
      11:34  error  Prefer value to $.val                                                  jquery/no-val
      16:7   error  Prefer getComputedStyle to $.css                                       jquery/no-css
      17:7   error  Prefer getComputedStyle to $.css                                       jquery/no-css
      18:7   error  'rrssbConfigAll' is not defined                                        no-undef
    /builds/issue/rrssb-3446297/web/modules/custom/rrssb-3446297/rrssb.init.js
      9:7  error  for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array  no-restricted-syntax
      9:7  error  The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype                                                             guard-for-in
    /builds/issue/rrssb-3446297/web/modules/custom/rrssb-3446297/rrssb.nodetype.js
      9:19  error  Prefer textContent to $.text  jquery/no-text
    ✖ 12 problems (12 errors, 0 warnings)
    

    These are mostly from eslint-plugin-no-jquery. I rarely work with jQuery, so I'm setting to "Needs work" and hopefully someone experienced in jQuery can fix them.

Production build 0.71.5 2024