question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linter is not correctly using .eslintrc.js files

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.19.1
  • Node Version: 8.11.2
  • npm Version: 6.1.0

What parser (default, Babel-ESLint, etc.) are you using? babel-eslint

Please show your full configuration:

.eslintrc.js

module.export = {
  parser: "babel-eslint",
  parserOptions: {
    ecmaVersion: 6,
    sourceType: "module",
    ecmaFeatures: {
      jsx: true,
      modules: true,
      experimentalObjectRestSpread: true
    }
  },
  extends: ["plugin:prettier/recommended", "airbnb"],
  plugins: ["react", "jsx-a11y", "import", "prettier"],
  env: {
    es6: true,
    browser: true,
    node: true,
    jest: true
  },
  rules: {
    "react/jsx-filename-extension": [1, { extensions: [".js", ".jsx"] }]
  }
};

.eslintrc (pure json)

{
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "modules": true,
      "experimentalObjectRestSpread": true
    }
  },
  "extends": ["airbnb", "plugin:prettier/recommended"],
  "plugins": ["react", "jsx-a11y", "import", "prettier"],
  "env": {
    "browser": true,
    "node": true,
    "jest": true
  },
  "rules": {
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
  }
}
Configuration
{
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "modules": true,
      "experimentalObjectRestSpread": true
    }
  },
  "extends": ["airbnb", "plugin:prettier/recommended"],
  "plugins": ["react", "jsx-a11y", "import", "prettier"],
  "env": {
    "browser": true,
    "node": true,
    "jest": true
  },
  "rules": {
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint. This can be reproduced by

$ create-react-app my-app

The error is showing within Visual Studio Code with the ESLint plugin and via the cli through the

$ yarn eslint src/**

where in the package.json the eslint command is

eslint: "eslint"

What did you expect to happen? Display actual eslint errors

  • no-unused-vars
  • no-undef (etc…)

What actually happened? Please include the actual, raw output from ESLint. Displaying errors: Parsing error: The keyword ‘import’ is reserved Parsing error: The keyword ‘const’ is reserved

Note that this error only happened for the eslintrc.js file and the .eslintrc file works. Took me a lot of trial and error to isolate that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Jul 11, 2018

Hi @MFry, thanks for the issue.

When working with JS configuration files, ESLint expects the configuration to be exported according to the CommonJS specification.

This means that instead of assigning to module.export, you need to assign to module.exports.

Correct configuration:

module.exports = {
  parser: "babel-eslint",
  parserOptions: {
    ecmaVersion: 6,
    sourceType: "module",
    ecmaFeatures: {
      jsx: true,
      modules: true,
      experimentalObjectRestSpread: true
    }
  },
  extends: ["plugin:prettier/recommended", "airbnb"],
  plugins: ["react", "jsx-a11y", "import", "prettier"],
  env: {
    es6: true,
    browser: true,
    node: true,
    jest: true
  },
  rules: {
    "react/jsx-filename-extension": [1, { extensions: [".js", ".jsx"] }]
  }
};

Hope this helps!

0reactions
phyzicalcommented, Dec 7, 2018

not a contributor but i feel like taking a stab, its probably easier to just sniff all .* files and eslintrc and filter out any not supported

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint not working in VS Code? - Stack Overflow
To verify, press Ctrl + Shift + U in VSCode to open the Output panel after opening a JavaScript file with a known...
Read more >
ESLint not working in VSCode? Help build a troubleshooting ...
Take a look into your eslintrc configuration file and make a list of all plugins and presets. Than make sure, they as well...
Read more >
How To Lint and Format Code with ESLint in Visual Studio Code
To find the settings in Visual Studio Code, use the command palette to open Preferences: Open Workspace Settings (JSON). With this code in...
Read more >
Configuration Files - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Command Line Interface - ESLint - Pluggable JavaScript Linter
You can view all the CLI options by running npx eslint -h . eslint [options] file.js [file.js] [dir] Basic configuration: --no-eslintrc Disable use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found