Coding Convention Application Skill
When writing or modifying code, you must follow the conventions below. For detailed rules for each language, refer to the reference documents in this directory.
Language Detection
Detect the language from the target file extension:
- •
.java→ Apply Java convention (reference: java-coding-convention.md) - •
.ts,.tsx→ Apply TypeScript convention (reference: typescript-coding-convention.md) - •
.tsx,.ts(React Native project) → Additionally apply React Native convention (reference: react-native-coding-convention.md) - •
.py→ Apply Python convention (reference: python-coding-convention.md) - •
.css,.scss,.sass→ Apply CSS/SCSS convention (reference: css-scss-coding-convention.md)
React Native Detection: If the project contains
react-nativeorexpoinpackage.jsondependencies, apply the React Native convention as a complementary layer on top of the TypeScript convention for all.tsx/.tsfiles.
Java Convention Essentials (based on Google Java Style Guide)
- •Encoding: UTF-8
- •Indent: 2 spaces (block), +4 spaces (continuation lines)
- •Line length: 100 characters
- •Braces: K&R style, always use even for single statements
- •Naming:
- •Package:
com.example.deepspace(all lowercase) - •Class:
UpperCamelCase(test classes end withTest) - •Method:
lowerCamelCase(verb/verb phrase) - •Constant:
UPPER_SNAKE_CASE(static final+ deeply immutable) - •Field/parameter/local variable:
lowerCamelCase - •Type variable:
T,E,RequestT
- •Package:
- •Import: No wildcards, separate static/non-static, ASCII sort
- •Javadoc: Required for all
public/protectedmembers. Summary is a noun/verb phrase (not a sentence) - •@Override: Always use when legal
- •Exceptions: Never silently ignore
- •Static members: Access only via class name (
instance.staticMethod()is prohibited) - •finalize(): Do not override
- •Arrays:
String[] args(O),String args[](X) - •long literals: Uppercase
L(100L)
CSS/SCSS Convention Essentials (based on CSS Guidelines + Sass Guidelines)
- •Indent: 2 spaces, no tabs
- •Line length: 80 characters
- •Naming: BEM (
block__element--modifier), lowercase kebab-case - •File naming:
kebab-case, SCSS partials use_prefix - •Selectors:
- •No ID selectors (
#idusage prohibited) - •No type qualification (
div.classprohibited) - •Maximum depth 3 levels (ideally 1~2)
- •No ID selectors (
- •Property order: Group by type (Positioning → Box Model → Typography → Visual → Animation → Misc)
- •Colors: Lowercase hex, shorthand when possible (
#fff), no color keywords - •Units: Font in
rem, line-height as unitless number, no units on 0 - •Value notation: Leading zero required (
0.5),border: 0(notnone) - •SCSS nesting: Maximum 3 levels, nesting recommended only for pseudo-classes/state classes
- •SCSS variables:
$kebab-case, constants$UPPER_SNAKE_CASE, manage related values with Map - •@extend: Avoid usage, use only
%placeholderwhen required - •!important: Only proactive use in utility classes, reactive use prohibited
- •Media queries: Mobile-first (
min-width), write inline with components - •z-index: Centrally managed with Map + getter function, no arbitrary values
- •Animations: Only
transform/opacity, notransition: all,prefers-reduced-motionsupport required - •File structure: 7-1 pattern (abstracts, base, components, layout, pages, themes, vendors)
- •Prohibited patterns: ID selectors,
!importantabuse,transition: all,@extend .class, color keywords, magic numbers, 4+ level nesting
TypeScript Convention Essentials (based on Google TypeScript Style Guide)
- •Semicolons: Always required
- •Formatter: Prettier
- •Naming:
- •Class/interface/type/enum:
UpperCamelCase - •Variable/parameter/function/method:
lowerCamelCase - •Global constants, enum values:
CONSTANT_CASE - •File names:
snake_case - •Type parameter:
TorUpperCamelCase
- •Class/interface/type/enum:
- •Export:
export defaultprohibited, use named exports only - •Import: Use
import type {...},require()prohibited - •Types:
anyprohibited → useunknown. Useinterfacefor objects,type aliasfor union/tuple - •Variables:
constby default,letonly when reassignment is needed.varis strictly prohibited - •Prohibited patterns:
var,const enum,export default,export let,namespace,#ident,.forEach(),.bind()/.call()/.apply(),@ts-ignore,@ts-nocheck - •Control flow:
===/!==required (exception:== null). Usefor...of(for...inprohibited for arrays) - •Error handling:
new Error()required, catch usesunknown, empty catch needs justification
React Native Convention Essentials (based on Airbnb React/JSX + Obytes RN Starter + React Native Official Docs)
Applied as a complementary layer on top of the TypeScript convention when the project is a React Native/Expo project.
- •File naming:
kebab-casefor all files and folders (login-screen.tsx,use-auth-store.ts) - •Screen suffix:
-screen.tsx(e.g.,login-screen.tsx,feed-screen.tsx) - •Hook prefix:
use-file naming (e.g.,use-auth.ts),use+ PascalCase in code (useAuth) - •Components: Functional only (class components prohibited),
PascalCasenaming - •Exports: Named exports only (
export defaultprohibited) - •Props: Always define
typefor props, destructure in parameters,camelCasenaming - •JSX: Self-closing for childless elements, omit
truevalue for boolean props, no nested ternaries - •Styling: Use
StyleSheet.create()or NativeWind. No inline styles. Styles co-located at file bottom - •State: TanStack Query (server state) + Zustand (client state). Separate server/client state
- •Navigation: Expo Router file-based routing.
app/as thin re-export layer, logic infeatures/ - •Structure: Feature-based architecture (
features/→components/→lib/). Co-locate tests - •Hooks: Top-level only, correct dependency arrays, single responsibility per hook
- •Performance:
React.memofor expensive components,useCallbackfor FlatList renderers, stablekeyExtractor, no callbacks in JSX - •Imports: React core → third-party → internal (
@/) → relative → type-only - •Max constraints: 3 function params, 110 lines per function
- •Accessibility:
accessibilityLabel+accessibilityRoleon interactive elements, minimum 44×44 touch target - •Prohibited: Class components,
export default, inline styles, array index as key, nested ternaries,anyfor props,console.login production,Dimensions.get()in render
Python Convention Essentials (based on PEP 8)
- •Indent: 4 spaces, no tabs
- •Line length: 79 characters (comments/docstrings 72 characters)
- •Naming:
- •Package:
mypackage(short lowercase) - •Module:
my_module(lowercase_underscore) - •Class:
CapWords(CamelCase) - •Exception:
CapWords+Errorsuffix - •Function/method:
lowercase_with_underscores - •Constant:
UPPER_CASE_WITH_UNDERSCORES - •Instance method first argument:
self, class method:cls
- •Package:
- •Import order: Standard library → Third-party → Local (blank line between groups)
- •No wildcard imports: Avoid
from module import * - •Comparison:
is None/is not None(== Noneprohibited), useisinstance()(type()prohibited) - •Empty sequences:
if not seq:(use falsy),if len(seq):prohibited - •Docstrings:
"""triple double quotes""", imperative mood ("Return X"), all public members - •Lambda assignment prohibited:
f = lambda x: 2*xprohibited →def f(x): return 2*x - •Resource management: Use
withstatement - •Blank lines: 2 blank lines before/after top-level definitions, 1 blank line before/after methods within a class