@cailiao/eslint-plugin-prettier
v0.2.8
Published
eslint-plugin-prettier
Downloads
261
Maintainers
Readme
eslint-plugin-prettier 预览版
各场景稳定性尚在测试中。
描述(Description)
本插件旨在帮助解决 prettier 和 eslint 规则冲突的问题,希望能同时满足偏爱 prettier 风格或 eslint 风格但又需要同时使用两个格式化插件的两种人群的需求。
(This plugin is designed to help solve the problem of conflicting rules between prettier and eslint, hoping to meet the needs of both people who prefer prettier style or eslint style but need to use both formatting plugins.)
eslint-plugin-prettier 的拓展,支持配置 eslint 以 prettier 为最终输出,还是以 eslint 的默认规则(或其他自定义规则)为最终输出。
开始使用
npm install @cailiao/eslint-plugin-prettier@latest --save-dev
注意: 如果报依赖缺失需要自行安装 eslint >= 7.28
prettier >= 2
:
npm install eslint@7 prettier@2 --save-dev
eslintrc
{
"plugins": ["@cailiao/prettier"],
"rules": {
"@cailiao/prettier/prettier": "warn"
// 其它rule
}
}
拓展的设置
Options
第一个参数
Object
:是一个对象,对象中的一个字段
mode
是本项目拓展的一个配置项,允许的值为'prettier-eslint'
或'eslint-prettier'
。'prettier-eslint'
为默认值,表示以 prettier 规则和 eslint 默认规则(或其他自定义规则)格式化自动修复冲突时,以 eslint 默认规则(或其他自定义规则)为最终输出;'eslint-prettier'
表示行为和原插件一样,以 prettier 规则为最终输出(原插件的行为在不同规则之间发生冲突时,输出可能不稳定)。
{
"@cailiao/prettier/prettier": [1, {
"mode": "eslint-prettier" // 缺省值: "prettier-eslint"
}]
}
原有设置:(以下信息来自 eslint-plugin-prettier 4.x)
Options
The first option:
An object representing options that will be passed into prettier. Example:
{ "prettier/prettier": ["error", { "singleQuote": true, "parser": "flow" }] }
NB: This option will merge and override any config set with
.prettierrc
files
The second option:
An object with the following options
usePrettierrc
: Enables loading of the Prettier configuration file, (default:true
). May be useful if you are using multiple tools that conflict with each other, or do not wish to mix your ESLint settings with your Prettier configuration.{ "prettier/prettier": [ "error", {}, { "usePrettierrc": false } ] }
fileInfoOptions
: Options that are passed to prettier.getFileInfo to decide whether a file needs to be formatted. Can be used for example to opt-out from ignoring files located innode_modules
directories.{ "prettier/prettier": [ "error", {}, { "fileInfoOptions": { "withNodeModules": true } } ] }