@zerowork/prettierrc 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ # Dependency directories
2
+ node_modules/
3
+
4
+ # Production
5
+ public/
6
+ dist/
7
+
8
+ # Cache
9
+ .cache/
10
+ cache/
11
+ .history/
12
+
13
+ # yarn v2
14
+ .yarn/
15
+
16
+ # See https://github.com/lerna/lerna/issues/2565
17
+ CHANGELOG.md
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # prettierrc
2
+
3
+ * prettier通用配置
4
+
5
+ ## 安装
6
+
7
+ ```sh
8
+ npm i -D prettier @zerowork/prettierrc
9
+ ```
10
+
11
+ ## 配置使用
12
+
13
+ ### 方式一:在`package.json`中配置`prettier`
14
+
15
+ * 在`package.json`中添加`prettier`字段,采用此方式将使用默认配置
16
+
17
+ ```diff
18
+ + "prettier": "@zerowork/prettierrc",
19
+ "main": "dist/index.js"
20
+ ```
21
+
22
+ ### 方式二:使用`.prettierrc.js`方式导入配置
23
+
24
+ * 新建`.prettierrc.js`,导入`@zerowork/prettierrc`,并支持配置覆盖
25
+
26
+ ```js
27
+ module.exports = {
28
+ ...require("@zerowork/prettierrc"),
29
+ // 扩展或覆盖相关配置字段
30
+ semi: false
31
+ }
32
+ ```
33
+
34
+ ## 配置使用`.prettierignore`
35
+
36
+ 1. 在 `npm scripts`中配置
37
+
38
+ ```json
39
+ {
40
+ "scripts": {
41
+ "format": "prettier --write . --ignore-path ./node_modules/@zerowork/prettierrc/.prettierignore"
42
+ }
43
+ }
44
+ ```
45
+
46
+ 2. 在 `lint-staged`中配置
47
+
48
+ ```json
49
+ {
50
+ "lint-staged": {
51
+ "*": [
52
+ "prettier --write --ignore-path ./node_modules/@zerowork/prettierrc/.prettierignore"
53
+ ]
54
+ }
55
+ }
56
+ ```
57
+
58
+ 3. 在 vscode `settings.json`中配置
59
+
60
+ ```json
61
+ {
62
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
63
+ "editor.formatOnSave": true,
64
+ "prettier.ignorePath": "./node_modules/@zerowork/prettier/.prettierignore"
65
+ }
66
+ ```
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./prettier.config');
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@zerowork/prettierrc",
3
+ "version": "1.0.0",
4
+ "description": "prettier通用配置",
5
+ "files": [
6
+ "index.js",
7
+ "README.md",
8
+ ".prettierignore",
9
+ "prettierrc.js",
10
+ "prettier.config.js",
11
+ "package.json"
12
+ ],
13
+ "main": "index.js",
14
+ "peerDependencies": {
15
+ "prettier": "*"
16
+ },
17
+ "devDependencies": {
18
+ "prettier": "^2.4.1"
19
+ },
20
+ "engines": {
21
+ "node": ">=12"
22
+ }
23
+ }
package/prettierrc.js ADDED
@@ -0,0 +1,47 @@
1
+ // https://prettier.io/docs/en/options.html
2
+
3
+ module.exports = {
4
+ // 超过最大值换行
5
+ printWidth: 120,
6
+ // tab缩进字符数
7
+ tabWidth: 2,
8
+ // 缩进不使用tab,使用空格
9
+ useTabs: false,
10
+ // 去掉代码结尾的分号
11
+ semi: false,
12
+ // 使用单引号
13
+ singleQuote: true,
14
+ // 在jsx中使用单引号代替双引号
15
+ jsxSingleQuote: false,
16
+ // 在对象或数组最后一个元素后面是否加逗号(不添加)
17
+ trailingComma: 'none',
18
+ // 让prettier使用eslint的代码格式进行校验
19
+ eslintIntegration: true,
20
+ // 在对象,数组括号与文字之间加空格 "{ foo: bar }"
21
+ bracketSpacing: true,
22
+ // (x) => {} 箭头函数参数只有一个时要有小括号。
23
+ arrowParens: 'always',
24
+ // 换行符使用 lf 结尾 <lf|crlf|cr|auto>
25
+ endOfLine: 'lf',
26
+ // 不让HTML中的 > 多行显示
27
+ bracketSameLine: false,
28
+ // 每个文件格式化的范围是文件的全部内容 - 范围开始
29
+ rangeStart: 0,
30
+ // 每个文件格式化的范围是文件的全部内容 - 范围结束
31
+ rangeEnd: Number.POSITIVE_INFINITY,
32
+ // 若为true,文件顶部加了 /*** @prettier */或/*** @format */的文件才会被格式化
33
+ requirePragma: false,
34
+ // 当requirePragma参数为true时,此参数为true将向@format标记后面添加一个换行符
35
+ insertPragma: false,
36
+ // 当Markdown文本超过printWidth时是否换行 <always|never|preserve> - preserve 保留用户输入的情况
37
+ proseWrap: 'preserve',
38
+ // 根据显示样式决定 html 要不要折行 <css|strict|ignore>"
39
+ htmlWhitespaceSensitivity: 'css',
40
+ // 对象key是否使用引号 <as-needed|consistent|preserve> - preserve 保留用户输入的情况
41
+ quoteProps: 'preserve',
42
+ // vue文件的script标签和Style标签下的内容需要缩进
43
+ vueIndentScriptAndStyle: false,
44
+ // 是否格式化嵌入到JS中的html标记的代码段或者Markdown语法 <auto|off> - auto 格式化
45
+ embeddedLanguageFormatting: 'auto',
46
+ };
47
+