# Cursor Rules for subconverter-rs
# Code Quality & Maintainability
file_size_limits:
pattern: ".*(\\.(rs|js|ts|tsx))$"
replacement: "// Max file size:
// - Rust: 1000 lines
// - TS/JS: 500 lines
// Split files that exceed these limits into modules"
note: "Maintain manageable file sizes to improve readability and maintainability"
function_size_limits:
pattern: "fn .*\\{[\\s\\S]{200,}\\}"
replacement: "// Functions should be under 50 lines
// Consider breaking large functions into smaller ones"
note: "Keep functions focused and concise for better maintainability"
# API Client Usage
api_client_usage:
pattern: "fetch\\(\\'?\\/api\\/"
replacement: "// Use API client functions from @/lib/api-client instead of direct fetch calls
// Example:
// import { updateRules } from '@/lib/api-client';
// const result = await updateRules();"
note: "Centralize API calls in api-client.ts instead of making direct fetch calls"
# C++ to Rust conversion patterns
cpp_method_to_rust_trait:
pattern: "tribool.*is_undef()"
replacement: "Option<bool>.is_undef()"
note: "Convert C++ tribool methods to Rust trait implementations"
ini_reader_adaptation:
pattern: "erase_section"
replacement: |
pub fn erase_section(&mut self) {
if self.current_section.is_empty() {
return;
}
self.ini.remove_section(&self.current_section);
if let Some(section_map) = self.content.get_mut(&self.current_section) {
section_map.clear();
}
self.ini.set(&self.current_section, "", None);
}
note: "Adapt INIReader methods to work with configparser crate"
noname_placeholder:
pattern: "ini.set(\"{NONAME}\""
replacement: "ini.set(\"{NONAME}\", item_name, item_val)"
note: "Handle {NONAME} placeholder in INI operations"
# Proxy conversion rules
proxy_handler_pattern:
pattern: "handle_(.*)\(node, remark, .*\)"
replacement: "fn handle_$1(node: &Proxy, remark: &str, ...) -> JsonValue"
note: "Implement proxy type handlers similarly across all formats"
yaml_mapping_pattern:
pattern: "YamlValue::Mapping\(.*\)"
replacement: "let mut map = Mapping::new(); map.insert(...); YamlValue::Mapping(map)"
note: "Create YAML mappings for proxy configurations"
# Type conversion
tribool_handling:
pattern: "tribool (.*) = ext\\.(.*)"
replacement: "let mut $1 = ext.$2; $1 = node.$2.define($1);"
note: "Handle tribool value definitions and overrides"
option_to_json:
pattern: "scv.apply_to_json\\(obj, \"skip-cert-verify\"\\)"
replacement: "scv.apply_to_json(obj, \"skip-cert-verify\")"
note: "Apply Option<bool> values to JSON objects conditionally"
# Common Rust patterns
error_handling:
pattern: "ini\\.set.*\\.unwrap_or\\(\\(\\)\\)"
replacement: "ini.set(...).unwrap_or(())"
note: "Handle potential errors in INI operations with unwrap_or(())"
string_manipulations:
pattern: "join\\(&.*\\)"
replacement: "join(&filtered_nodelist, \",\")"
note: "Join string arrays with separators"
yaml_node_operations:
pattern: "yaml_node\\.to_string\\(\\)"
replacement: "match yaml_node.to_string() { Ok(result) => result, Err(_) => String::new() }"
note: "Handle YAML node serialization with proper error handling"
# File structure
module_organization:
pattern: "mod (.*)"
replacement: "pub mod $1"
note: "Organize code into modules with proper visibility"
# JavaScript/TypeScript project configuration
js_ts_project_setup:
pattern: "(package\\.json|next\\.config\\.js|webpack\\.config\\.js)"
replacement: |
// Use yarn for package management
// - Add "packageManager": "yarn@4.x" to package.json
// - Create .npmrc with "engine-strict=true"
// - Use rspack instead of webpack where possible
// For Next.js projects:
// next.config.js
const { withExperimental } = require('@rspack/next-plugin');
module.exports = withExperimental({
// Additional config here
});
// For standard JS/TS projects:
// rspack.config.js
const rspack = require('@rspack/core');
module.exports = {
entry: './src/index.ts',
// Other rspack configuration
};
note: "All JS/TS subprojects should use yarn as package manager and rspack for bundling"
build_script_pattern:
pattern: "\"scripts\": \\{([^}]*)\\}"
replacement: "\"scripts\": {\n \"dev\": \"rspack serve\",\n \"build\": \"rspack build\",\n$1\n }"
note: "Use rspack in build scripts instead of webpack"