Skip to content

Inconsistent behaviour with import/ignore #478

@rhys-vdw

Description

@rhys-vdw

Getting some strangely inconsistent behaviour with the import/ignore setting.

My config:

// .eslintrc.js
module.exports = {
  "settings": {
    "import/ignore": [
      "\.erb$",
      "\.coffee$",
      "node_modules"
    ],
    "import/resolver": {
      "webpack": {
        "config": "./config/webpack.config.js"
      }
    }
  },
// ... the rest is irrelevant

The erroneous errors:

> eslint --config .eslintrc.js app/assets/javascripts/


/Users/rhys/Projects/usability-hub/usability_hub/app/assets/javascripts/components/test-form/screenshots-editor/screenshots-editor.js
  12:37  error    Parse errors in imported module '../../../views/screenshot-hitzone-editor': Unexpected token %= (8:31)  import/namespace
  12:37  error    Parse errors in imported module '../../../views/screenshot-hitzone-editor': Unexpected token %= (8:31)  import/default
  12:37  warning  Parse errors in imported module '../../../views/screenshot-hitzone-editor': Unexpected token %= (8:31)  import/no-named-as-default
  12:37  warning  Parse errors in imported module '../../../views/screenshot-hitzone-editor': Unexpected token %= (8:31)  import/no-named-as-default-member

The file that that is throwing errors:

Lines 12 and 13 from screenshots-editor.js (the file containing failed imports above):

// ...
import ScreenshotHitzoneEditor from '../../../views/screenshot-hitzone-editor';
import RailsRoutes from '../../../rails-routes';
// ...

The reason why I'm showing both of these lines is because both of these references files are .js.erb files.

Line 8 from screenshot-hitzone-editor.js.erb:

// ...
const SCREENSHOT_MAX_WIDTH = <%= Screenshot::MAX_DISPLAY_WIDTH %>;
// ...

And the same erb syntax used in rails-routes.js.erb:

// ...
<%=
routes = [
  /^choose_test$/,
  /^confirm_destroy_response$/,
// ...

So ESLint will try to parse screenshot-hitzone-editor.js.erb, but will (correctly) avoid parsing rails-routes.js.erb. There are several erb files in the project, and this is the first time that this configuration strategy has failed.

Note that I can replace the import statements with fully qualified paths, and the same problem occurs:

// still fails:
import ScreenshotHitzoneEditor from '../../../views/screenshot-hitzone-editor.js.erb';
import RailsRoutes from '../../../rails-routes.js.erb';

So the problem does appear to be with eslint-import AFAICT.

I'm happy to help debug this.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions