webpack-contrib / eslint-webpack-plugin

A ESLint plugin for webpack
MIT License
258 stars 49 forks source link

Checking/validating json files #196

Closed jandresampaio closed 1 year ago

jandresampaio commented 1 year ago

Documentation Is:

Please Explain in Detail...

Plugin is working perfectly for js andts files but it's not validating json files. If we use eslint src --ext js,ts,tsx,json is works as expected but we are using the eslint-webpack-plugin to check the warnings in the same terminal window as the compiler.

Not sure if this is expected and what is the recommended configuration to achieve this:

My current webpack config file:

const webpack = require("webpack");
const ESLintPlugin = require("eslint-webpack-plugin");
const options = require("./.eslintrc.json");

module.exports = {
    ...
    plugins: [
      new webpack.DefinePlugin({
        "process.env.ENV": JSON.stringify(webpackConfigEnv.ENV),
      }),
      new ESLintPlugin({
        extensions: ["js", "jsx", "ts", "tsx", "json"],
        baseConfig: options
      })
    ],
  };

and eslintrc.json file:

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:react/jsx-runtime",
    "plugin:react-hooks/recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/recommended",
    "plugin:import/typescript",
    "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": [
    "react",
    "react-hooks",
    "@typescript-eslint",
    "import",
    "prettier"
  ],
  "rules": {
    "ban-ts-ignore": 0,
    "@typescript-eslint/ban-ts-comment": 0,
    "@typescript-eslint/no-explicit-any": 0
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}

Your Proposal for Changes

It should validate json files.

alexander-akait commented 1 year ago

Can you add files https://github.com/webpack-contrib/eslint-webpack-plugin#files?

jandresampaio commented 1 year ago

Can you add files https://github.com/webpack-contrib/eslint-webpack-plugin#files?

@alexander-akait like this?

 new ESLintPlugin({
        baseConfig: options,
        files: [
          "./src/**/*.(json|tsx|ts)",
        ]
      }),

It gives the same result

jandresampaio commented 1 year ago

So this is my mistake, I was testing with a json that was not being used in the build, i.e, imported inside some other file. I guess it's not possible to check for json files outside the build then...

alexander-akait commented 1 year ago

Yeah, we check files only related to build