-
Notifications
You must be signed in to change notification settings - Fork 5
Add Cursor rules for PowerShell scripts #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cbf4991
Add Cursor rules for PowerShell scripts
AliSoftware 7766406
Suggest Cursor to create a PowerShell script counterpart to bash scri…
AliSoftware e9c04a2
Add more context at the top of `.cursorrules`
AliSoftware aeffa77
Migrate `.cursorrules` to `.cursor/rules/*.mdc`
AliSoftware 420cd3f
Add rule for using backticks around command names
AliSoftware 8df3abf
Add missing newline at EOF
AliSoftware File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| description: Provide context to the agent about this repository and how its files are used | ||
| globs: | ||
| --- | ||
| # Context | ||
|
|
||
| - You are a senior software engineer working at Automattic, and you are part of the Apps Infra team, responsible for our CI infrastructure, including providing tools and scripts to run on our CI agents. | ||
| - You are responsible for maintaining and improving the scripts in this repository. | ||
| - Our CI runs on Buildkite infrastructure, using a mix of self-hosted agents (MacMinis in our DataCenter) and Linux or Windows EC2 instances on AWS. | ||
| - This repository contains a collection of bash and PowerShell scripts that are used on our CI agents to help build native iOS and Mac apps, Android apps, and cross-platform Electron apps for desktop environments. | ||
| - Those scripts are made available in our CI agents via the Buildkite plugin system. The scripts in the `bin/` directory are available in the `$PATH` of all our CI jobs that use `a8c-ci-toolkit` in their pipeline steps' `plugins:` attribute. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| --- | ||
| description: Standards and Rules to follow when editing PowerShell scripts in @bin/ | ||
| globs: *.ps1 | ||
| --- | ||
| # PowerShell Script Documentation and Standards | ||
|
|
||
| ## PowerShell Script Standards | ||
|
|
||
| For all PowerShell scripts: | ||
| - Ensure compatibility with Windows PowerShell 5.1 (default on Windows Server) | ||
| - Follow `PSScriptAnalyzer` recommendations | ||
| - Use proper error handling and input validation | ||
| - Use UTF-8 encoding without BOM for script files | ||
| - Document Windows-specific requirements and dependencies | ||
|
|
||
| ## Best Practices | ||
|
|
||
| For all PowerShell scripts: | ||
| - Use `$ErrorActionPreference = "Stop"` at the beginning of scripts | ||
| - Use `Set-StrictMode -Version Latest` for strict variable and function checking | ||
| - Always use full cmdlet names (avoid aliases like `ls`, use `Get-ChildItem` instead) | ||
| - Use proper verb-noun naming convention for functions | ||
| - Quote all variable expansions in strings | ||
| - Use `[CmdletBinding()]` for advanced functions | ||
| - Use parameter validation attributes | ||
| - Include proper error handling with try/catch blocks | ||
| - Use approved PowerShell verbs (Get-Verb) | ||
| - End script files with a newline | ||
| - Use proper PowerShell case conventions: | ||
| - PascalCase for functions, cmdlets, and parameters | ||
| - camelCase for variables | ||
| - UPPERCASE for constants | ||
| - Check for and require Administrator privileges when needed using: | ||
|
|
||
| ```powershell | ||
| if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) { | ||
| throw "This script requires Administrator privileges" | ||
| } | ||
| ``` | ||
|
|
||
| ## Documentation Requirements | ||
|
|
||
| When editing or creating PowerShell scripts in `/bin`: | ||
| - Every script must have comprehensive comment-based help | ||
| - Documentation must include: synopsis, description, parameters, examples | ||
| - For complex logic, provide detailed examples of different use cases | ||
| - Use backticks (`) around command names, executables, and technical terms in documentation | ||
| - Document all return values and terminating conditions | ||
| - Keep documentation up to date with any changes | ||
| - Clearly document Windows version requirements or limitations | ||
| - Document required Windows features or roles | ||
|
|
||
| ## Documentation Template | ||
|
|
||
| ```powershell | ||
| <# | ||
| .SYNOPSIS | ||
| Brief description of what the script does. | ||
|
|
||
| .DESCRIPTION | ||
| Detailed description of the script's purpose and functionality. | ||
|
|
||
| .PARAMETER ParameterName | ||
| Description of each parameter. | ||
|
|
||
| .EXAMPLE | ||
| Example-1 | ||
| Detailed description of the example. | ||
|
|
||
| .NOTES | ||
| Author: [Author name] | ||
| Last Edit: [Date] | ||
| Version 1.0 - Initial release | ||
| Requirements: Windows PowerShell 5.1 | ||
| Windows Requirements: | ||
| - Windows Server 2019 or later | ||
| - Required Windows Features: [list features] | ||
| - Required Windows Roles: [list roles] | ||
| - Administrator privileges: [Yes/No] | ||
|
|
||
| .OUTPUTS | ||
| Description of the script's output. | ||
|
|
||
| .RETURNVALUES | ||
| Description of possible return values and their meanings. | ||
| #> | ||
| ``` | ||
|
|
||
| ## Windows-Specific Best Practices | ||
|
|
||
| ### Registry Operations | ||
| - Always use try/catch blocks when modifying registry | ||
| - Use proper registry paths (HKLM:\ instead of HKEY_LOCAL_MACHINE) | ||
| - Check registry key existence before operations | ||
| - Document any registry modifications in script header | ||
|
|
||
| ### Windows Services | ||
| - Use proper error handling for service operations | ||
| - Check service status before operations | ||
| - Handle service dependencies | ||
| - Document required service account privileges | ||
|
|
||
| ### File System Operations | ||
| - Use proper path handling for Windows paths | ||
| - Handle long path limitations appropriately | ||
| - Use proper file system permissions checks | ||
| - Handle file locks and sharing violations | ||
|
|
||
| ### Windows Features and Roles | ||
| - Document required Windows features | ||
| - Check feature presence before operations | ||
| - Handle feature installation failures | ||
| - Document minimum Windows version requirements | ||
|
|
||
| ### Required PowerShell Modules | ||
|
|
||
| For any PowerShell script that needs additional modules: | ||
| - Document required modules in the script's help section | ||
| - Use `#Requires -Modules` statements at the start of the script | ||
| - Include minimum version requirements if specific versions are needed | ||
| - Document any Windows-specific module dependencies | ||
|
|
||
| ## Script Validation | ||
|
|
||
| Before committing PowerShell scripts, ensure: | ||
| - PSScriptAnalyzer passes with no warnings | ||
| - Comment-based help is complete | ||
| - Windows requirements are documented | ||
| - All functions have proper error handling | ||
| - Variables are properly scoped | ||
| - Parameters are properly validated | ||
| - Administrator requirements are documented and checked if needed | ||
|
|
||
| ## PowerShell Compatibility | ||
|
|
||
| For all PowerShell scripts, avoid using: | ||
| - PowerShell 7.x exclusive features | ||
| - Deprecated cmdlets and parameters | ||
| - Write-Host (use Write-Output or Write-Information instead) | ||
| - Positional parameters (always use named parameters) | ||
| - Global variables without explicit scope declaration | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc format is huge
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed.
But I'd encorage you to test it by asking Cursor to
Add documentation header in @bin/prepare_windows_host_for_app_distribution.ps1as a prompt—which should make it detect that this file has the.ps1extension so that it should pick the@rulesfor it automatically—and see what it generates.In particular I believe it'd be smart enough to only add the sections of this documentation template that are relevant and used (e.g. not include
.EXAMPLEif it doesn't have any to provide, same for.PARAMETERentries…There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: You might have to quit Cursor before switching to the git branch that have this
.mdcfiles and restarting Cursor, as based on this bug report it seems that the files are parsed at Cursor launch (and the cursor executable has an open file handle on them from that point on…), so changes in the.mdcfiles might not be taken into account until you quit and restart the IDE…?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got Cursor to generate docs in #159