पाठ 23 / 27

Best Practices और Anti-patterns

ESLint और Prettier best practices अपनाएँ: shared configs extend करें, धीरे-धीरे अपनाएँ और CI checks कभी न छोड़ें।

मुख्य सिद्धांत

DO: shared configs extend करें, अपनाते समय error से पहले warn चुनें, configs git में commit करें। DON'T: core rules बंद न करें, formatter conflicts अनदेखा न करें, CI checks न छोड़ें।

अच्छे vs बुरे patterns

Good और bad ESLint configuration patterns की तुलना करें।

// GOOD: shared config, specific overrides, gradual severity
export default [
  js.configs.recommended,
  prettier,
  { files: ['**/*.test.js'], rules: { 'no-console': 'off' } },
  { rules: { 'no-console': 'warn' } },
];

// BAD: switch off core rules wholesale
export default [{ rules: { 'no-unused-vars': 'off', 'no-undef': 'off' } }];

// BAD: strict errors on day one
export default [{ rules: { 'no-console': 'error' } }];

Output:

Good patterns use extends, overrides, and warn initially

समय के साथ विकास

Loose (warn, कुछ rules) से शुरू करें और समय के साथ tighten करें (error, अधिक rules) जैसे टीम adapts। यह friction को कम करता है और adoption को improve करता है।

त्वरित जाँच

त्वरित जाँच: टीम adoption के लिए एक best practice क्या है?

  • सभी rules को immediately errors के रूप में लागू करें।
  • अधिकांश rules को disable करें।
  • Warn के साथ शुरू करें, जैसे टीम adapts तो gradually error में move करें।
  • CI checks छोड़ दें
Answer

Warn के साथ शुरू करें, जैसे टीम adapts तो gradually error में move करें। — Gradual enforcement प्रतिरोध को कम करता है और टीम को progressively अपने workflow को adjust करने देता है।