Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-75365

ESLint should support ES6 from 40 onwards as standard

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0.2, 4.0.5
    • 4.0.6
    • JavaScript
    • MOODLE_400_STABLE
    • MOODLE_400_STABLE
    • MDL-75365-400
    • MDL-75365-master
    • Hide

      This issue will be tested by CI as we build and lint all files anyway.

      To further test, you can:

      1. install moodle-local_ci and moodle-local_codechecker

        git clone https://github.com/moodlehq/moodle-local_ci local/ci
        git clone https://github.com/moodlehq/moodle-local_codechecker local/codechecker
        cd local/ci
        composer install
        cd -
        

      2. Install JS dependencies

        npm i
        

      3. Run eslint:

        npx grunt ignorefiles eslint
        

        1. Confirm no failures
      4. Edit a template and add a javascript snippet to the bottom, for example open lib/templates/welcome.mustache in your editor, and add

        {{#js}}
        const foo = 'bar';
        window.console.log(foo);
        {{/js}}
        

      5. Run the mustachelint tool:

        php local/ci/mustache_lint/mustache_lint.php -f=`pwd`/lib/templates/welcome.mustache --basename=`pwd` -v=https://html5.validator.nu
        

        1. Confirm that there were no errors
          (Prior to this patch, Mustachelint would give confusing errors about const being a reserved word, or other weird errors)
      6. Create a file in the moodle root directory named test.js with content:

        const foo = 'bar';
        

      7. Run eslint on it:

        npx eslint test.js
        

        1. Confirm that there were no errors
          (Prior to this patch, errors were reported about use of ES6 syntax)
      8. In a terminal window run grunt watch:

        npx grunt watch
        

      9. Edit a YUI file such as lib/yui/src/chooserdialogue/js/chooserdialogue.js and add an ES6-ism, at the top, such as:

        const foo = 'bar';
        

      10. Save the file and look at the grunt output
        1. Confirm that it did complain about use of const
      Show
      This issue will be tested by CI as we build and lint all files anyway. To further test, you can: install moodle-local_ci and moodle-local_codechecker git clone https://github.com/moodlehq/moodle-local_ci local/ci git clone https://github.com/moodlehq/moodle-local_codechecker local/codechecker cd local/ci composer install cd - Install JS dependencies npm i Run eslint: npx grunt ignorefiles eslint Confirm no failures Edit a template and add a javascript snippet to the bottom, for example open lib/templates/welcome.mustache in your editor, and add {{#js}} const foo = 'bar'; window.console.log(foo); {{/js}} Run the mustachelint tool: php local/ci/mustache_lint/mustache_lint.php -f=`pwd`/lib/templates/welcome.mustache --basename=`pwd` -v=https://html5.validator.nu Confirm that there were no errors (Prior to this patch, Mustachelint would give confusing errors about const being a reserved word, or other weird errors) Create a file in the moodle root directory named test.js with content: const foo = 'bar'; Run eslint on it: npx eslint test.js Confirm that there were no errors (Prior to this patch, errors were reported about use of ES6 syntax) In a terminal window run grunt watch: npx grunt watch Edit a YUI file such as lib/yui/src/chooserdialogue/js/chooserdialogue.js and add an ES6-ism, at the top, such as: const foo = 'bar'; Save the file and look at the grunt output Confirm that it did complain about use of const

    Description

      We dropped support for IE in 4.0, and with it we can now support ES6 syntax in all JS files.

      Whilst we do not support them in all cases, we can now do so where relevant.

      We should be able to set a default environment of es6 (and possibly newer versions too) for all files, and then just disable it for YUI.

      Attachments

        Issue Links

          Activity

            People

              dobedobedoh Andrew Lyons
              dobedobedoh Andrew Lyons
              Simey Lameze Simey Lameze
              Jun Pataleta Jun Pataleta
              Angelia Dela Cruz Angelia Dela Cruz
              David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                16/Jan/23

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 3 hours, 41 minutes
                  3h 41m