### Install eslint-plugin-sweepit and ESLint Source: https://github.com/jjenzz/sweepi/blob/main/packages/eslint-plugin-sweepit/README.md Installs the necessary packages for using eslint-plugin-sweepit and ESLint as development dependencies. ```bash npm install --save-dev eslint-plugin-sweepit eslint ``` -------------------------------- ### Refactoring Example: Before and After Source: https://github.com/jjenzz/sweepi/blob/main/packages/eslint-plugin-sweepit/docs/rules/jsx-flat-owner-tree.md This TypeScript/JSX code provides a side-by-side comparison of a component structure before and after applying the `jsx-flat-owner-tree` rule's principles. The 'before' example shows a deep, problematic chain, while the 'after' example demonstrates the refactored, flatter structure using compound components. ```tsx // before function Root() { return ; } function Page() { return (
); } function Header() { return (
); } // after function Root() { return (
); } ``` -------------------------------- ### Initialize Sweepi Toolchain CLI Source: https://context7.com/jjenzz/sweepi/llms.txt Initializes the Sweepi toolchain in `~/.sweepi` by creating the directory, writing ESLint configuration, and installing necessary dependencies. The `--force` option can be used to reset an existing installation. ```bash sweepi init sweepi init --force ``` -------------------------------- ### Install Sweepi Globally Source: https://github.com/jjenzz/sweepi/blob/main/README.md Install the Sweepi package globally using npm. This is recommended for users who plan to perform audits frequently, as it offers faster execution compared to using npx for each run. ```bash npm install --global sweepi ``` -------------------------------- ### Basic ESLint Flat Config Setup Source: https://context7.com/jjenzz/sweepi/llms.txt Configures ESLint using the flat config system by importing and spreading the pre-configured rule sets from the `eslint-plugin-sweepit` package. This setup enables both core and React-specific Sweepi rules. ```javascript import sweepit from 'eslint-plugin-sweepit'; export default [ ...sweepit.configs.core, ...sweepit.configs.react ]; ``` -------------------------------- ### Example Core ESLint Config Contents Source: https://context7.com/jjenzz/sweepi/llms.txt Illustrates the types of rules included in the `sweepit.configs.core` configuration, focusing on TypeScript, functional programming, and general code quality checks. The example code demonstrates how these rules might flag issues like mutable data or uninitialized variables. ```javascript // What configs.core includes: // - sonarjs.configs.recommended from eslint-plugin-sonarjs // - functional/immutable-data with ignoreAccessorPattern: ['*.displayName', '*.current'] // - no-param-reassign with { props: true } // - prefer-const // - @typescript-eslint/switch-exhaustiveness-check // - complexity with { max: 5, variant: 'modified' } // Example: core config detects these issues function process(data) { let result = []; // error: prefer-const data.items = []; // error: functional/immutable-data data = null; // error: no-param-reassign return result; } ``` -------------------------------- ### Initialize Sweepi (Bash) Source: https://github.com/jjenzz/sweepi/blob/main/packages/sweepi/README.md Initializes Sweepi by creating the ~/.sweepi directory, writing the default ESLint configuration, and installing necessary dependencies like eslint and eslint-plugin-sweepit. It also adds the Sweepi skill. ```bash npx sweepi init ``` -------------------------------- ### Initialize Sweepi Toolchain (TypeScript) Source: https://context7.com/jjenzz/sweepi/llms.txt Initializes the Sweepi toolchain programmatically. Allows customization of the home directory, forces a reset of the installation, and provides a status callback for progress updates. Returns the toolchain directory and installation status. ```typescript import { initializeToolchain } from 'sweepi'; const result = await initializeToolchain({ homeDirectory: '/custom/home', // optional, defaults to os.homedir() forceReset: false, // optional, removes existing installation onStatus: (message) => { // optional, status callback console.log(message); }, }); console.log(result.toolchainDirectory); // ~/.sweepi console.log(result.installedDependencies); // true if fresh install ``` -------------------------------- ### Correct JSX handler prop naming examples Source: https://github.com/jjenzz/sweepi/blob/main/packages/eslint-plugin-sweepit/docs/rules/jsx-on-handler-verb-suffix.md These examples illustrate correct usage of the 'jsx-on-handler-verb-suffix' rule. They show handler props that adhere to the convention of ending with a verb, such as 'onValueChange' or 'onClick'. This includes standard HTML event handlers and custom ones following the pattern. ```tsx