簡體   English   中英

ESLint:在.eslintrc.js中設置自定義格式化程序

[英]ESLint: set custom formatter in .eslintrc.js

我正在使用帶有craco的 create-react-app(Create-React-App-Configuration-Override)

Craco不是很異國情調。 它只是允許我將我自己的eslintrc文件與create-react-app一起使用

我正在嘗試使用自定義的eslint格式化程序,特別是eslint-formatter-friendly滿足了我的需要(通過iTerm / Guake終端鏈接到行號的文件),但是還有很多其他的格式化程序: http ://npmsearch.com/ ?q = eslint格式器

我嘗試在.eslintrc.js文件中設置一個format: 'unix'formatter: 'unix' unix'-但這沒有用,eslint明確給出了一個錯誤,例如“無法識別的頂級屬性”。

我尋找了可以在.eslintrc.js文件中指定格式器的任何方式,但是我發現這不是一個選擇。 在搜索並掃描了gulp-eslint,eslint-grunt和grunt-eslint的源代碼之后,最終我更仔細地查看了craco的源代碼-在其中讀取了一些eslint配置: https : //github.com/sharegate/ craco / blob / master / recipes / use-an-eslintrc-config-file / craco.config.js

處理此內容的源代碼: https : //github.com/sharegate/craco/blob/master/packages/craco/lib/features/webpack/eslint.js

我需要做的就是使用craco.config.js:

/* globals module */
const { ESLINT_MODES } = require("@craco/craco");
const reactHotReloadPlugin = require('craco-plugin-react-hot-reload');

module.exports = {
    plugins: [{
        plugin: reactHotReloadPlugin
    }],
    eslint: {
        mode: ESLINT_MODES.file,
        loaderOptions: {
            formatter: require("eslint-formatter-friendly")
        }
    },
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM