webpack-contrib / eslint-loader

[DEPRECATED] A ESlint loader for webpack
MIT License
1.06k stars 121 forks source link

Expecting eslint-loader to report same linting errors as npm run lint when both refer to same configuration file and ts extension #301

Closed dcs3spp closed 5 years ago

dcs3spp commented 5 years ago

Expected Behavior

Expecting eslint-loader to report the same linting errors as npm run lint. Both reference the same configuration file and extension. The project is a typescript project available here.

Actual Behavior

npm run lint reports 24 problems within ./src and ./test folders. webpack eslint-loader only reports 3 warnings for unexpected any rule violations

Code

npm run lint script

"./node_modules/.bin/eslint . --ext .ts -c ./eslintrc.js",

web.config.common.js

 module: {
    rules: [
      {
        // run tslint prior to transpiling
        test: /\.(ts)$/,
        enforce: 'pre',
        exclude: /node_modules/,
        loader: 'eslint-loader',
        options: {
          cache: false,
          configFile: './eslintrc.js',
          emitError: true,
          emitWarning: true,
          eslintPath: require.resolve('eslint'),
          failOnError: true,
          failOnWarning: true,
        },
      },
      {
        // transpile typescript into javascript
        test: /.(ts)$/,
        loader: 'ts-loader',
        options: { configFile: 'tsconfig.build.json' },
      },
    ],
  },
};

eslintrc.js

const path = require('path');

module.exports = {
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint', 'prettier'],
  'extends': [
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
    'prettier/@typescript-eslint',
  ],
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
    project: path.resolve(__dirname,'./tsconfig.json'),
    tsconfigRootDir: __dirname,
  },
  env: {
    node: true,
    commonjs: true,
    es6: true,
    jest: true,
  },
  rules: {
    // '@typescript-eslint/no-explicit-any': 'off',
    '@typescript-eslint/explicit-member-accessibility': 'off',
    '@typescript-eslint/interface-name-prefix': 'off',
    '@typescript-eslint/indent': 'off',
    'camelcase': ['error', { properties: 'always' }],
    'id-blacklist': ['error', 'any', 'Number', 'number', 'String', 'string', 'Boolean', 'boolean', 'Undefined', 'undefine'],
    indent: 'off',
    'max-len': ['error', { code: 150 }],
    'member-ordering': 'off',
    'object-literal-sort-keys': 'off',
    quotes: ['error','single'],
  },
  settings: {},
};

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  },
  "exclude": ["node_modules", "dist"]
}

How Do We Reproduce?

code base is available here

dcs3spp commented 5 years ago

Apologies to all, I think I understand what was happening....

My npm run lint script was reporting lint errors/warnings from . (./src/ and ./test). If I altered the lint script to inspect ./src and modified files that are referenced from the entrypoint(s) then the same errors were being reported. At first I had the options failOnError: true, and failOnWarning: true so only one error/warning was being reported at anyone time. When I removed these options then the lint messages started to match up with those reported by npm run lint script. With webpack I am only operating on the ./src from the entrypoint(s) with no inspection of the tests.