Skip to content

Commit 18573e1

Browse files
committed
Add import organization rules for JavaScript/TypeScript
- Create markdown rules for import grouping and spacing - Define clear import order guidelines for React/TS projects - Provide comprehensive examples of import organization - Ensure compliance with eslint import/order rules
1 parent dc3f6f7 commit 18573e1

File tree

3 files changed

+108
-12
lines changed

3 files changed

+108
-12
lines changed
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
description: PowerShell 7 Command Generation (Not Bash)
3-
globs: ["*.ps1", "*.psm1", "*.psd1", "*.md", "*.txt"]
3+
globs: "*.ps1", "*.psm1", "*.psd1", "*.md", "*.txt"
44
alwaysApply: true
55
---
6+
Generate PowerShell 7 commands for Windows 11, not Bash syntax:
67

7-
When generating console commands, use PowerShell 7 syntax for Windows 11, NOT bash syntax. Remember these key differences:
8+
- PowerShell cmdlets: Get-ChildItem (not ls), Set-Location (not cd)
9+
- Paths use backslashes (C:\Users\)
10+
- Flags use single hyphen (-Force)
11+
- Variables: $variable, string interpolation: "$()"
12+
- Environment variables: $env:VARIABLE
13+
- Piping: | (with proper object handling)
14+
- Command separation: ; (not &&)
15+
- Redirection: >, >>, 2>
816

9-
- Use PowerShell cmdlets like Get-ChildItem (not ls), Set-Location (not cd), etc.
10-
- Use backslashes for paths (C:\Users\) not forward slashes
11-
- Command flags use hyphen prefix (-Force) not double-hyphen (--force)
12-
- Variables use $ prefix ($variable) and string interpolation uses "$()"
13-
- Environment variables use $env:VARIABLE format
14-
- Piping uses | operator but cmdlets expect specific object input
15-
- Command concatenation uses ; or separate lines, not &&
16-
- Redirection uses >, >>, 2> (not 2>&1)
17-
18-
Always prefer PowerShell-native approaches over legacy cmd.exe commands.
17+
Prefer PowerShell-native approaches over cmd.exe commands.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
description: Empty Lines Between Import Groups
3+
globs: "**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"
4+
alwaysApply: true
5+
---
6+
When organizing imports in JavaScript/TypeScript files, maintain at least one empty line between different import groups to follow the eslint import/order rule.
7+
8+
Import groups are typically arranged in this order:
9+
1. Built-in Node.js modules
10+
2. External npm packages/modules
11+
3. Internal project imports (components, utils, etc.)
12+
4. Stylesheet imports (CSS, SCSS, etc.)
13+
5. Asset imports (images, fonts, etc.)
14+
15+
Example of proper import grouping:
16+
17+
```javascript
18+
// Built-in modules
19+
import path from 'path';
20+
import fs from 'fs';
21+
22+
// External packages
23+
import React, { useState } from 'react';
24+
import classnames from 'classnames';
25+
26+
// Internal project imports
27+
import Button from '../components/Button';
28+
import { formatDate } from '../utils/date';
29+
30+
// Stylesheets
31+
import '../styles/components/app.scss';
32+
33+
// Assets
34+
import logo from '../assets/logo.svg';
35+
```
36+
37+
This pattern:
38+
- Improves code readability
39+
- Makes import sections visually distinct
40+
- Complies with eslint import/order rule
41+
- Helps maintain consistent code organization
42+
43+
Benefits: Improves readability, makes code organization consistent, and satisfies linting requirements.
44+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
---
7+
description: Import Order Requirements for React Components
8+
globs: "**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"
9+
alwaysApply: true
10+
---
11+
# Import Ordering Rules
12+
13+
For proper linting compliance, imports must follow this specific ordering pattern:
14+
15+
## Order by Import Group
16+
1. External/npm modules (React, react-router-dom, etc.)
17+
2. Blank line
18+
3. Internal project modules (components, utilities)
19+
4. Stylesheets (CSS, SCSS)
20+
5. Component imports in alphabetical order
21+
6. Image/asset imports according to specific pattern
22+
23+
## Image/Asset Import Order
24+
For image imports with different sizes and formats:
25+
26+
1. Group by size first (large, medium, small)
27+
2. For each size group, order by format (.jpg first, then .webp)
28+
29+
### Example
30+
```javascript
31+
// External packages
32+
import React from 'react';
33+
import { Link } from 'react-router-dom';
34+
35+
// Internal components/utilities
36+
import PageTitle from './page-title';
37+
import '../styles/components/welcome.scss';
38+
import ImageWithContent from '../components/ImageWithContent';
39+
import LinkWithDescription from '../components/LinkWithDescription';
40+
41+
// Images - ordered by size first, then format
42+
import portraitImageLarge from '../images/portrait-large.jpg';
43+
import portraitImageLargeWebp from '../images/portrait-large.webp';
44+
import portraitImageMedium from '../images/portrait-medium.jpg';
45+
import portraitImageMediumWebp from '../images/portrait-medium.webp';
46+
import portraitImageSmall from '../images/portrait-small.jpg';
47+
import portraitImageSmallWebp from '../images/portrait-small.webp';
48+
```
49+
50+
This pattern satisfies ESLint import/order rules and maintains consistent code organization.
51+
```
52+
53+
</rewritten_file>

0 commit comments

Comments
 (0)