1

I have spent some hours digging into Webpack Encore and ESLint issues, but I cannot seem to find a solution to this problem.

I specify that I want to change or turn off some TypeScript-ESLint rules, but nothing happens. I get linter warnings anyway. My configuration looks as follows:

.eslintrc.json

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "rules": {
    "@typescript-eslint/no-non-null-assertion": "off"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "ES2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "strict": true,
    "noImplicitAny": true,
    "esModuleInterop": true,
    "baseUrl": ".",
  },
  "include": [
    "assets/scripts/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

And here are the relevant parts of my encore configuration:

Encore
  // ...
  .enableTypeScriptLoader()
  .enableForkedTypeScriptTypesChecking()
  .enableVueLoader()
  .enableEslintLoader((options) => {}, { lintVue: true })
  // ...
;

And this is the warning I receive, although I disabled the rule:

/some/path/my-file.ts
  97:82  warning  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion

To me, it seems like this PR should fix my issue, but it does not.

Do you guys have any idea? I would be very grateful for any tip :)

Edit:

With the help of lotype and a coworker of mine, I finally found the solution. A couple of things must be changed.

First, make sure the correct parser is used:

.enableEslintLoader((options) => {
  options.parser = require('./.eslintrc.json').parser;
  // https://webpack.js.org/loaders/eslint-loader/#cache
  options.cache = false; // optional, but recommended
}, { lintVue: true })

Then, make sure to add TypeScript rules to the override section, and "normal" rules to the rule section like this:

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "rules": {
    "no-console": "warn"
  },
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "rules": {
        "@typescript-eslint/no-non-null-assertion": "off",
        "@typescript-eslint/no-explicit-any": "off"
      }
    }
  ]
}

Thanks for helping me with this, guys!

1 Answer 1

2

Would you try putting it into the overrides section of your .eslintrc.json?

  "overrides": [
    {
      "files": ["*.ts"],
      "rules": {
        "@typescript-eslint/no-non-null-assertion": "off"
      }
    }
  ]

Edit: "files" needed as per specification

Sign up to request clarification or add additional context in comments.

3 Comments

Sadly, that was not it. However, thanks for the idea, it was worth a try!
Your answer was one part of the solution, so thank you very much! I will make this the accepted answer. Anyone with the same problem: Please see my question's edit!
Glad I could help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.