|
| 1 | +# general (built-in plugin) |
| 2 | + |
| 3 | +The `general` plugin provides error detection and possible problems rules. These rules catch common programming errors and potential bugs before they cause issues in production. |
| 4 | + |
| 5 | +## Available Rules |
| 6 | + |
| 7 | +All rules can be configured using either the `general/` or `eslint/` prefix (for backward compatibility). |
| 8 | + |
| 9 | +### Error Detection |
| 10 | + |
| 11 | +**Variable & Scope:** |
| 12 | +- `no-const-assign` - Disallow reassigning const variables |
| 13 | +- `no-redeclare` - Disallow variable redeclaration |
| 14 | +- `no-undef` - Disallow undeclared variables |
| 15 | +- `no-unused-vars` - Disallow unused variables ([docs](/rules/no-unused-vars)) |
| 16 | +- `no-shadow` - Disallow variable declarations from shadowing outer scope |
| 17 | +- `no-use-before-define` - Disallow use of variables before they are defined |
| 18 | + |
| 19 | +**Functions & Callbacks:** |
| 20 | +- `array-callback-return` - Enforce return statements in array callbacks |
| 21 | +- `getter-return` - Enforce return statements in getters |
| 22 | +- `constructor-super` - Require super() calls in constructors |
| 23 | +- `no-constructor-return` - Disallow returning value from constructor |
| 24 | + |
| 25 | +**Control Flow:** |
| 26 | +- `for-direction` - Enforce "for" loop update clause moving counter in the right direction |
| 27 | +- `no-fallthrough` - Disallow fallthrough of case statements |
| 28 | +- `no-unreachable` - Disallow unreachable code after return, throw, continue, and break |
| 29 | +- `no-constant-condition` - Disallow constant expressions in conditions |
| 30 | + |
| 31 | +**Objects & Classes:** |
| 32 | +- `no-dupe-keys` - Disallow duplicate keys in object literals |
| 33 | +- `no-dupe-class-members` - Disallow duplicate class members |
| 34 | +- `no-duplicate-case` - Disallow duplicate case labels |
| 35 | + |
| 36 | +**Async & Promises:** |
| 37 | +- `no-async-promise-executor` - Disallow async promise executor |
| 38 | +- `no-promise-executor-return` - Disallow returning values from Promise executor |
| 39 | + |
| 40 | +**Comparisons:** |
| 41 | +- `no-compare-neg-zero` - Disallow comparing against -0 |
| 42 | +- `no-self-assign` - Disallow assignments where both sides are exactly the same |
| 43 | +- `no-self-compare` - Disallow comparisons where both sides are exactly the same |
| 44 | +- `use-isnan` - Require calls to isNaN() when checking for NaN |
| 45 | +- `valid-typeof` - Enforce comparing typeof expressions against valid strings |
| 46 | + |
| 47 | +**Patterns & Syntax:** |
| 48 | +- `no-empty-pattern` - Disallow empty destructuring patterns |
| 49 | +- `no-sparse-arrays` - Disallow sparse arrays |
| 50 | +- `no-irregular-whitespace` - Disallow irregular whitespace |
| 51 | +- `no-loss-of-precision` - Disallow number literals that lose precision |
| 52 | +- `no-unsafe-negation` - Disallow negating the left operand of relational operators |
| 53 | +- `no-useless-catch` - Disallow unnecessary catch clauses |
| 54 | + |
| 55 | +**Modern JavaScript:** |
| 56 | +- `prefer-const` - Require const declarations for variables that are never reassigned ([docs](/rules/prefer-const)) |
| 57 | +- `prefer-object-spread` - Prefer object spread over Object.assign |
| 58 | +- `prefer-template` - Require template literals instead of string concatenation |
| 59 | + |
| 60 | +## Configuration |
| 61 | + |
| 62 | +Configure rules in your `pickier.config.ts`: |
| 63 | + |
| 64 | +```ts |
| 65 | +import type { PickierConfig } from 'pickier' |
| 66 | + |
| 67 | +const config: PickierConfig = { |
| 68 | + pluginRules: { |
| 69 | + // Use general/ prefix (recommended) |
| 70 | + 'general/no-undef': 'error', |
| 71 | + 'general/no-unused-vars': 'error', |
| 72 | + 'general/prefer-const': 'error', |
| 73 | + |
| 74 | + // Or use eslint/ prefix for compatibility |
| 75 | + 'eslint/no-undef': 'error', |
| 76 | + }, |
| 77 | +} |
| 78 | + |
| 79 | +export default config |
| 80 | +``` |
| 81 | + |
| 82 | +## Best Practices |
| 83 | + |
| 84 | +- Keep error detection rules at `'error'` severity to catch bugs early |
| 85 | +- Use `prefer-const` to enforce immutability by default |
| 86 | +- Enable `no-unused-vars` to keep code clean and catch typos |
| 87 | +- Most of these rules don't have auto-fix, so they require manual correction |
| 88 | + |
| 89 | +## See Also |
| 90 | + |
| 91 | +- [Quality Plugin](/rules/quality.md) - Best practices and code quality rules |
| 92 | +- [Rules Index](/rules/index.md) - Complete rule catalog |
| 93 | +- [Plugin System](/advanced/plugin-system.md) - Plugin configuration guide |
0 commit comments