### Install peer dependencies Source: https://github.com/voxpelli/eslint-config/blob/main/README.md Use install-peerdeps to automatically install the required peer dependencies for this configuration. ```bash install-peerdeps --dev @voxpelli/eslint-config ``` -------------------------------- ### Install ESLint Configuration Source: https://context7.com/voxpelli/eslint-config/llms.txt Install the @voxpelli/eslint-config package and ESLint as development dependencies using npm. ```bash npm install --save-dev @voxpelli/eslint-config eslint ``` -------------------------------- ### Installation: Using install-peerdeps Source: https://context7.com/voxpelli/eslint-config/llms.txt Recommends using npx install-peerdeps to install the package and its peer dependencies, ensuring automatic resolution. ```bash # Using install-peerdeps (recommended) npx install-peerdeps --dev @voxpelli/eslint-config ``` -------------------------------- ### Quick Setup with Default Export Source: https://context7.com/voxpelli/eslint-config/llms.txt Use the default export for a ready-to-use ESLint configuration array, preconfigured for ESM projects with Mocha test support. ```javascript // eslint.config.js export { default } from '@voxpelli/eslint-config'; ``` -------------------------------- ### Compare Dependency Files with jq Source: https://github.com/voxpelli/eslint-config/blob/main/dependents-data/README.md Use this command to compare the `workflow-external.json` file with `dependents-data/filtered.json` after sorting and flattening the data. Requires `jq` to be installed. ```sh jd -set -color <(jq 'map(.) | flatten | sort' workflow-external.json) <(cat dependents-data/filtered.json) ``` -------------------------------- ### Update Project Dependencies Source: https://github.com/voxpelli/eslint-config/blob/main/dependents-data/README.md Run this command to update the project's dependencies. Ensure npm is installed and configured. ```sh npm run dependents ``` -------------------------------- ### TypeScript Support Configuration Source: https://context7.com/voxpelli/eslint-config/llms.txt TypeScript support is enabled by default. This example shows how to explicitly pass TypeScript options, though 'ts: true' is the default. ```javascript // eslint.config.js import { voxpelli } from '@voxpelli/eslint-config'; // TypeScript support is enabled by default export default voxpelli({ // Pass any neostandard TypeScript options ts: true, // Already true by default }); ``` -------------------------------- ### Configurable Setup with voxpelli() Function Source: https://context7.com/voxpelli/eslint-config/llms.txt Utilize the main voxpelli() function to create a customized ESLint configuration. Options include CJS mode, disabling Mocha rules, and custom ignores. ```javascript // eslint.config.js import { voxpelli } from '@voxpelli/eslint-config'; // Basic configuration with CommonJS mode export default voxpelli({ cjs: true, // Use CJS-appropriate rules instead of ESM noMocha: true, // Disable Mocha test rules }); ``` -------------------------------- ### Mocha Test Configuration Example Source: https://context7.com/voxpelli/eslint-config/llms.txt Mocha rules are enabled by default for files in the 'test/' directory. The 'mocha/no-mocha-arrows' rule is disabled, allowing arrow functions in tests. ```javascript // eslint.config.js import { voxpelli } from '@voxpelli/eslint-config'; // Mocha rules enabled by default for test/**/* export default voxpelli({ noMocha: false, // Default - Mocha rules enabled }); // Example test file (test/example.test.js): // Arrow functions are allowed in Mocha tests describe('Example', () => { it('should work', () => { expect(true).to.equal(true); }); }); ``` -------------------------------- ### Promise Rules: Prefer async/await over .then() Source: https://context7.com/voxpelli/eslint-config/llms.txt Enforces the use of async/await syntax over .then() chains for cleaner promise handling. Examples show both preferred and discouraged patterns. ```javascript // Rule: 'promise/prefer-await-to-then': 'error' // Good - use async/await async function fetchUser(id) { const response = await fetch(`/api/users/${id}`); const data = await response.json(); return data; } // Bad - would fail linting // function fetchUser(id) { // return fetch(`/api/users/${id}`) // .then(response => response.json()) // .then(data => data); // } ``` -------------------------------- ### Security Rules: Detect Child Process Usage Source: https://context7.com/voxpelli/eslint-config/llms.txt Includes security rules from eslint-plugin-security, with noisy rules disabled. Example demonstrates a potential security warning for using 'child_process'. ```javascript // Security rules are applied automatically // These rules are disabled to reduce false positives: // 'security/detect-object-injection': 'off' // 'security/detect-unsafe-regex': 'off' // Example - other security rules still apply: import { exec } from 'node:child_process'; // This would trigger security/detect-child-process function runCommand(cmd) { exec(cmd, (err, stdout) => { // Security warning console.log(stdout); }); } ``` -------------------------------- ### Sort Destructure Keys Rule Source: https://context7.com/voxpelli/eslint-config/llms.txt Enforces alphabetical sorting of destructured object keys for consistency. Provides examples of correct and incorrect destructuring. ```javascript // Rule: 'sort-destructure-keys/sort-destructure-keys': 'error' // Good - keys are sorted alphabetically const { alpha, beta, gamma } = options; // Bad - would fail linting // const { gamma, alpha, beta } = options; // Example with nested destructuring function processConfig({ database, logging, server }) { const { host, password, port, user } = database; return { host, port }; } ``` -------------------------------- ### Modified Neostandard Rules Example Source: https://context7.com/voxpelli/eslint-config/llms.txt Illustrates the enforced trailing commas in multiline objects and the stricter 'no-unused-vars' rule requiring ignored arguments to be prefixed with an underscore. ```javascript // These rules are applied automatically: // '@stylistic/comma-dangle': ['warn', { // arrays: 'always-multiline', // objects: 'always-multiline', // imports: 'always-multiline', // exports: 'always-multiline', // functions: 'never', // }] // Example code that passes linting: const config = { name: 'example', value: 42, // Trailing comma required in multiline objects }; // Unused args must be prefixed with underscore function handler(req, _res, _next) { console.log(req.url); } ``` -------------------------------- ### Additional Core Rules: Object Shorthand and Comments Source: https://context7.com/voxpelli/eslint-config/llms.txt Enforces core ESLint rules like object shorthand, no-console warnings, and detection of constant binary expressions. Includes example for object shorthand and FIXME comments. ```javascript // Additional core rules applied: // 'func-style': ['warn', 'expression', { 'allowArrowFunctions': true }] // 'no-console': 'warn' // 'no-constant-binary-expression': 'error' // 'no-warning-comments': ['warn', { 'terms': ['fixme'] }] // 'object-shorthand': ['error', 'properties', { 'avoidQuotes': true }] // Example of object shorthand (required): const name = 'example'; const value = 42; // Good - use shorthand const obj = { name, value }; // Bad - would fail linting // const obj = { name: name, value: value }; // FIXME comments trigger warnings: // FIXME: This needs to be fixed // eslint warns ``` -------------------------------- ### JSDoc Rules: TypeScript-flavor JSDoc Source: https://context7.com/voxpelli/eslint-config/llms.txt Configures JSDoc for TypeScript-flavor, with strict type checking rules disabled for compatibility. Example shows a JSDoc comment that passes linting. ```javascript // Configured rules: // 'jsdoc/check-types': 'off' // 'jsdoc/require-jsdoc': 'off' // 'jsdoc/valid-types': 'off' // 'jsdoc/tag-lines': ['warn', 'never', { 'startLines': 1 }] // Example JSDoc that passes linting: /** * Processes user data and returns formatted result. * * @param {import('./types').User} user - The user object * @param {{ format?: string }} options - Processing options * @returns {Promise} */ export async function processUser(user, options = {}) { const { format = 'json' } = options; return format === 'json' ? JSON.stringify(user) : user.toString(); } ``` -------------------------------- ### Unicorn Rules: Catch Error Name and Switch Case Braces Source: https://context7.com/voxpelli/eslint-config/llms.txt Applies Unicorn plugin rules, preferring 'err' for catch blocks and allowing switch cases without braces. Example shows correct usage. ```javascript // Key unicorn overrides: // 'unicorn/catch-error-name': ['error', { name: 'err', ignore: ['^cause$'] }] // 'unicorn/prevent-abbreviations': 'off' // 'unicorn/switch-case-braces': ['error', 'avoid'] // Example code following unicorn rules: async function fetchData(url) { try { const response = await fetch(url); return response.json(); } catch (err) { // Use 'err' not 'error' console.error('Failed to fetch:', err.message); throw err; } } // Switch cases without braces function getColor(status) { switch (status) { case 'success': return 'green'; case 'error': return 'red'; default: return 'gray'; } } ``` -------------------------------- ### Configure with options Source: https://github.com/voxpelli/eslint-config/blob/main/README.md Use the voxpelli function to customize the configuration, such as enabling CJS context or disabling Mocha rules. ```js import { voxpelli } from '@voxpelli/eslint-config'; export default voxpelli({ cjs: true, // Ensures the config has rules fit for a CJS context rather than an ESM context noMocha: true, // By standard this config expects tests to be of the Mocha kind, but one can opt out }); ``` -------------------------------- ### Extending Base Configuration with Custom Rules Source: https://context7.com/voxpelli/eslint-config/llms.txt Extend the base configuration by spreading the result of voxpelli() into a new array and adding custom rules or file-specific configurations. ```javascript // eslint.config.js import { voxpelli } from '@voxpelli/eslint-config'; export default [ ...voxpelli({ cjs: false, noMocha: false, }), { // Custom ESLint rules rules: { 'no-console': 'off', // Override a rule from the base config }, }, { // Target specific files files: ['scripts/**/*.js'], rules: { 'n/no-process-env': 'off', }, }, ]; ``` -------------------------------- ### Extend configuration Source: https://github.com/voxpelli/eslint-config/blob/main/README.md Combine the voxpelli configuration with custom ESLint rules by exporting an array. ```js import { voxpelli } from '@voxpelli/eslint-config'; export default [ ...voxpelli({ // Config options }), { // Custom ESLint config }, ]; ``` -------------------------------- ### Export default configuration Source: https://github.com/voxpelli/eslint-config/blob/main/README.md Export the configuration directly in your eslint.config.js or eslint.config.mjs file. ```js export { default } from '@voxpelli/eslint-config'; ``` -------------------------------- ### Node.js Rules: Prefer Promise-based fs Source: https://context7.com/voxpelli/eslint-config/llms.txt Use promise-based fs methods instead of synchronous ones for better async handling. Ensure Node.js version supports 'node:fs/promises'. ```javascript // Rules applied automatically: // 'n/prefer-global/console': 'warn' // 'n/prefer-promises/fs': 'warn' // 'n/no-process-env': 'warn' // 'n/no-sync': 'error' // Example - Use promise-based fs instead of sync import { readFile } from 'node:fs/promises'; async function loadConfig() { const content = await readFile('config.json', 'utf8'); return JSON.parse(content); } // Avoid direct process.env access - wrap in config module // config.js const config = { port: process.env.PORT || 3000, // eslint warns here }; export default config; ``` -------------------------------- ### Adding Custom Ignores to ESLint Configuration Source: https://context7.com/voxpelli/eslint-config/llms.txt Incorporate additional file patterns to ignore beyond the default .gitignore patterns and coverage directories. ```javascript // eslint.config.js import { voxpelli } from '@voxpelli/eslint-config'; export default voxpelli({ ignores: [ 'dist/**/*', 'build/**/*', 'vendor/**/*', ], }); ``` -------------------------------- ### ESM-Specific Rules Enforcement Source: https://context7.com/voxpelli/eslint-config/llms.txt In ESM mode (default), function declarations are enforced. Arrow functions are still permitted, but function declarations are preferred. ```javascript // eslint.config.js import { voxpelli } from '@voxpelli/eslint-config'; // ESM mode (default) - enforces function declarations export default voxpelli({ cjs: false, // Default }); // Example code style enforced in ESM mode: // Preferred - function declaration export function processData(data) { return data.map(item => item.value); } // Arrow functions are still allowed export const transform = (x) => x * 2; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.