@alexlit/config-prettier 16.6.3 → 17.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.
- package/README.md +21 -9
- package/index.js +96 -37
- package/package.json +3 -2
- package/plugins/jsdoc.js +1 -1
- package/plugins/packagejson.js +3 -0
- package/plugins/php.js +3 -0
- package/plugins/pug.js +2 -1
- package/plugins/ruby.js +3 -0
- package/plugins/sh.js +3 -0
- package/plugins/solidity.js +3 -0
- package/plugins/sort-json.js +2 -1
- package/plugins/sql.js +3 -0
- package/plugins/svelte.js +2 -1
- package/plugins/tailwindcss.js +2 -1
- package/plugins/xml.js +2 -1
package/README.md
CHANGED
|
@@ -8,14 +8,26 @@ npm i @alexlit/config-prettier -D
|
|
|
8
8
|
|
|
9
9
|
## Connection
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import config from '@alexlit/config-prettier';
|
|
11
|
+
- Default
|
|
12
|
+
([see plugins enabled by default](https://github.com/alex-lit/lint-kit/blob/master/packages/config-prettier/index.js#L5))
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
```js
|
|
15
|
+
// prettier.config.js
|
|
16
|
+
import { createConfig } from '@alexlit/config-prettier';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
export default createConfig();
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Custom
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
// prettier.config.js
|
|
25
|
+
import { createConfig } from '@alexlit/config-prettier';
|
|
26
|
+
|
|
27
|
+
export default createConfig({
|
|
28
|
+
php: true,
|
|
29
|
+
ruby: true,
|
|
30
|
+
sql: false,
|
|
31
|
+
tailwindcss: false,
|
|
32
|
+
});
|
|
33
|
+
```
|
package/index.js
CHANGED
|
@@ -1,38 +1,97 @@
|
|
|
1
|
-
/* eslint-disable
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
/* eslint-disable no-loops/no-loops, no-restricted-syntax, no-await-in-loop */
|
|
2
|
+
|
|
3
|
+
import { omit } from 'radash';
|
|
4
|
+
|
|
5
|
+
const PLUGINS = {
|
|
6
|
+
/** @see [prettier-plugin-jsdoc](https://github.com/hosseinmd/prettier-plugin-jsdoc) */
|
|
7
|
+
jsdoc: true,
|
|
8
|
+
|
|
9
|
+
/** @see [prettier-plugin-packagejson](https://github.com/matzkoh/prettier-plugin-packagejson) */
|
|
10
|
+
packagejson: true,
|
|
11
|
+
|
|
12
|
+
/** @see [plugin-php](https://github.com/prettier/plugin-php) */
|
|
13
|
+
php: false,
|
|
14
|
+
|
|
15
|
+
/** @see [plugin-pug](https://github.com/prettier/plugin-pug) */
|
|
16
|
+
pug: true,
|
|
17
|
+
|
|
18
|
+
/** @see [plugin-ruby](https://github.com/prettier/plugin-ruby) */
|
|
19
|
+
ruby: false,
|
|
20
|
+
|
|
21
|
+
/** @see [prettier-plugin-sh](https://github.com/astorije/prettier-plugin-sh) */
|
|
22
|
+
sh: true,
|
|
23
|
+
|
|
24
|
+
/** @see [prettier-plugin-solidity](https://github.com/prettier-solidity/prettier-plugin-solidity) */
|
|
25
|
+
solidity: true,
|
|
26
|
+
|
|
27
|
+
/** @see [prettier-plugin-sort-json](https://github.com/Gudahtt/prettier-plugin-sort-json) */
|
|
28
|
+
'sort-json': true,
|
|
29
|
+
|
|
30
|
+
/** @see [prettier-plugin-sql](https://github.com/un-ts/prettier/tree/master/packages/sql) */
|
|
31
|
+
sql: false,
|
|
32
|
+
|
|
33
|
+
/** @see [prettier-plugin-svelte](https://github.com/sveltejs/prettier-plugin-svelte) */
|
|
34
|
+
svelte: false,
|
|
35
|
+
|
|
36
|
+
/** @see [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss) */
|
|
37
|
+
tailwindcss: false,
|
|
38
|
+
|
|
39
|
+
/** @see [plugin-xml](https://github.com/prettier/plugin-xml) */
|
|
40
|
+
xml: true,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create plugins config list
|
|
45
|
+
*
|
|
46
|
+
* @param {PLUGINS} plugins Enabled/disabled plugins list
|
|
47
|
+
*
|
|
48
|
+
* @returns {import('prettier').Config} Prettier configuration
|
|
49
|
+
*/
|
|
50
|
+
const createPluginsConfig = async (plugins = {}) => {
|
|
51
|
+
let pluginsConfig = { plugins: [] };
|
|
52
|
+
|
|
53
|
+
const pluginEntries = Object.entries({ ...PLUGINS, ...plugins });
|
|
54
|
+
|
|
55
|
+
for (const [name, isActive] of pluginEntries) {
|
|
56
|
+
if (isActive) {
|
|
57
|
+
const { default: config } = await import(
|
|
58
|
+
`@alexlit/config-prettier/plugins/${name}.js`
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (config.plugins?.length > 0) {
|
|
62
|
+
pluginsConfig.plugins.push(...config.plugins);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
pluginsConfig = { ...pluginsConfig, ...omit(config, ['plugins']) };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return pluginsConfig;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Create prettier config
|
|
74
|
+
*
|
|
75
|
+
* @param {PLUGINS} plugins
|
|
76
|
+
* @param {import('prettier').Config} options Prettier options
|
|
77
|
+
*
|
|
78
|
+
* @returns {import('prettier').Config} Prettier configuration
|
|
79
|
+
*/
|
|
80
|
+
export const createConfig = async (plugins = {}, options = {}) => {
|
|
81
|
+
const pluginsConfig = await createPluginsConfig(plugins);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
endOfLine: 'lf',
|
|
85
|
+
|
|
86
|
+
plugins: [...pluginsConfig.plugins, ...(options.plugins ?? [])],
|
|
87
|
+
|
|
88
|
+
proseWrap: 'always',
|
|
89
|
+
singleQuote: true,
|
|
90
|
+
tabWidth: 2,
|
|
91
|
+
trailingComma: 'all',
|
|
92
|
+
vueIndentScriptAndStyle: true,
|
|
93
|
+
|
|
94
|
+
...omit(pluginsConfig, ['plugins']),
|
|
95
|
+
...omit(options, ['plugins']),
|
|
96
|
+
};
|
|
38
97
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexlit/config-prettier",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "prettier config",
|
|
6
6
|
"keywords": [
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"prettier-plugin-sort-json": "^3.1.0",
|
|
46
46
|
"prettier-plugin-sql": "^0.18.0",
|
|
47
47
|
"prettier-plugin-svelte": "^3.2.2",
|
|
48
|
-
"prettier-plugin-tailwindcss": "^0.5.
|
|
48
|
+
"prettier-plugin-tailwindcss": "^0.5.12",
|
|
49
|
+
"radash": "^12.1.0"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
52
|
"node": ">=18.12.0"
|
package/plugins/jsdoc.js
CHANGED
package/plugins/php.js
ADDED
package/plugins/pug.js
CHANGED
package/plugins/ruby.js
ADDED
package/plugins/sh.js
ADDED
package/plugins/sort-json.js
CHANGED
package/plugins/sql.js
ADDED
package/plugins/svelte.js
CHANGED
package/plugins/tailwindcss.js
CHANGED