Taro: 能否提供代码格式化配置文件.prettierrc?

Created on 15 Mar 2019  ·  7Comments  ·  Source: NervJS/taro

这个功能解决了什么问题?

taro官方文档有最佳实践的代码要求,提供.prettierrc,方便代码格式化

你期望的功能是怎样的?

提供.prettierrc,类似:
````
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
]
}

````

补充信息

Most helpful comment

@yuche Prettier 其实可以强制 JSX 使用单引号,使用 "jsxSingleQuote": true

{
    "printWidth": 86,
    "tabWidth": 2,
    "useTabs": false,
    "semi": true,
    "singleQuote": true,
    "jsxSingleQuote": true,
    "trailingComma": "es5",
    "bracketSpacing": true,
    "jsxBracketSameLine": true,
    "arrowParens": "avoid",
    "endOfLine": "crlf"
}

All 7 comments

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

prettier 的话,可能不是每个人都在用,而且每个人的配置也不同

多个人在维护同一个项目,是不是应该统一格式化配置?不然格式化下源码提交上去,出现大量变更,做代码审核的人会很费劲的。

antd团队最近就把代码格式化的配置提交上去

prettier 在 Taro 中使用有两个问题:

  1. 一般有修复功能的 ESLint 规则会使用,Taro 的绝大部分自定义规则是没办法修复的(例如无法在 JSX 使用 ...spread 语法),这样提供了也意义不大
  2. Taro 推荐在 JSX 使用单引号,prettier 在 JSX 是强制双引号

@yuche Prettier 其实可以强制 JSX 使用单引号,使用 "jsxSingleQuote": true

{
    "printWidth": 86,
    "tabWidth": 2,
    "useTabs": false,
    "semi": true,
    "singleQuote": true,
    "jsxSingleQuote": true,
    "trailingComma": "es5",
    "bracketSpacing": true,
    "jsxBracketSameLine": true,
    "arrowParens": "avoid",
    "endOfLine": "crlf"
}

prettier 在 Taro 中使用有两个问题:

  1. 一般有修复功能的 ESLint 规则会使用,Taro 的绝大部分自定义规则是没办法修复的(例如无法在 JSX 使用 ...spread 语法),这样提供了也意义不大
  2. Taro 推荐在 JSX 使用单引号,prettier 在 JSX 是强制双引号

其实我一直没明白,为什么 Taro 要在 JSX 中使用单引号。

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deepcoldy picture deepcoldy  ·  3Comments

ruixiu picture ruixiu  ·  3Comments

LadyChatterleyLover picture LadyChatterleyLover  ·  3Comments

leafchao picture leafchao  ·  3Comments

chankamlam picture chankamlam  ·  3Comments