### ESM Usage Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/default-config.md Demonstrates how to import and use the default ESLint configuration in an ESM (ECMAScript Modules) setup. It shows how to spread the configuration and specify files to lint. ```javascript import love from 'eslint-config-love' export default [ { ...love, files: ['**/*.js', '**/*.ts'], }, ] ``` -------------------------------- ### Quick Lookup Guide: How do I...? Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Provides a quick lookup guide for common questions related to ESLint configuration and usage. ```markdown ### "How do I...?" | Question | Answer Location | |----------|-----------------| | Use the configuration? | default-config.md, configuration.md | | Override a specific rule? | configuration.md, any rule document | | Handle TypeScript types? | typescript-eslint-rules.md, types.md | | Fix import issues? | import-rules.md | | Handle async code correctly? | promise-rules.md, typescript-eslint-rules.md | | Manage eslint-disable comments? | eslint-comments-rules.md | | Write Node.js code? | node-rules.md | | Organize project imports? | import-rules.md, configuration.md | | Set up path aliases? | import-rules.md, configuration.md | | Relax rules for legacy code? | configuration.md, relevant rule document | | Use in CommonJS project? | configuration.md | ``` -------------------------------- ### File Manifest Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/README.md This snippet shows the directory structure and the purpose of each file within the documentation. ```text output/ ├── README.md (this file) ├── types.md Type definitions reference ├── configuration.md Configuration guide └── api-reference/ ├── default-config.md Main config object ├── module-exports.md All exported symbols ├── eslint-core-rules.md 97 core rules ├── typescript-eslint-rules.md 97 TypeScript rules ├── eslint-comments-rules.md 6 directive rules ├── node-rules.md 7 Node.js rules ├── promise-rules.md 5 Promise rules └── import-rules.md 8 Import rules ``` -------------------------------- ### Example Command Line Usage Source: https://github.com/mightyiam/eslint-config-love/blob/master/README.md Run ESLint on all files in the current directory using the configured rules. ```bash $ npx eslint . ``` -------------------------------- ### Example Plugin Usage in Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Illustrates how to include various ESLint plugins within the main configuration object. ```typescript plugins: { '@typescript-eslint': Plugin '@eslint-community/eslint-comments': Plugin 'n': Plugin 'promise': Plugin 'import': Plugin } ``` -------------------------------- ### Import Main Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/00-START-HERE.md Import the main ESLint configuration object from the 'eslint-config-love' package. This is the primary way to start using the configuration. ```javascript import love from 'eslint-config-love' export default [{ ...love, files: ['**/*.ts'] }] ``` -------------------------------- ### Example PluginUsage Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Illustrates how to configure a specific plugin, such as '@typescript-eslint', using the `PluginUsage` interface. This includes specifying rules with their error levels and configurations. ```typescript const typescriptEslint: PluginUsage = { pluginName: '@typescript-eslint', plugin: plugin, // from typescript-eslint rules: { '@typescript-eslint/explicit-function-return-type': ['error', { /* ... */ }], '@typescript-eslint/no-explicit-any': ['error', { /* ... */ }], // ... 97 more rules } } ``` -------------------------------- ### Quick Lookup Guide: What rule controls...? Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Provides a quick lookup guide to identify rules controlling specific code concerns. ```markdown ### "What rule controls...?" | Concern | Documents | |---------|-----------| | Function complexity | eslint-core-rules.md (complexity rule) | | File length | eslint-core-rules.md (max-lines rule) | | Parameter count | typescript-eslint-rules.md (max-params rule) | | Variable naming | typescript-eslint-rules.md (naming-convention rule) | | Return type annotations | typescript-eslint-rules.md (explicit-function-return-type rule) | | Type assertions | typescript-eslint-rules.md (consistent-type-assertions rule) | | Unused variables | typescript-eslint-rules.md (no-unused-vars rule) | | Unused imports | import-rules.md (no-duplicates rule) | | Promise patterns | promise-rules.md (all 5 rules) | | Callback errors | node-rules.md (handle-callback-err rule) | | Console usage | eslint-core-rules.md (no-console rule) | | Magic numbers | typescript-eslint-rules.md (no-magic-numbers rule) | ``` -------------------------------- ### Require Description Rule Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-comments-rules.md Shows examples of eslint-disable comments with and without descriptions. Use the '--' syntax to provide a clear explanation for disabling a rule. ```javascript // ✗ Wrong: no description /* eslint-disable no-console */ console.log('test') // ✓ Correct: descriptive explanation /* eslint-disable no-console -- TODO: implement proper logging */ console.log('test') // ✓ Correct: describing browser environment /* eslint-env browser */ window.alert('test') // ✓ Correct: enable doesn't need description /* eslint-enable no-console */ ``` -------------------------------- ### Example Usage of Exported Members Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Demonstrates how to import and access rules, plugins, and rules grouped by plugin name from the `eslint-config-love/src/plugin-usage` module. ```typescript import { rules, plugins, rulesPerPlugin } from 'eslint-config-love/src/plugin-usage' // Access rules by plugin const tsRules = rulesPerPlugin['@typescript-eslint'] const importRules = rulesPerPlugin['import'] // Access all flattened rules const allRules = rules // Includes keys like: // 'no-console', '@typescript-eslint/no-explicit-any', 'import/first' // Access plugins const tsPlugin = plugins['@typescript-eslint'] ``` -------------------------------- ### Promise Error Handling Examples Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/promise-rules.md Demonstrates proper error handling for Promises using try-catch blocks, .catch() with promise chains, and Promise.all. ```javascript // Good: proper error handling async function fetchUser(id) { try { const response = await fetch(`/api/users/${id}`) if (!response.ok) { throw new Error(`HTTP ${response.status}`) } return response.json() } catch (error) { console.error('Failed to fetch user:', error) throw error // Re-throw or handle appropriately } } ``` ```javascript // Good: Promise chain with catch fetchUser(1) .then(user => console.log(user)) .catch(error => console.error(error)) ``` ```javascript // Good: Promise.all with proper error handling Promise.all([promise1, promise2]) .then(([result1, result2]) => { // Both succeeded }) .catch(error => { // At least one failed }) ``` -------------------------------- ### Async Function Best Practices Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/promise-rules.md Provides examples of simple async functions, async functions with integrated error handling, and parallel asynchronous operations using Promise.all. ```javascript // Good: simple async function async function processData(url) { const response = await fetch(url) return response.json() } ``` ```javascript // Good: async function with error handling async function processData(url) { try { const response = await fetch(url) if (!response.ok) throw new Error(`HTTP ${response.status}`) return response.json() } catch (error) { console.error('Processing failed:', error) throw error } } ``` ```javascript // Good: parallel async operations async function loadMultiple(urls) { try { const responses = await Promise.all( urls.map(url => fetch(url).then(r => r.json())) ) return responses } catch (error) { console.error('Loading failed:', error) throw error } } ``` -------------------------------- ### Example RulesRecord Structure Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Provides an example of a 'RulesRecord' object, showcasing various rule configurations including basic settings, options, and TypeScript-specific rules. ```typescript rules: { 'no-console': ['error'], 'no-const-assign': ['error'], 'eqeqeq': ['error', 'always', { null: 'always' }], '@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true, allowHigherOrderFunctions: true }], 'import/first': ['error'] } ``` -------------------------------- ### CommonJS Usage Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/default-config.md Illustrates how to import and use the default ESLint configuration within a CommonJS environment using dynamic import. This is useful for projects that do not yet support ESM. ```javascript module.exports = (async function config() { const { default: love } = await import('eslint-config-love') return [ { ...love, files: ['**/*.js', '**/*.ts'], }, ] })() ``` -------------------------------- ### Main ESLint Configuration Export Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/README.md Import and spread the main `eslint-config-love` configuration. Use this for basic setup targeting TypeScript files. ```javascript import love from 'eslint-config-love' export default [ { ...love, files: ['**/*.ts'], }, ] ``` -------------------------------- ### Comment Formatting Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-comments-rules.md Demonstrates the recommended `--` syntax for adding descriptions to ESLint directive comments. This format clearly explains the reason for disabling a rule. ```javascript /* eslint-disable no-console -- Temporary debugging for JIRA-123 */ ``` -------------------------------- ### Project Navigation Structure Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/MANIFEST.md This diagram illustrates the primary navigation path through the ESLint Config Love documentation, starting from the entry point and branching out to various sections like README, INDEX, configuration, and API reference. ```text Start Here ↓ 00-START-HERE.md (main entry) ↓ ├→ README.md (overview) ├→ INDEX.md (complete index) ├→ configuration.md (setup guide) └→ api-reference/ (rule details) ├→ default-config.md ├→ module-exports.md ├→ eslint-core-rules.md ├→ typescript-eslint-rules.md ├→ eslint-comments-rules.md ├→ node-rules.md ├→ promise-rules.md └→ import-rules.md ``` -------------------------------- ### No Unlimited Disable Rule Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-comments-rules.md Demonstrates the correct way to disable specific rules versus disabling all rules. Always specify the rules being disabled to prevent masking new issues. ```javascript // ✗ Wrong: disables all rules /* eslint-disable */ const x = 1 /* eslint-enable */ // ✓ Correct: specific rules /* eslint-disable no-unused-vars */ const x = 1 /* eslint-enable no-unused-vars */ ``` -------------------------------- ### CommonJS vs ESM Code Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/node-rules.md Illustrates the difference in syntax and module loading between CommonJS (using `require` and `module.exports`) and ECMAScript Modules (using `import` and `export`). Highlights where Node.js specific ESLint rules typically apply. ```javascript // CommonJS (where these rules apply) const fs = require('fs') module.exports = { /* ... */ } // ESM (rules don't apply the same way) import fs from 'fs' export { /* ... */ } ``` -------------------------------- ### ESLint Configuration: Relaxing Promise Rules Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/promise-rules.md Example ESLint configuration to disable the 'promise/avoid-new' rule, allowing the use of the Promise constructor when necessary. ```javascript export default [ { ...love, files: ['src/**/*.ts'], rules: { ...love.rules, 'promise/avoid-new': 'off', // Allow Promise constructor if needed }, }, ] ``` -------------------------------- ### No Aggregating Enable Rule Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-comments-rules.md Illustrates the difference between correct explicit rule enabling and incorrect ambiguous multi-rule enabling. Explicitly list rules when using eslint-enable. ```javascript // ✓ Correct: explicit rules /* eslint-disable no-console, no-alert */ console.log('test') /* eslint-enable no-console, no-alert */ // ✗ Wrong: ambiguous enable /* eslint-disable no-console, no-alert */ console.log('test') /* eslint-enable */ ``` -------------------------------- ### Promise Chain Patterns Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/promise-rules.md Shows examples of clear promise chains for sequential asynchronous operations and handling multiple specific errors using chained .catch() blocks. ```javascript // Good: clear promise chain fetch('/api/data') .then(response => response.json()) .then(data => processData(data)) .then(result => console.log(result)) .catch(error => console.error('Error:', error)) ``` ```javascript // Good: multiple catch handlers for specific errors fetch('/api/data') .then(response => { if (!response.ok) throw new Error('API error') return response.json() }) .catch(error => { if (error instanceof TypeError) { console.error('Network error:', error) } else { console.error('API error:', error) } }) ``` -------------------------------- ### Disable Enable Pair Rule Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-comments-rules.md Demonstrates correct usage of eslint-disable and eslint-enable pairs. The allowWholeFile option permits disabling rules for the entire file. ```javascript /* eslint-disable no-console -- TODO: remove later */ console.log('test') /* eslint-enable no-console */ // File-wide disable is allowed: /* eslint-disable */ // ... entire file with rules disabled ``` -------------------------------- ### ESLint Configuration: Strict Promise Enforcement Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/promise-rules.md Example ESLint configuration to enforce strict Promise patterns by enabling rules like 'promise/no-return-wrap', 'promise/no-multiple-resolved', and 'promise/prefer-catch'. ```javascript export default [ { ...love, files: ['src/**/*.ts'], rules: { ...love.rules, 'promise/no-return-wrap': 'error', 'promise/no-multiple-resolved': 'error', 'promise/prefer-catch': 'error', }, }, ] ``` -------------------------------- ### No Unused Enable Rule Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-comments-rules.md Highlights the issue of using eslint-enable without a preceding eslint-disable directive. Ensure enable directives have a corresponding disable directive. ```javascript // ✗ Wrong: enable without prior disable console.log('test') /* eslint-enable no-console */ // no-console was never disabled // ✓ Correct: matching pair /* eslint-disable no-console */ console.log('test') /* eslint-enable no-console */ ``` -------------------------------- ### ESLint Config with ECMAScript Modules Source: https://github.com/mightyiam/eslint-config-love/blob/master/README.md Use this configuration when your project uses ECMAScript Modules for its build or import system. Ensure 'eslint-config-love' is installed. ```javascript import love from 'eslint-config-love' export default [ { ...love, files: ['**/*.js', '**/*.ts'], }, ] ``` -------------------------------- ### Ignore Import Rules for Test Files Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/import-rules.md Relaxes specific import rules, such as 'import/first', for test files to allow more flexibility in test setup. ```javascript export default [ { ...love, files: ['src/**/*.ts'], }, { files: ['test/**/*.test.ts'], rules: { ...love.rules, 'import/first': 'off', // test setup imports can come after other code }, }, ] ``` -------------------------------- ### Override ESLint Core Rules Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-core-rules.md Demonstrates how to override specific ESLint core rules by providing new configurations within the `rules` object. This example changes 'no-console' to a warning, increases the complexity limit, and raises the maximum lines per file. ```javascript export default [ { ...love, rules: { ...love.rules, 'no-console': 'warn', // Change from error to warn 'complexity': ['error', { max: 15 }], // Increase complexity limit 'max-lines': ['error', { max: 600 }], // Increase file line limit }, }, ] ``` -------------------------------- ### Require Node.js Protocol Prefix for Built-ins Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/import-rules.md Requires Node.js built-in modules to use the 'node:' protocol prefix for clarity and to prevent naming conflicts with installed packages. ```javascript // ✓ Correct: use node: prefix import fs from 'node:fs' import path from 'node:path' import { readFile } = from 'node:fs/promises' // ✗ Wrong: missing node: prefix import fs from 'fs' import path from 'path' // ✓ Correct: third-party packages don't use prefix import express from 'express' import lodash from 'lodash' ``` -------------------------------- ### Apply ESLint Config to Specific Files Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/configuration.md Use the 'files' property to specify glob patterns for files that should be linted by this configuration. This example applies the 'eslint-config-love' configuration to all .ts and .tsx files within the 'src' directory. ```javascript import love from 'eslint-config-love' export default [ { ...love, files: ['src/**/*.ts', 'src/**/*.tsx'], }, ] ``` -------------------------------- ### Ignore Specific Files and Directories with ESLint Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/configuration.md Use the 'ignores' property to define glob patterns for files and directories that should be excluded from linting. This example ignores common build output, dependency, and version control directories. It also shows how to apply a configuration to all .ts files while ignoring others. ```javascript export default [ { ignores: ['dist/', 'build/', 'node_modules/', '.git/'], }, { ...love, files: ['**/*.ts'], }, ] ``` -------------------------------- ### Disable a Rule Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Example of how to disable a specific ESLint rule, in this case, 'no-console'. ```typescript rules: { 'no-console': 'off' } ``` -------------------------------- ### Type System Reference Overview Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Lists the key type definitions available in the project for configuration and plugin development. Refer to types.md for full details. ```markdown **See types.md for:** - TSESLint.FlatConfig.Config — Main configuration type - TSESLint.FlatConfig.Plugin — Plugin type definition - TSESLint.SharedConfig.RuleEntry — Rule configuration type - TSESLint.SharedConfig.RulesRecord — All rules record - PluginUsage — Plugin definition interface - FlatConfig extended properties ``` -------------------------------- ### Enable a Rule with Error Level Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Example of how to enable a specific ESLint rule, 'no-console', to report errors. ```typescript rules: { 'no-console': 'error' } ``` -------------------------------- ### Import Plugin Rules Overview Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Lists the rules provided by the Import plugin. Refer to the specified file for details. ```markdown **Import (8 rules):** - enforce-node-protocol-usage, export, first, no-absolute-path - no-duplicates, no-named-default, no-webpack-loader-syntax ``` -------------------------------- ### No Duplicate Disable Rule Example Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-comments-rules.md Shows how to avoid redundant eslint-disable comments for the same rule. Duplicate disables can indicate errors and should be removed. ```javascript // ✗ Wrong: duplicate disables /* eslint-disable no-console */ console.log('1') /* eslint-disable no-console */ // Duplicate console.log('2') // ✓ Correct: single disable /* eslint-disable no-console */ console.log('1') console.log('2') ``` -------------------------------- ### Accessing and Viewing ESLint Rule Configurations Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-core-rules.md Demonstrates how to import the ESLint configuration and access specific rule configurations, such as 'complexity' and 'no-console'. This is useful for understanding the exact settings applied by the configuration. ```javascript import love from 'eslint-config-love' // View complexity rule configuration const complexityConfig = love.rules.complexity // Result: ['error', { variant: 'modified', max: 10 }] // View no-console rule configuration const noConsoleConfig = love.rules['no-console'] // Result: ['error'] ``` -------------------------------- ### Promise Plugin Rules Overview Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Lists the rules provided by the Promise plugin. Refer to the specified file for details. ```markdown **Promise (5 rules):** - avoid-new, no-multiple-resolved, no-return-wrap, param-names, prefer-catch ``` -------------------------------- ### Use Consistent Module Paths Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/import-rules.md Employs relative paths for local modules, 'node:' prefix for built-ins, package names for dependencies, and path aliases for configured shortcuts. ```javascript // Good: relative paths for local modules import { config } from '../config' import { logger } from '../services/logger' import { Helper } from './helper' // Good: node: prefix for built-ins import fs from 'node:fs' import path from 'node:path' // Good: package names for dependencies import express from 'express' import React from 'react' // Good: path aliases (if configured) import { config } from '@config' import { logger } from '@services/logger' ``` -------------------------------- ### Import Default Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/configuration.md Import the default ESLint configuration object provided by the 'eslint-config-love' package. ```javascript import love from 'eslint-config-love' // love is of type: TSESLint.FlatConfig.Config ``` -------------------------------- ### Override ESLint Rule Options Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/README.md Customize the options for a specific ESLint rule. This example shows how to configure the `no-magic-numbers` rule to ignore certain values. ```javascript { rules: { 'no-magic-numbers': ['error', { ignore: [0, 1, -1] }] } } ``` -------------------------------- ### Promise Constructor and Resolution Patterns Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/promise-rules.md Illustrates the correct usage of the Promise constructor for wrapping callback-based APIs and using Promise.resolve/reject for immediate values or errors. ```javascript // Good: constructor for wrapping callbacks function readFile(filename) { return new Promise((resolve, reject) => { fs.readFile(filename, (err, data) => { if (err) reject(err) else resolve(data) }) }) } ``` ```javascript // Good: use Promise.resolve for immediate values const value = 42 const promise = Promise.resolve(value) ``` ```javascript // Good: use Promise.reject for immediate errors const error = new Error('failed') const rejected = Promise.reject(error) ``` -------------------------------- ### Partial File Matching Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/default-config.md Shows how to apply the default ESLint configuration to specific file patterns and override rules for other files. This allows for granular control over linting across different parts of a project. ```javascript import love from 'eslint-config-love' export default [ { ...love, files: ['src/**/*.ts', 'test/**/*.ts'], }, { files: ['src/**/*.js'], rules: { '@typescript-eslint/no-var-requires': 'off', }, }, ] ``` -------------------------------- ### Use Default ESLint Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Apply the default ESLint configuration by spreading it into your ESLint configuration array. Specify files to include in the configuration. ```javascript import love from 'eslint-config-love' export default [ { ...love, files: ['**/*.ts', '**/*.tsx'], }, ] ``` -------------------------------- ### Target Specific Files with Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/configuration.md Use the 'files' property in the flat configuration format to apply settings to specific file patterns. ```javascript import love from 'eslint-config-love' export default [ { ...love, files: ['**/*.ts', '**/*.tsx'], }, { files: ['src/**/*.js'], rules: { '@typescript-eslint/no-var-requires': 'off', }, }, { files: ['**/*.test.ts'], rules: { 'no-console': 'off', }, }, ] ``` -------------------------------- ### Target Specific Files Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/00-START-HERE.md Apply the configuration to specific files or directories using the 'files' property. This is useful for setting different configurations for different parts of your project. ```javascript export default [{ ...love, files: ['src/**/*.ts'] }] ``` -------------------------------- ### Disabling Rules with ESLint Comments Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/default-config.md Provides examples of how to disable specific ESLint rules using inline comments. This is useful for temporarily bypassing a rule for a particular line or block of code. ```javascript // eslint-disable-next-line @typescript-eslint/no-explicit-any const value: any = foo() /* eslint-disable @typescript-eslint/no-non-null-assertion */ const bar = obj!.property /* eslint-enable @typescript-eslint/no-non-null-assertion */ ``` -------------------------------- ### Node.js Plugin Rules Overview Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Lists the rules provided by the Node.js plugin. Refer to the specified file for details. ```markdown **Node.js (7 rules):** - handle-callback-err, no-callback-literal, no-deprecated-api - no-exports-assign, no-new-require, no-path-concat, process-exit-as-throw ``` -------------------------------- ### Access All Flattened ESLint Rules Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Get a flattened record of all configured ESLint rules, including core, TypeScript, import, Promise, comments, and Node.js rules, by importing the `rules` export from the `plugin-usage` sub-module. ```typescript import { rules } from 'eslint-config-love/src/plugin-usage' rules['no-console'] // Core rule rules['@typescript-eslint/explicit-function-return-type'] // TypeScript rule rules['import/first'] // Import rule rules['promise/avoid-new'] // Promise rule rules['@eslint-community/eslint-comments/require-description'] // Comments rule rules['n/handle-callback-err'] // Node.js rule ``` -------------------------------- ### Import Promise Rules Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Import the predefined Promise rules from the 'eslint-config-love' package. This snippet demonstrates accessing the plugin name, plugin object, and the specific rules for Promise. ```typescript import promiseRules from 'eslint-config-love/src/plugin-usage/promise' // promiseRules.pluginName === 'promise' // promiseRules.plugin = PromisePlugin // promiseRules.rules = { 'avoid-new': [...], ... } ``` -------------------------------- ### Path Management with Node.js Path Module Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/node-rules.md Illustrates using the built-in 'path' module for cross-platform compatible file and directory operations. This is a best practice for ensuring code works across different operating systems. ```javascript const path = require('path') const fs = require('fs') // Cross-platform file operations const configPath = path.join(process.cwd(), 'config', 'settings.json') const data = fs.readFileSync(configPath, 'utf8') // Use path for directory operations const srcDir = path.join(__dirname, '..', 'src') const files = fs.readdirSync(srcDir) ``` -------------------------------- ### Consistent Export Patterns Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/import-rules.md Demonstrates various consistent export styles including named exports, default exports, mixed exports, and re-exporting from other modules. ```javascript // Pattern 1: Named exports export const foo = 'bar' export const baz = 'qux' export { foo, baz } // Pattern 2: Default export export default { foo, baz } // Pattern 3: Mixed (default + named) export const foo = 'bar' export default { foo, other: 'data' } // Pattern 4: Re-export from another module export { foo, bar } from './another-module' export { default as Component } from './Component' ``` -------------------------------- ### Type-Safe Configuration with File Specificity Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/typescript-eslint-rules.md Shows how to apply strict type safety rules for TypeScript files and relax them for test files using specific 'files' properties in the ESLint configuration. ```javascript import love from 'eslint-config-love' export default [ { ...love, files: ['src/**/*.ts'], rules: { ...love.rules, // Strict type safety '@typescript-eslint/strict-boolean-expressions': 'error', '@typescript-eslint/no-floating-promises': 'error', }, }, { // Relax rules for test files files: ['src/**/*.test.ts'], rules: { '@typescript-eslint/no-explicit-any': 'off', }, }, ] ``` -------------------------------- ### Import Default ESLint Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Import the default ESLint configuration object from the `eslint-config-love` package. This is a production-ready configuration for TypeScript projects. ```typescript import love from 'eslint-config-love' ``` -------------------------------- ### ESLint Core Rules Overview Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Lists the categories of ESLint core rules covered in the documentation. Refer to the specified file for a complete list. ```markdown ### ESLint Core Rules (97 total) See **eslint-core-rules.md** for: - accessor-pairs, array-callback-return, arrow-body-style - complexity, consistent-this, constructor-super, curly - default-case-last, eqeqeq, for-direction, grouped-accessor-pairs - guard-for-in, logical-assignment-operators, max-depth, max-lines - new-cap, no-alert, no-async-promise-executor, no-await-in-loop - no-caller, no-case-declarations, no-class-assign, no-compare-neg-zero - no-cond-assign, no-console, no-const-assign, no-constructor-return - no-control-regex, no-debugger, no-delete-var, no-dupe-args - [... and 70 more rules] ``` -------------------------------- ### Override Rule Configuration Options Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/configuration.md Provide additional configuration options to rules that accept them, like setting a maximum value for complexity or line count. ```javascript import love from 'eslint-config-love' export default [ { ...love, rules: { ...love.rules, 'complexity': ['error', { max: 15 }], 'max-lines': ['error', { max: 600 }], 'no-magic-numbers': ['error', { ignore: [0, 1, -1] }], }, }, ] ``` -------------------------------- ### Configure Rule with Single Option Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Demonstrates configuring a rule, 'complexity', with a single option object to set a maximum complexity value. ```typescript rules: { 'complexity': ['error', { max: 10 }] } ``` -------------------------------- ### Import ESLint Core Rules Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Import the default export from `eslint-config-love/src/plugin-usage/eslint` to access the `PluginUsage` object for ESLint core rules. This object contains metadata and the rules themselves. ```typescript import eslintRules from 'eslint-config-love/src/plugin-usage/eslint' // eslintRules.pluginName === '' // eslintRules.plugin === 'eslint' // eslintRules.rules = { 'no-console': [...], 'no-var': [...], ... } ``` -------------------------------- ### ESLint Comments Plugin Rules Overview Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Lists the rules provided by the ESLint Comments plugin. Refer to the specified file for details. ```markdown **ESLint Comments (6 rules):** - disable-enable-pair, no-aggregating-enable, no-duplicate-disable - no-unlimited-disable, no-unused-enable, require-description ``` -------------------------------- ### Import TypeScript ESLint Rules Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Import the default export from `eslint-config-love/src/plugin-usage/typescript-eslint` to access the `PluginUsage` object for TypeScript ESLint rules. This object contains metadata and the rules themselves. ```typescript import tsRules from 'eslint-config-love/src/plugin-usage/typescript-eslint' // tsRules.pluginName === '@typescript-eslint' // tsRules.plugin = TypeScriptESLintPlugin // tsRules.rules = { 'explicit-function-return-type': [...], ... } ``` -------------------------------- ### Export Hierarchy Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Illustrates the export hierarchy of the eslint-config-love package, showing the main export and sub-modules. ```markdown ## Export Hierarchy ``` eslint-config-love (main package) ├── default export │ └── TSESLint.FlatConfig.Config (main configuration) │ ├── plugin-usage (sub-module) │ ├── rulesPerPlugin (Record) │ ├── rules (RulesRecord) │ ├── plugins (Record) │ │ │ ├── eslint.ts → PluginUsage (97 core rules) │ ├── typescript-eslint.ts → PluginUsage (97 TS rules) │ ├── eslint-comments.ts → PluginUsage (6 comment rules) │ ├── n.ts → PluginUsage (7 Node rules) │ ├── promise.ts → PluginUsage (5 Promise rules) │ └── import.ts → PluginUsage (8 Import rules) │ └── types.d.ts └── Module type declarations ``` ``` -------------------------------- ### TypeScript ESLint Rules Overview Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/INDEX.md Lists the categories of TypeScript ESLint rules covered in the documentation. Refer to the specified file for a complete list. ```markdown ### TypeScript ESLint Rules (97 total) See **typescript-eslint-rules.md** for: - array-type, await-thenable, ban-ts-comment, class-literal-property-style - consistent-generic-constructors, consistent-indexed-object-style - consistent-type-assertions, consistent-type-definitions - dot-notation, explicit-function-return-type, explicit-member-accessibility - init-declarations, max-params, method-signature-style, naming-convention - no-array-delete, no-array-constructor, no-base-to-string - [... and 80 more rules] ``` -------------------------------- ### ESLint Config with CommonJS Source: https://github.com/mightyiam/eslint-config-love/blob/master/README.md This configuration is for projects that use CommonJS module syntax. It dynamically imports the 'eslint-config-love' package. ```javascript module.exports = (async function config() { const { default: love } = await import('eslint-config-love') return [ { ...love, files: ['**/*.js', '**/*.ts'], }, ] })() ``` -------------------------------- ### Configuring ESLint Comments for Strict Description Requirements Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/eslint-comments-rules.md Demonstrates how to enforce stricter comment standards by requiring descriptions for all disable comments, including enable/env directives. ```javascript export default [ { ...love, files: ['src/**/*.ts'], rules: { ...love.rules, '@eslint-community/eslint-comments/require-description': [ 'error', { ignore: [] } // Require descriptions even for enable/env ], }, }, ] ``` -------------------------------- ### Require Imports at Top of File Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/import-rules.md Ensures all import statements appear at the beginning of a module, before any other code, to clearly indicate dependencies. ```javascript // ✓ Correct: imports first import fs from 'node:fs' import path from 'node:path' const config = { /* ... */ } const data = fs.readFileSync('file.txt') // ✗ Wrong: imports after other code const config = { /* ... */ } import fs from 'node:fs' // Should be at top // ✓ Correct: comments are allowed before imports // Copyright notice /* License header */ import fs from 'node:fs' const data = fs.readFileSync('file.txt') ``` -------------------------------- ### Import Import Rules Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Import the predefined Import rules from the 'eslint-config-love' package. This snippet shows how to access the plugin name, plugin object, and the specific rules for Import. ```typescript import importRules from 'eslint-config-love/src/plugin-usage/import' // importRules.pluginName === 'import' // importRules.plugin = ImportPlugin // importRules.rules = { 'first': [...], ... } ``` -------------------------------- ### Sub-module Exports - Plugin Usage Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Access detailed information about plugins and their rules, including organized rule sets and individual plugin configurations. ```APIDOC ## Sub-module Exports - Plugin Usage ### Description Provides utilities and data structures for understanding and utilizing the plugins and rules within `eslint-config-love`. ### Module Path `eslint-config-love/src/plugin-usage` #### Named Export: PluginUsage (interface) ##### Description An interface representing a plugin's usage, including its name, the plugin object itself, and its associated rules. ##### Type Definition ```typescript export interface PluginUsage { pluginName: string plugin: TSESLint.FlatConfig.Plugin | 'eslint' rules: Record } ``` #### Named Export: rulesPerPlugin ##### Description An object where keys are plugin identifiers (e.g., `'@typescript-eslint'`) and values are records of rules specific to that plugin. ##### Type `Record` ##### Example ```typescript import { rulesPerPlugin } from 'eslint-config-love/src/plugin-usage' rulesPerPlugin['@typescript-eslint'] rulesPerPlugin['@eslint-community/eslint-comments'] rulesPerPlugin['import'] rulesPerPlugin['n'] rulesPerPlugin['promise'] rulesPerPlugin[''] // ESLint core rules ``` #### Named Export: rules ##### Description An object containing all configured rules from all plugins, flattened into a single record with qualified names. ##### Type `TSESLint.SharedConfig.RulesRecord` ##### Example ```typescript import { rules } from 'eslint-config-love/src/plugin-usage' rules['no-console'] rules['@typescript-eslint/explicit-function-return-type'] rules['import/first'] rules['promise/avoid-new'] rules['@eslint-community/eslint-comments/require-description'] rules['n/handle-callback-err'] ``` #### Named Export: plugins ##### Description An object containing the plugin objects themselves, keyed by their identifier. Excludes the ESLint core rules. ##### Type `Record` ##### Example ```typescript import { plugins } from 'eslint-config-love/src/plugin-usage' plugins['@typescript-eslint'] plugins['@eslint-community/eslint-comments'] plugins['import'] plugins['n'] plugins['promise'] ``` ``` -------------------------------- ### TypeScript Integration: Promise.all with Typed Results Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/promise-rules.md Illustrates using Promise.all in TypeScript with a tuple type for the resolved values, ensuring type safety for multiple asynchronous operations. ```typescript // Good: Promise.all with typed results const results: Promise<[Data1, Data2]> = Promise.all([ fetchData('url1'), fetchData('url2'), ]) ``` -------------------------------- ### Import Node.js Rules Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/module-exports.md Import the predefined Node.js rules from the 'eslint-config-love' package. This snippet shows how to access the plugin name, plugin object, and the specific rules for Node.js. ```typescript import nRules from 'eslint-config-love/src/plugin-usage/n' // nRules.pluginName === 'n' // nRules.plugin = NodePlugin // nRules.rules = { 'handle-callback-err': [...], ... } ``` -------------------------------- ### Using TypeScript ESLint Parser Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Specifies the TypeScript ESLint parser for the configuration. ```typescript parser: TSESLint.FlatConfig.Parser // from typescript-eslint ``` -------------------------------- ### Organize Imports by Type Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/import-rules.md Organizes imports in a consistent order: Node.js built-ins, third-party packages, and internal modules. ```javascript // 1. Node.js built-ins import fs from 'node:fs' import path from 'node:path' import { createServer } from 'node:http' // 2. Third-party packages import express from 'express' import { Request, Response } from 'express' import lodash from 'lodash' // 3. Internal modules (relative imports) import { config } from '../config' import { logger } from '../services/logger' import { Helper } from './utils/helper' // Then code export const app = express() ``` -------------------------------- ### Overriding Parser Options Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/default-config.md Demonstrates how to override specific parser options, such as enabling JSX support, while retaining the default settings for other parser options. This is useful for configuring type-aware linting and other language features. ```javascript import love from 'eslint-config-love' export default [ { ...love, languageOptions: { ...love.languageOptions, parserOptions: { ...love.languageOptions.parserOptions, ecmaFeatures: { jsx: true }, }, }, }, ] ``` -------------------------------- ### Override Rules in Configuration Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/configuration.md Spread the default configuration and override specific rules to customize ESLint behavior. ```javascript import love from 'eslint-config-love' export default [ { ...love, // Override specific rules rules: { ...love.rules, 'no-console': 'warn', '@typescript-eslint/explicit-function-return-type': 'off', }, }, ] ``` -------------------------------- ### Consistent Module Export Patterns Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/node-rules.md Shows three common patterns for exporting modules in Node.js: direct assignment of an object, incremental assignment of properties, and exporting a class. Choose one pattern for consistency within a project. ```javascript // Pattern 1: Direct assignment module.exports = { foo: 'bar', baz: () => { /* ... */ } } // Pattern 2: Named exports module.exports.foo = 'bar' module.exports.baz = () => { /* ... */ } // Pattern 3: Class export class MyClass { method() { /* ... */ } } module.exports = MyClass ``` -------------------------------- ### Prefer .catch() for Error Handling Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/promise-rules.md Use the `.catch(handler)` method for handling Promise rejections instead of `.then(null, handler)`. This improves readability and correctly handles synchronous errors within `.then()` callbacks. ```javascript // ✓ Correct: use .catch() promise .then(data => process(data)) .catch(error => console.error(error)) // ✗ Wrong: use .then() for error handling promise .then(data => process(data), error => console.error(error)) // Subtle difference: .catch() is better promise .then(data => { // If this throws synchronously, .catch() will catch it return JSON.parse(data) }) .catch(error => console.error(error)) ``` -------------------------------- ### Accessing and Viewing TypeScript ESLint Rule Configurations Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/api-reference/typescript-eslint-rules.md This snippet demonstrates how to import and access specific TypeScript ESLint rule configurations from the 'eslint-config-love' module. It shows how to retrieve the configuration for '@typescript-eslint/explicit-function-return-type' and '@typescript-eslint/consistent-type-imports'. ```javascript import love from 'eslint-config-love' // View explicit return type rule configuration const explicitReturnType = love.rules['@typescript-eslint/explicit-function-return-type'] // Result: ['error', { allowExpressions: true, ... }] // View consistent type imports rule configuration const consistentTypeImports = love.rules['@typescript-eslint/consistent-type-imports'] // Result: ['error', { prefer: 'type-imports', ... }] ``` -------------------------------- ### CommonJS Dynamic Import Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/configuration.md Use dynamic import to integrate the ES module-based 'eslint-config-love' into a CommonJS project. ```javascript module.exports = (async function config() { const { default: love } = await import('eslint-config-love') return [ { ...love, files: ['**/*.ts'], }, ] })() ``` -------------------------------- ### Enabling Type-Aware Linting Source: https://github.com/mightyiam/eslint-config-love/blob/master/_autodocs/types.md Configures the TypeScript ESLint parser to enable type-aware linting by setting 'projectService' to true. ```typescript parserOptions: { projectService: true // Enable type-aware linting } ```