New issue
Advanced search Search tips

Issue 912394 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Dec 7
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

ESLint analyzer doesn't support JS module files

Project Member Reported by jeffcarp@chromium.org, Dec 6

Issue description

https://tricium-dev.appspot.com/run/5748022428303360

ESLint doesn't seem to parse JS module files correctly:

> Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

https://chromium-review.googlesource.com/c/infra/infra/+/1357212/6/appengine/monorail/static/js/elements/mr-account-dropdown.js#1

I'm unsure if ESLint supports linting both JS module and non-JS module files in the same run.
 
Status: Available (was: Untriaged)
Apparently in the config there is parserOptions.sourceType, which is either set to "script" (default) or "module" if your code is in ECMAScript modules.

I'm wondering whether ESLint will give any errors like this when parsing "scripts" with parserOptions.sourceType set to module... if not then the easiest fix is probably just to set "sourceType" to "module".

Note, the docs I was just looking at was:
https://eslint.org/docs/user-guide/configuring#specifying-parser-options

The modified config would be:

{
  "extends": "google",
  "env": {
    "es6": true
  },
  "parserOptions": {
    "sourceType": "module"
  },
  "rules": {
    "require-jsdoc": 0,
    "indent": ["error", 2]
  }
}

To test it on example files we can run

 $ eslint --parser-options='{"sourceType":"module"}' ...

I just tried running it on a couple files that *didn't* have import, and didn't find any issues with that yet.

Cc: -qyears...@chromium.org
Owner: qyears...@chromium.org
Status: Started (was: Available)
Relevant discussion: https://stackoverflow.com/questions/36367656/eslint-sourcetype-mixture-of-script-and-module

Looks like the downside of using "module" with non-modules is the warning that "use strict" isn't necessary in modules. But with the google style config base, it seems like I'm not getting that warning anyway. So in this case the simple solution may be to just specify "module" source type.

https://chromium-review.googlesource.com/c/infra/infra/+/1365935
Project Member

Comment 4 by bugdroid1@chromium.org, Dec 7

The following revision refers to this bug:
  https://chromium.googlesource.com/infra/infra/+/9a310d0bb46c03c59d68b474e20990d0e8369686

commit 9a310d0bb46c03c59d68b474e20990d0e8369686
Author: Quinten Yearsley <qyearsley@chromium.org>
Date: Fri Dec 07 00:10:44 2018

Switch default config for eslint to use "module" source type

Bug:  912394 
Change-Id: I7c0f0e84f8e4f4b442ab98e380dd6986f34034b0
Reviewed-on: https://chromium-review.googlesource.com/c/1365935
Commit-Queue: Quinten Yearsley <qyearsley@chromium.org>
Reviewed-by: Jeff Carpenter <jeffcarp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#19404}
[modify] https://crrev.com/9a310d0bb46c03c59d68b474e20990d0e8369686/go/src/infra/tricium/functions/eslint/test/example.js
[modify] https://crrev.com/9a310d0bb46c03c59d68b474e20990d0e8369686/go/src/infra/tricium/functions/eslint/package-lock.json
[modify] https://crrev.com/9a310d0bb46c03c59d68b474e20990d0e8369686/go/src/infra/tricium/functions/eslint/.eslintrc.json

Status: Fixed (was: Started)
Tricium now parses and checks JS module files, e.g. https://chromium-review.googlesource.com/c/infra/infra/+/1357212/8

Sign in to add a comment