@empathyco/eslint-config
Version:
ESLint and Prettier config preset
63 lines (61 loc) • 1.42 kB
JavaScript
// src/utils/loadPrettierPlugins.js
import { existsSync, readFileSync } from "fs";
import { resolve } from "path";
import process from "process";
import { globSync } from "tinyglobby";
function checkPackageJson(path) {
if (existsSync(path)) {
const packageJson = JSON.parse(readFileSync(path, "utf-8"));
const deps = {
...packageJson.dependencies || {},
...packageJson.devDependencies || {}
};
if (deps.tailwindcss || deps["@nuxtjs/tailwindcss"]) {
return true;
}
}
return false;
}
function isTailwindInstalled() {
try {
const packages = globSync(["**/package.json"], {
ignore: ["**/node_modules/**", "**/dist/**"]
});
for (const pkg of packages) {
const packageJsonPath = resolve(process.cwd(), pkg);
if (checkPackageJson(packageJsonPath)) {
return true;
}
}
} catch {
return false;
}
return false;
}
function loadPrettierPlugins() {
const plugins = [];
if (isTailwindInstalled()) {
plugins.push(import("prettier-plugin-tailwindcss"));
}
return plugins;
}
// prettier.config.js
var config = {
printWidth: 100,
singleQuote: true,
arrowParens: "avoid",
semi: false,
plugins: loadPrettierPlugins(),
overrides: [
{
files: "*.svg",
options: {
parser: "html"
}
}
]
};
var prettier_config_default = config;
export {
prettier_config_default as default
};