{"library":"prettier-eslint","title":"Prettier ESLint Integrator","description":"Prettier-ESLint is a JavaScript utility that orchestrates code formatting by running Prettier first, then applying ESLint's `--fix` functionality. This sequential approach is crucial for maintaining consistent code style across projects, as it resolves potential conflicts between Prettier's opinionated formatting and custom ESLint rules. The current stable version is 16.4.2, with an active development branch targeting version 17 which introduces support for ESLint v9's flat configuration. The package is actively maintained with regular patch and minor releases, alongside a new major version in alpha. It differentiates itself by providing a single programmatic interface to combine these tools, ensuring that ESLint fixes are applied *after* Prettier's formatting, thus preventing ESLint from undoing Prettier's work.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install prettier-eslint"],"cli":null},"imports":["import prettierEslint from 'prettier-eslint';","import type { Options } from 'prettier-eslint';","const { default: prettierEslint } = await import('prettier-eslint');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import prettierEslint from 'prettier-eslint';\nimport { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';\nimport { join } from 'node:path';\n\n// Create a dummy ESLint config for demonstration\nconst eslintConfigContent = `module.exports = {\n  env: { node: true, es2021: true },\n  extends: ['eslint:recommended', 'prettier'],\n  parserOptions: { ecmaVersion: 'latest' },\n  rules: {\n    'semi': ['error', 'never'],\n    'quotes': ['error', 'single'],\n    'indent': ['error', 2]\n  }\n};\n`;\n\n// Ensure a temporary directory exists for config and file\nconst tempDir = join(process.cwd(), 'temp-eslint-test');\nif (!existsSync(tempDir)) {\n  mkdirSync(tempDir, { recursive: true });\n}\n\nconst eslintConfigFile = join(tempDir, '.eslintrc.js');\nconst tempFilePath = join(tempDir, 'example.js');\n\nwriteFileSync(eslintConfigFile, eslintConfigContent);\n\nconst rawCode = `const   myVar  =  \"Hello world\" ; function   test ( ) {  console . log ( myVar )  ;  }  test ( )  ;`;\nwriteFileSync(tempFilePath, rawCode);\n\nasync function formatCode() {\n  try {\n    console.log('Original code:\\n', rawCode);\n\n    const formattedCode = await prettierEslint({\n      text: rawCode,\n      filePath: tempFilePath, // Essential for ESLint to find its config\n      eslintConfig: { // Can be provided directly or found via filePath\n        overrideConfigFile: eslintConfigFile,\n      },\n      prettierOptions: { printWidth: 80, tabWidth: 2, semi: false, singleQuote: true },\n      fallbackPrettierOptions: { printWidth: 80, tabWidth: 2, semi: false, singleQuote: true },\n      logLevel: 'debug',\n    });\n\n    console.log('\\nFormatted code:\\n', formattedCode);\n    writeFileSync(tempFilePath.replace('.js', '.formatted.js'), formattedCode);\n\n  } catch (error) {\n    console.error('Error during formatting:', error);\n  }\n}\n\nformatCode();\n","lang":"typescript","description":"This quickstart demonstrates how to programmatically format a JavaScript string using `prettier-eslint`. It creates a temporary ESLint configuration file and a JavaScript file to illustrate the process, showing how to pass the code, file path, and configuration options. It's crucial for ESLint to correctly locate its configuration to apply fixes effectively.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}