How to configure ESlint correctly? Who can help?

Started by ubacher, June 28, 2017, 06:49:25 PM

Previous topic - Next topic

ubacher

(Background: ESlint analyzes your code for errors. It is available as a plugin for VS Code.)

I am having difficulty knowing what answers to put when I configure ESlint.

Here are the questions you get when you run eslint --init
? How would you like to configure ESLint? (Use arrow keys)
> Answer questions about your style
  Use a popular style guide
  Inspect your JavaScript file(s)
 
   Which file(s), path(s), or glob(s) should be examined?

What format do you want your config file to be in?
Javasript
YAML
JSON

Are you using ECMAScript 6 features? (y/N)
Are you using ES6 modules? (y/N)

Where will your code run? (Press <space> to select, <a> to toggle all, <i> to inverse selection)
>(*) Browser
( ) Node

Do you use CommonJS? (y/N)
Do you use JSX? (y/N)


What are the best answers for an Imatch scripter?

I don't recall what answers I put originally (produced no errors)  but with the following answers I do get an error:
C:\Users\ubach>eslint --init
? How would you like to configure ESLint? Inspect your JavaScript file(s)
? Which file(s), path(s), or glob(s) should be examined? c:/ProgramData/photools.com/webroot/user
? What format do you want your config file to be in? JavaScript
? Are you using ECMAScript 6 features? Yes
? Are you using ES6 modules? Yes
? Where will your code run? Browser
? Do you use CommonJS? No
? Do you use JSX? No


Automatic Configuration failed.  No files were able to be parsed.
Error: Automatic Configuration failed.  No files were able to be parsed.
    at configureRules (C:\Users\ubach\AppData\Roaming\npm\node_modules\eslint\lib\config\config-initializer.js:144:15)
    at processAnswers (C:\Users\ubach\AppData\Roaming\npm\node_modules\eslint\lib\config\config-initializer.js:252:18)
    at inquirer.prompt.then.secondAnswers (C:\Users\ubach\AppData\Roaming\npm\node_modules\eslint\lib\config\config-initializer.js:417:26)
Determining Config: 0% [------------------------------] 0.0s elapsed, eta 0.0s
C:\Users\ubach>

Mario

My eslintrc.json looks like this:


{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true,
        "node": true,
        "jquery": true,
        "jasmine":true
    },
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "sourceType": "module"
    },
    "rules": {
        "no-const-assign": "warn",
        "no-this-before-super": "warn",
        "no-undef": "warn",
        "no-unreachable": "warn",
        "no-unused-vars": "off",
        "constructor-super": "warn",
        "valid-typeof": "warn"
    },
    "globals": {
        "IMWS": false,
        "IMatch": false,
        "IMatchTranslate": false,
        "ol":false
    }
}


I use only the basic stuff. KISS principle.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

Just tried finding where this eslintrc.json file is located. Could not find it - but maybe because it does not exist?
The closest I found was under Roaming/npm.

Could you please tell us where-to we should store this file.

thrinn

My .eslintrc.json is in the webroot directory.
C:\ProgramData\photools.com\imatch6\webroot\.eslintrc.json

This way the same config is used for all apps (provided they are stored in some sub directories of this path).

Thorsten
Win 10 / 64, IMatch 2018, IMA

ubacher

Thanks. Copied Mario's file and put it there (webroot).

Mario

The ESLit plug-in documentation explains that you have to create this file for your project (in the project root) and then customize it to your requirements.
The plug-in for VSCode is just a wrapper for ESLint so the best reference is the ESLint web site: http://eslint.org/
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook