@persagy2/eslint-plugin
Version:
一个适用于 vue3.x、typescript 项目的通用eslint预设插件
42 lines (38 loc) • 1.34 kB
text/typescript
import { Config, resolveConfig, resolveConfigFile } from 'prettier'
import { fileURLToPath } from 'node:url'
import np from 'node:path'
const __filename = fileURLToPath(import.meta.url)
/** 项目根目录 */
const root: string = np.resolve(np.dirname(__filename), '..')
/** 默认配置 */
const DEFAULT_CONFIG: Config = {
// ! 注意: 由于 eslint-plugin-prettier 识别不出来时, 会默认给一个 babel 的 parser, 所以这里覆盖掉这个配置
// ! 让 prettier 自己去识别
parser: undefined,
/** 在语句末尾打印分号 */
semi: false,
/** 优先单引号 */
singleQuote: true,
/** 单行 120字节代码 */
printWidth: 120,
/** tab 长度 */
tabWidth: 4,
/** 多行数组、对象结尾不附加逗号 */
trailingComma: 'none',
/** 文件结尾空行 */
endOfLine: 'auto'
}
/** 检索或使用默认的prettier配置 */
export const resolvePrettierConfig = async (): Promise<Config> => {
/** 可能存在的配置文件路径 */
const configPath: string | undefined = await resolveConfigFile(root)
if (!configPath) {
return DEFAULT_CONFIG
} else {
const config = await resolveConfig(configPath)
return {
...DEFAULT_CONFIG,
...config
}
}
}