Skip to content

A powerful CLI tool that automatically fixes common ESLint issues in React projects. Say goodbye to unused imports, unused variables, and other linting headaches!

License

Notifications You must be signed in to change notification settings

sh20raj-dump/react-suitable

Repository files navigation

Suitable ๐Ÿ”ง

A powerful CLI tool that automatically fixes common ESLint issues in React projects. Say goodbye to unused imports, unused variables, and other linting headaches!

Visitors npm version Downloads GitHub stars License: MIT

โœจ Features

  • ๐Ÿงน Auto-fix unused imports - Removes all unused import statements
  • ๐Ÿ—‘๏ธ Remove unused variables - Eliminates unused variables and parameters
  • โš›๏ธ React-optimized - Built specifically for React, Next.js, and TypeScript projects
  • ๐ŸŽฏ Smart detection - Automatically detects your project type and applies appropriate rules
  • ๐Ÿ”„ Interactive mode - Menu-driven approach for customized fixing
  • ๐Ÿƒโ€โ™‚๏ธ Fast & efficient - Processes large codebases quickly
  • ๐Ÿ“Š Detailed reporting - Shows exactly what was fixed
  • ๐Ÿ”ง Configurable - Use your existing ESLint config or our optimized defaults

๐Ÿš€ Quick Start

Installation

# Install globally
npm install -g suitable

# Or run with npx (no installation needed)
npx suitable

Basic Usage

# Fix issues in current directory
suitable

# Fix issues in specific directory
suitable ./src

# Interactive mode with menu
suitable --interactive

# Dry run (see what would be fixed without changing files)
suitable --dry-run

# Use custom ESLint config
suitable --config ./my-eslint-config.js

Quick Demo

Test it on any React project:

# Navigate to your React project
cd my-react-app

# See what issues can be fixed (dry run)
npx suitable --dry-run

# Fix all auto-fixable issues
npx suitable

# Use interactive mode for customization
npx suitable --interactive

๐Ÿ“‹ Command Line Options

Option Description Default
--interactive, -i Run in interactive mode with menu false
--dry-run Show what would be fixed without making changes false
--config <path> Path to custom ESLint configuration file Auto-detect
--include <patterns> File patterns to include (comma-separated) **/*.{js,jsx,ts,tsx}
--exclude <patterns> File patterns to exclude (comma-separated) node_modules/**,build/**,dist/**
--fix, -f Automatically fix issues true

๐ŸŽฎ Interactive Mode

Launch interactive mode for a guided experience:

suitable --interactive

The interactive mode will:

  1. Detect your project type (React, Next.js, TypeScript)
  2. Configure ESLint rules based on your project
  3. Select file patterns to process
  4. Choose fix options (auto-fix, dry-run, focus areas)
  5. Show summary and ask for confirmation
  6. Execute the fixes with your chosen configuration

๐Ÿ”ง What Gets Fixed

Unused Imports

// Before
import React from "react";
import { useState, useEffect } from "react";
import axios from "axios";
import _ from "lodash";

function MyComponent() {
  const [count, setCount] = useState(0);
  return <div>{count}</div>;
}

// After
import { useState } from "react";

function MyComponent() {
  const [count, setCount] = useState(0);
  return <div>{count}</div>;
}

Unused Variables

// Before
function processData(items, config, options) {
  const result = [];
  const temp = "unused";

  items.forEach((item) => {
    result.push(item.name);
  });

  return result;
}

// After
function processData(items) {
  const result = [];

  items.forEach((item) => {
    result.push(item.name);
  });

  return result;
}

Code Formatting

  • Removes trailing spaces
  • Fixes indentation
  • Adds missing semicolons
  • Standardizes quotes
  • Fixes object/array spacing

React-Specific Issues

  • Removes unused React imports (React 17+)
  • Fixes React Hooks rules violations
  • Optimizes JSX prop usage
  • Removes unused component props

๐Ÿ› ๏ธ Configuration

Default Configuration

Suitable comes with sensible defaults optimized for React projects:

{
  // Focus on unused code removal
  'unused-imports/no-unused-imports': 'error',
  'unused-imports/no-unused-vars': 'error',

  // React optimizations
  'react/react-in-jsx-scope': 'off', // React 17+
  'react-hooks/rules-of-hooks': 'error',
  'react-hooks/exhaustive-deps': 'warn',

  // Auto-fixable formatting
  'no-trailing-spaces': 'error',
  'semi': 'error',
  'quotes': ['error', 'single'],
  // ... and more
}

Custom Configuration

Use your existing ESLint config:

suitable --config ./.eslintrc.js

Or create a project-specific config that extends Suitable's defaults:

// .eslintrc.js
module.exports = {
  extends: ["suitable/react"], // Use Suitable's React preset
  rules: {
    // Your custom rules
    "no-console": "warn",
  },
};

๐Ÿ—๏ธ Project Structure Support

Suitable works with various project structures:

your-react-project/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ hooks/
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ””โ”€โ”€ pages/
โ”œโ”€โ”€ public/
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ .eslintrc.js (created if not exists)

๐Ÿ”ง IDE Integration

VS Code Extension

Get the official Suitable VS Code extension for seamless integration:

# Navigate to extension directory
cd react-suitable-vscode

# Install dependencies and compile
npm install && npm run compile

# Development mode (opens Extension Development Host)
# Press F5 in VS Code or use "Run > Start Debugging"

Extension Features:

  • Fix Current File: Ctrl+Shift+Alt+F (Mac: Cmd+Shift+Alt+F)
  • Fix Workspace: Ctrl+Shift+Alt+W (Mac: Cmd+Shift+Alt+W)
  • Interactive Mode: Guided configuration and execution
  • Dry Run: Preview changes before applying
  • Auto-fix on Save: Optional automatic fixing when saving files
  • Context Menu Integration: Right-click options for supported files
  • Output Panel: Detailed logging in "Suitable" output channel

Configure via VS Code Settings:

{
  "suitable.autoFixOnSave": false,
  "suitable.enableNotifications": true,
  "suitable.includePatterns": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"],
  "suitable.excludePatterns": ["node_modules/**", "build/**", "dist/**"]
}

Fix a Create React App project

cd my-cra-app
suitable

Fix a Next.js project with TypeScript

cd my-nextjs-app
suitable --interactive  # Will detect Next.js and suggest appropriate config

Fix specific directories only

suitable --include "src/**/*.{ts,tsx}" --exclude "src/**/*.test.ts"

See what would be fixed without making changes

suitable --dry-run

๐Ÿ“Š Output Example

๐Ÿ”ง Suitable - React ESLint Auto-fixer
Fixing common linting issues in your React project...

โœ“ ESLint configuration ready
โœ“ Processing complete: 47 issues fixed in 23 files

# โœจ Summary

Files processed: 23
Issues fixed: 47
Unused imports removed: 18
Unused variables removed: 12

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

๐Ÿ“ License

MIT License - see LICENSE for details.

๐Ÿ™‹โ€โ™€๏ธ Support

๐ŸŽฏ Roadmap

  • VS Code extension - Official VS Code extension for seamless editor integration
  • Git hook integration
  • CI/CD pipeline integration
  • More framework support (Vue, Angular)
  • Custom rule templates
  • Performance optimizations for large codebases

Made with โค๏ธ for the React community

About

A powerful CLI tool that automatically fixes common ESLint issues in React projects. Say goodbye to unused imports, unused variables, and other linting headaches!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published