303-javascript-guide

A JavaScript coding guide covering naming, formatting, quotation marks, modern variable declarations, and other coding practices. JavaScript is a programming language commonly used for web applications.

In plain words
What is it for?
Use it when writing or checking JavaScript, including variable names, functions, components, booleans, arrays, indentation, semicolons, and const or let usage.
Why use it?
It gives developers shared rules that make JavaScript code easier to read, maintain, and review.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/haidong-once/cursor-rules-collection/303-javascript-guide
Clone the repo
git clone --depth 1 https://github.com/HaiDong-Once/cursor-rules-collection
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 3,171 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.03171
Opus 5 $0.00000 $0.01586
Sonnet 5 $0.00000 $0.00634
Haiku 4.5 $0.00000 $0.00317

Measured 2d ago against content hash edabfcbaf22d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

303-javascript-guide scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

frontend/303-javascript-guide.mdc · 529 lines

How it starts

The opening of the file, as written. The whole thing — 529 lines — stays where its author put it; the contents beside it link to each section on GitHub.

JavaScript编码指南 (303)

规则概述

本规范定义了JavaScript的编码规范和最佳实践,旨在提高代码质量、可读性和可维护性。

基本规范

1.1 命名规范

  • 变量命名:使用驼峰命名法(camelCase)
  • 常量命名:使用全大写下划线分隔(UPPER_SNAKE_CASE)
  • 函数命名:使用动词短语,驼峰命名法(如:getUserInfo
  • 组件命名:使用大驼峰命名法(PascalCase)
  • 布尔值:以 ishascanshould 开头
  • 数组命名:使用复数形式,如 usersuserList
// 变量命名
let userName = 'Zhang San';
const MAX_COUNT = 100;

// 函数命名
function getUserProfile() { /*...*/ }

// 组件命名
class UserProfile extends Component { /*...*/ }

// 布尔值
const isActive = true;
const hasPermission = false;

// 数组
const userList = [];
const products = [];

1.2 代码格式

  • 使用2个空格缩进
  • 语句末尾使用分号
  • 花括号起始位置与声明在同一行
  • 单行代码长度不超过80-100个字符
  • 使用空行分离代码逻辑块
// 推荐
function calculateTotal(items) {
  let total = 0;
  
  for (let i = 0; i < items.length; i++) {
    total += items[i].price;
  }
  
  return total;
}

1.3 引号使用

  • 统一使用单引号(')而非双引号("
  • 模板字符串使用反引号(`
// 推荐
const name = 'John Doe';
const greeting = `Hello, ${name}!`;

// 不推荐
const name = "John Doe";

ES6+特性使用

2.1 变量声明

  • 使用 constlet 代替 var
  • 默认使用 const,只有在需要重新赋值时使用 let
  • 避免使用 var(存在变量提升和作用域问题)
// 推荐
const PI = 3.14;
let count = 0;
count++;

// 不推荐
var PI = 3.14;
var count = 0;

2.2 箭头函数

  • 优先使用箭头函数,特别是在回调函数中
  • 简单的单行表达式无需花括号和return语句
  • 多行表达式使用花括号和return语句
// 单行箭头函数
const double = x => x * 2;

// 多行箭头函数
const calculateArea = (width, height) => {
  const area = width * height;
  return area;
};

// 回调函数
items.map(item => item.value);

2.3 解构赋值

  • 使用对象解构获取对象属性
  • 函数参数过多时使用对象参数,解构获取
// 对象解构
const { name, age, address } = user;

// 函数参数解构
function getUserInfo({ name, age, address }) {
  // 使用 name, age, address
}

getUserInfo({
  name: '张三',
  age: 30,
  address: '北京'
});

2.4 展开运算符

  • 使用展开运算符(...)合并对象和数组
// 合并数组
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const combined = [...arr1, ...arr2];

// 合并对象
const defaults = { theme: 'light', language: 'en' };
const userSettings = { theme: 'dark' };
const settings = { ...defaults, ...userSettings };

Read the full file on GitHub · 529 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 529 lines · 0 tokens per session scan A edabfcbaf22d

Subscribe to this mod's changes

303-javascript-guide is a cursor rule published in the GitHub repository HaiDong-Once/cursor-rules-collection (24 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 3,171 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.