# DSS Coding Standards Migration Guide
This guide shows how to migrate existing code to DSS coding standards defined in `.knowledge/dss-coding-standards.json`.
## Table of Contents
- [Shadow DOM Migration](#shadow-dom-migration)
- [Inline Event Handler Removal](#inline-event-handler-removal)
- [Inline Style Extraction](#inline-style-extraction)
- [Semantic HTML](#semantic-html)
- [Accessibility Improvements](#accessibility-improvements)
- [Logger Migration](#logger-migration)
- [State Management](#state-management)
---
## Shadow DOM Migration
### ❌ Before (No Shadow DOM)
```javascript
export default class MyComponent extends HTMLElement {
connectedCallback() {
this.innerHTML = `
`;
}
}
```
### ✅ After (With Shadow DOM)
```javascript
export default class MyComponent extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' }); // ✓ Enable Shadow DOM
}
connectedCallback() {
this.render();
}
render() {
this.shadowRoot.innerHTML = `
`;
}
}
```
**Key Changes:**
- ✓ Add `attachShadow()` in constructor
- ✓ Change `this.innerHTML` to `this.shadowRoot.innerHTML`
- ✓ Extract styles to `
`;
}
setupEventListeners() {
// ✓ Event delegation with AbortController for cleanup
this.abortController = new AbortController();
this.shadowRoot.addEventListener('click', (e) => {
const action = e.target.closest('[data-action]')?.dataset.action;
if (action === 'cardClick') {
this.handleCardClick(e);
} else if (action === 'buttonClick') {
this.handleButtonClick(e);
}
}, { signal: this.abortController.signal });
}
handleCardClick(e) {
console.log('Card clicked');
}
handleButtonClick(e) {
e.stopPropagation();
this.dispatchEvent(new CustomEvent('button-clicked', {
bubbles: true,
composed: true
}));
}
```
**Key Changes:**
- ✓ Remove ALL `onclick`, `onmouseover`, `onmouseout` attributes
- ✓ Use CSS `:hover` for hover effects
- ✓ Event delegation with `data-action` attributes
- ✓ Single event listener using `closest('[data-action]')`
- ✓ AbortController for automatic cleanup
- ✓ Custom events for component communication
---
## Inline Style Extraction
### ❌ Before (Inline Styles Everywhere)
```javascript
render() {
this.innerHTML = `
${this.title}
`;
}
```
### ✅ After (Styles in Shadow DOM)
```javascript
render() {
this.shadowRoot.innerHTML = `
${this.title}
`;
}
```
**Key Changes:**
- ✓ ALL styles moved to `
`;
}
```
**Key Changes:**
- ✓ Use `