electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.5k stars 520 forks source link

eslint-webpack-plugin and fork-ts-checker-webpack-plugin print nothing in terimnal when run electron-forge start #3179

Open Jerry2Lemon opened 1 year ago

Jerry2Lemon commented 1 year ago

Pre-flight checklist

Electron Forge version

6.0.5

Electron version

23.1.1

Operating system

Windows 10

Last known working Electron Forge version

6.0.5

Expected behavior

Firstly, I use electron-forge to create a project with typescript, webpack, eslint. I wish if some errors or warnings occur when coding, TypeScript Type Check or ESLint can print the error or warning tips in terminal.

Then I read the electron-forge code and webpack5 configuration, I find electron-forge set " infrastructureLogging.level " and " stats " to be " none " value.

// some code ...

for (const entryConfig of config) {
  if (!entryConfig.plugins) entryConfig.plugins = [];
  entryConfig.plugins.push(pluginLogs);

  entryConfig.infrastructureLogging = {
    level: 'none',
  };
  entryConfig.stats = 'none';
}

// some code ...

const config = await this.configGenerator.getPreloadConfigForEntryPoint(entryPoint);
config.infrastructureLogging = {
  level: 'none',
};
config.stats = 'none';

// some code ...

So I delete " infrastructureLogging " and " stats " code, then TypeScript Type Check or ESLint print as I wish in terminal. So can electron-forge use infrastructureLogging and stats in webpack.renderer.config.ts for final config?

WARNING in [eslint]
F:\electron-webpack-eslint-app\src\renderer.ts
  31:1  warning  Unexpected console statement            no-console
  32:7  warning  'a' is assigned a value but never used  @typescript-eslint/no-unused-vars

✖ 3 problems (1 error, 2 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

ERROR in [eslint]
F:\electron-webpack-eslint-app\src\renderer.ts
  32:25  error  Newline required at end of file but not found  eol-last

✖ 3 problems (1 error, 2 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

webpack 5.75.0 compiled with 1 error and 1 warning in 6552 ms
<e> [ForkTsCheckerWebpackPlugin] ERROR in ./src/renderer.ts:32:7
<e> TS2322: Type 'boolean' is not assignable to type 'number'.
<e>     30 |
<e>     31 | console.log('👋 This message is being logged by "renderer.js", included via webpack');
<e>   > 32 | const a: number = false;
<e>        |       ^
<e>
<i> [ForkTsCheckerWebpackPlugin] Found 1 error in 6419 ms.

Then I press ctrl+s to trigger save in renderer.ts flie, but the eslint print the same error/warning twice, it's unexpected !

<e> [ForkTsCheckerWebpackPlugin] ERROR in ./src/renderer.ts:32:7
<e> TS2322: Type 'boolean' is not assignable to type 'number'.
<e>     30 |
<e>     31 | console.log('👋 This message is being logged by "renderer.js", included via webpack');
<e>   > 32 | const a: number = false;
<e>        |       ^
<e>
<i> [ForkTsCheckerWebpackPlugin] Found 1 error in 157 ms.
assets by path main_window/ 597 KiB
  asset main_window/index.js 597 KiB [emitted] (name: main_window)
  asset main_window/index.html 262 bytes [emitted]
assets by info 905 bytes [immutable]
  asset main_window.677a2accce3370776cc9.hot-update.js 870 bytes [emitted] [immutable] [hmr] (name: main_window)
  asset main_window.677a2accce3370776cc9.hot-update.json 35 bytes [emitted] [immutable] [hmr]
Entrypoint main_window 597 KiB = main_window/index.js 597 KiB main_window.677a2accce3370776cc9.hot-update.js 870 bytes
cached modules 172 KiB [cached] 32 modules
runtime modules 26.3 KiB 13 modules
./src/renderer.ts 1.06 KiB [built]

WARNING in [eslint]
F:\electron-webpack-eslint-app\src\renderer.ts
  31:1  warning  Unexpected console statement            no-console
  32:7  warning  'a' is assigned a value but never used  @typescript-eslint/no-unused-vars

✖ 3 problems (1 error, 2 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

WARNING in [eslint]
F:\electron-webpack-eslint-app\src\renderer.ts
  31:1  warning  Unexpected console statement            no-console
  32:7  warning  'a' is assigned a value but never used  @typescript-eslint/no-unused-vars

✖ 3 problems (1 error, 2 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

ERROR in [eslint]
F:\electron-webpack-eslint-app\src\renderer.ts
  32:25  error  Newline required at end of file but not found  eol-last

✖ 3 problems (1 error, 2 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

ERROR in [eslint]
F:\electron-webpack-eslint-app\src\renderer.ts
  32:25  error  Newline required at end of file but not found  eol-last

✖ 3 problems (1 error, 2 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

webpack 5.75.0 compiled with 2 errors and 2 warnings in 569 ms

Actual behavior

TypeScript Type Check or ESLint print nothing in terimnal when run electron-forge start and some errors or warnings in code.

Steps to reproduce

step1:

yarn create electron-app electron-webpack-eslint-app --template=webpack-typescript

step2:

cd electron-webpack-eslint-app

step3:

npx install-peerdeps --dev eslint-config-airbnb-base

step4: add "extends": "airbnb-base" to .eslintrc.json

{
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "airbnb-base",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/recommended",
    "plugin:import/electron",
    "plugin:import/typescript"
  ],
  "parser": "@typescript-eslint/parser",
  "ignorePatterns": ["webpack.*"]
}

step5:

yarn add -D eslint-webpack-plugin

step6: add eslint-webpack-plugin to webpack.plugins.ts

import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');

export const plugins = [
  new ForkTsCheckerWebpackPlugin({
    logger: 'webpack-infrastructure',
  }),
  new ESLintPlugin({ extensions: ["ts", "tsx", "js", "jsx"] })
];

step7: add some error or warning code in " src/renderer.ts "

import './index.css';

console.log('👋 This message is being logged by "renderer.js", included via webpack');
const a: number = false;

step8: run script

yarn start

Additional information

No response

ezze commented 10 months ago

Any news on this, guys? I faced the same issue using 7.2.0.

It also seems that this one may be related: https://github.com/electron/forge/issues/2928