Skip to content

Commit dbd6c36

Browse files
authored
Revise Copilot instructions for PR checks
Refactor Copilot instructions to focus on automated checks for PR reviews, removing outdated project overview and certification goals.
1 parent 7014f50 commit dbd6c36

File tree

1 file changed

+155
-201
lines changed

1 file changed

+155
-201
lines changed

.github/copilot-instructions.md

Lines changed: 155 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -1,203 +1,157 @@
1-
# GitHub Copilot Instructions for Certified Power BI Custom Visual
2-
3-
## Project Overview
4-
This repository contains a Power BI custom visual that aims to achieve Microsoft certification. Certified Power BI visuals must meet strict code requirements and security standards set by the Microsoft Power BI team.
5-
6-
## Certification Goals
7-
- Meet all Microsoft certification requirements for Power BI custom visuals
8-
- Pass code reviews, static code analysis, and security testing
9-
- Maintain compatibility with PowerPoint export and email subscriptions
10-
- Ensure safe DOM manipulation and secure coding practices
11-
- Support the latest Power BI SDK and rendering events API
12-
13-
## Technology Stack
14-
- **TypeScript**: Primary development language (strongly typed, object-oriented)
15-
- **D3.js**: Core library for data visualization and DOM manipulation
16-
- **Power BI Visuals SDK**: Latest version of powerbi-visuals-tools
17-
- **Node.js**: Development environment and build tools
18-
- **npm**: Package management
19-
20-
## Required Files and Structure
21-
The repository must contain these essential files:
22-
- `capabilities.json` - Visual configuration and data mappings
23-
- `pbiviz.json` - Visual metadata and build configuration
24-
- `package.json` - Dependencies and build scripts
25-
- `package-lock.json` - Dependency lock file
26-
- `tsconfig.json` - TypeScript compiler configuration
27-
- `.gitignore` - Must exclude node_modules, .tmp, and dist folders
28-
- `src/visual.ts` - Main visual implementation file
29-
30-
## Coding Standards and Conventions
31-
32-
### TypeScript Best Practices
33-
- Use strict TypeScript configuration with type safety enabled
34-
- Prefer strongly typed interfaces and classes over any types
35-
- Use arrow functions for callbacks and event handlers
36-
- Implement proper error handling for all operations
37-
- Follow object-oriented programming principles
38-
39-
### Naming Conventions
40-
- Use PascalCase for classes and interfaces
41-
- Use camelCase for variables, methods, and properties
42-
- Use UPPER_CASE for constants
43-
- Use descriptive names that clearly indicate purpose
44-
45-
### Code Organization
46-
- Separate concerns into logical modules and classes
47-
- Keep the main visual class focused on visualization logic
48-
- Extract utility functions into separate modules
49-
- Maintain clean separation between data processing and rendering
50-
51-
## Certification Requirements - CRITICAL SECURITY RULES
52-
53-
### STRICTLY FORBIDDEN - These will cause certification failure:
54-
- **NO external network requests**: Never use `fetch()`, `XMLHttpRequest`, or WebSocket connections
55-
- **NO dynamic code execution**: Never use `eval()`, `Function()` constructor, or similar methods
56-
- **NO unsafe DOM manipulation**: Never use `innerHTML` with user data or `D3.html()` with user input
57-
- **NO arbitrary timeouts**: Avoid unsafe use of `setTimeout()`, `setInterval()` with user-provided functions
58-
- **NO minified code**: All JavaScript/TypeScript must be readable and reviewable
59-
- **NO private/commercial libraries**: Only use public, reviewable open-source components
60-
- **NO external service access**: WebAccess privileges must be empty or omitted in capabilities.json
61-
62-
### Required Security Practices:
63-
- **Sanitize all user input** before adding to DOM
64-
- **Use safe DOM methods** like `textContent`, `setAttribute`, or D3's safe methods
65-
- **Implement proper error handling** to prevent JavaScript exceptions
66-
- **Support Rendering Events API** for proper lifecycle management
67-
- **Validate all data inputs** before processing
68-
69-
## Package Management Requirements
70-
71-
### Required Dependencies in package.json:
72-
```json
73-
{
74-
"devDependencies": {
75-
"typescript": "latest",
76-
"eslint": "latest",
77-
"eslint-plugin-powerbi-visuals": "latest"
78-
},
79-
"scripts": {
80-
"eslint": "npx eslint . --ext .js,.jsx,.ts,.tsx",
81-
"package": "pbiviz package"
82-
}
83-
}
1+
# Agent-oriented Copilot instructions for PR checks
2+
3+
**Purpose.** Keep only the checks and guidance that an automated coding agent (Copilot-style) can perform reliably during a PR review for a Power BI custom visual repository. Interactive/manual steps live in `HUMAN-certification-checklist.md`.
4+
5+
**Context.** This repository contains a Microsoft custom visual for Power BI. All contributions must follow Microsoft coding standards and Power BI custom visual guidelines. The agent prioritizes checks that enforce those standards and flags deviations for human review.
6+
7+
---
8+
9+
## Summary of agent-capable checks (categories)
10+
11+
- **PR metadata**: non-empty description; conventional commit title.
12+
- **Manifests & capabilities (Power BI)**: presence & schema sanity of `capabilities.json`, `pbiviz.json`, `package.json`, `tsconfig.json`, `src/visual.ts`; no `WebAccess`; version bump rules.
13+
- **Security & forbidden patterns**: unsafe DOM, dynamic scripts, timers-with-strings, `eval/new Function`, network APIs, unsafe bindings.
14+
- **Secrets scanning**: common tokens/keys; urgent human review.
15+
- **Build artifacts & minification & assets**: `.min.*` in `src/`, overly large or minified-looking files.
16+
- **Linting, tests, CI**: scripts present; ESLint config; CI status present if `src/**` changed.
17+
- **Dependencies**: lockfile updated on dependency change; major version bumps flagged.
18+
- **Tests & localization**: unit tests reminder on logic changes; `stringResources/en-US/**` coverage; spellcheck.
19+
- **Documentation & changelog**: `changelog.md` on non-trivial changes; usage examples for public APIs.
20+
- **Code quality & architecture**: scope summary, performance & accessibility hints, state/event cleanup, error handling, maintainability notes.
21+
- **Reporting**: one-line summary counts; per-finding snippets; suggested fixes; auto-labels.
22+
23+
> Maintainers: thresholds, regexes and message templates are the **single source of truth** in this file to avoid divergence.
24+
25+
---
26+
27+
## Detailed rules
28+
29+
### 1) Manifests & capabilities (Power BI)
30+
- **Presence**: `capabilities.json`, `pbiviz.json`, `package.json`, `tsconfig.json`, `src/visual.ts`.
31+
Missing → `error`.
32+
- **Capabilities**:
33+
- No `WebAccess` or privileges that permit arbitrary network calls → `error`.
34+
- `dataRoles` and `dataViewMappings` must be present → `error`.
35+
- **`pbiviz.json`**:
36+
- `visual.version` must bump for functional changes (semver).
37+
- `visual.guid`, `visual.displayName`, `author`, `supportUrl`, `apiVersion` present.
38+
- `apiVersion` compatible with `@types/powerbi-visuals-api` (major alignment) → mismatch → `warning`.
39+
40+
### 2) Security & forbidden patterns (report file:line)
41+
- Unsafe DOM:
42+
- `innerHTML\s*=``error` with safe alternative.
43+
- `.html\(` (D3 selections) → `error` when D3 imported; otherwise `warning`.
44+
- Dynamic scripts / code eval:
45+
- `createElement\(['"]script['"]\)` / `appendChild` of scripts → `error`.
46+
- `eval\(` or `new Function\(``error`.
47+
- String-based timers:
48+
`set(?:Timeout|Interval)\(\s*(['"]).*?\1``error`.
49+
- Network / runtime:
50+
- `fetch\(`, `XMLHttpRequest`, `WebSocket``error` (Power BI certified visuals constraint).
51+
- Prefer safe APIs:
52+
- `textContent`, `setAttribute` over `innerHTML`. Provide auto-fix snippet if RHS is a simple string literal.
53+
54+
### 3) Secrets & credentials
55+
- Run regex scans on changed text files (exclude binaries and lock files).
56+
- Examples (non-exhaustive):
57+
- `AKIA[0-9A-Z]{16}` (AWS)
58+
- `ghp_[A-Za-z0-9]{36,}` (GitHub)
59+
- `xox[baprs]-[A-Za-z0-9-]{10,48}` (Slack)
60+
- `eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}` (JWT)
61+
- `(AccountKey|SharedAccessKey|SAS|Sig|se=|sp=|sr=|spr=|sv=|st=|sk=|connection\s*string)\s*=\s*[^;'\n]+` (Azure)
62+
- `npm_[A-Za-z0-9]{36,}` (NPM)
63+
- `-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----`
64+
- Any hit → `error` + urgent human review. **Do not auto-edit.**
65+
66+
### 4) Build artifacts, minification & large assets
67+
- `error`: any `\.min\.(js|ts|css)$` under `src/**`.
68+
- `warning`: likely-minified file (avg line length > 300 and median > 120) in `src/**`.
69+
- `warning`: large files in `src/**` > 250 KB (exclude `assets/**` and PBIVIZ icons).
70+
- `warning`: assets > 500 KB — recommend re-evaluating bundling, compression, or CDN prohibition (if applicable).
71+
72+
### 5) Linting, tests
73+
- `package.json` scripts must include:
74+
- `lint`, `test`, `package` (or `pbiviz package`) → missing → `warning`.
75+
- ESLint configuration must exist at repo root:
76+
- Prefer `eslint.config.mjs`; if `.eslintrc.*` or `.eslintignore` or `eslintConfig` in `package.json` -> ask to migrate to `eslint.config.mjs`.
77+
- Missing → `warning` + suggest basic config for Power BI visuals.
78+
79+
### 6) Dependencies
80+
- On `dependencies`/`devDependencies` changes require updated `package-lock.json` or `yarn.lock``warning`.
81+
- Major-bump in `package.json``warning` with request to describe motivation/test-case.
82+
- When adding new features → ensure minor-version is bumped.
83+
- (Optional, as `info`) suggest running `npm audit` (at maintainers' discretion).
84+
85+
### 7) Tests & localization
86+
- If logic touched in `src/**` and no new/updated tests nearby → `warning`-reminder.
87+
- UI strings:
88+
- Check `stringResources/en-US/resources.resjson` and string correspondence from code.
89+
- Missing localization keys → `warning`.
90+
- Spellcheck (en-US as source):
91+
- Report probable typos with level (`info`/`warning`) and replacement suggestion.
92+
- Exclude identifiers/acronyms/brand-names based on `.spellcheck-whitelist`.
93+
94+
### 8) Documentation & changelog
95+
- For non-trivial changes — update `changelog.md``info`/`warning`.
96+
- For new public APIs — add usage examples → `info`.
97+
98+
### 9) Code quality & architecture (senior review mindset)
99+
- Briefly summarize PR purpose and affected areas (render, data, settings, UI).
100+
- Highlight:
101+
- Potential performance bottlenecks (DOM in hot paths, unnecessary loops, re-renders).
102+
- Accessibility (ARIA, contrasts, keyboard navigation, screen reader).
103+
- Errors/edge-cases: null/undefined/empty data.
104+
- Resource management: cleanup D3-selectors, event handlers, timers.
105+
- State/races/leaks; excessive coupling; duplication.
106+
- Power BI SDK/utilities compliance, formatting, API contracts.
107+
108+
## Spellcheck Configuration
109+
110+
### What to Check:
111+
- UI strings in code (`src/**`)
112+
- localization files (`stringResources/en-US/**`)
113+
- PR title and description.
114+
115+
### Severity:
116+
- `warning` — UI strings and localization.
117+
- `info` — PR metadata and comments.
118+
119+
---
120+
121+
## Severity & automated labels
122+
123+
- **error** — must fix before merge (e.g., secrets, `WebAccess`, minified code in `src/**`, forbidden APIs).
124+
- **warning** — should fix soon (e.g., missing PR description/tests, major dep bump, large assets).
125+
- **info** — suggestions/style (typos, architecture improvements).
126+
127+
**Auto-labels** (by highest severity and change type):
128+
`security`, `needs-review`, `tests`, `enhancement`, `performance`, `localization`.
129+
130+
---
131+
132+
## Canonical regex library (reference)
84133
```
85-
86-
### Build Commands That Must Work:
87-
- `npm install` - Must complete without errors
88-
- `pbiviz package` - Must compile successfully
89-
- `npm audit` - Must not return high or moderate warnings
90-
- `npm run eslint` - Must pass without lint errors
91-
92-
## Data Handling Guidelines
93-
94-
### capabilities.json Configuration:
95-
- Define clear dataRoles with appropriate displayName, name, and kind
96-
- Implement proper dataViewMappings for your visual type
97-
- Use objects section for formatting properties
98-
- Set appropriate privileges (usually empty for certified visuals)
99-
- Support tooltips, highlighting, and other Power BI features
100-
101-
### Data Processing:
102-
- Handle empty or null data gracefully
103-
- Implement proper data validation and type checking
104-
- Support dynamic data updates through the update() method
105-
- Respect data view mappings and transformations
106-
- Test with various data sizes and edge cases
107-
108-
## Visual Implementation Standards
109-
110-
### Main Visual Class Structure:
111-
```typescript
112-
export class Visual implements IVisual {
113-
private target: HTMLElement;
114-
private updateCount: number;
115-
private settings: VisualSettings;
116-
private host: IVisualHost;
117-
118-
constructor(options: VisualConstructorOptions) {
119-
// Initialize visual components safely
120-
}
121-
122-
public update(options: VisualUpdateOptions) {
123-
// Handle data updates and rendering
124-
// Always check for data availability
125-
// Implement proper error handling
126-
}
127-
128-
public destroy(): void {
129-
// Clean up resources properly
130-
}
131-
}
134+
# Conventional commits
135+
^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9-./]+\))?(!)?: .{1,72}$
136+
137+
# Unsafe DOM / HTML injection
138+
\binnerHTML\s*=
139+
\.html\s*\(
140+
141+
# Dynamic scripts / code eval
142+
createElement\s*\(\s*['"]script['"]\s*\)|appendChild\s*\([^)]*script[^)]*\)
143+
\beval\s*\(
144+
\bnew\s+Function\s*\(
145+
set(?:Timeout|Interval)\s*\(\s*(['"]).*?\1
146+
147+
# Network APIs
148+
\bXMLHttpRequest\b|\bWebSocket\b|\bfetch\s*\(
149+
150+
# Secrets (subset)
151+
AKIA[0-9A-Z]{16}
152+
ghp_[A-Za-z0-9]{36,}
153+
xox[baprs]-[A-Za-z0-9-]{10,48}
154+
eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}
155+
(AccountKey|SharedAccessKey|SAS|Sig|se=|sp=|sr=|spr=|sv=|st=|sk=|connection\s*string)\s*=\s*[^;'\n]+
156+
npm_[A-Za-z0-9]{36,}
132157
```
133-
134-
### Rendering Best Practices:
135-
- Use D3.js for safe data binding and DOM manipulation
136-
- Implement proper enter/update/exit patterns for data joins
137-
- Handle viewport changes and resizing gracefully
138-
- Support accessibility features (ARIA labels, keyboard navigation)
139-
- Optimize performance for large datasets
140-
141-
## Testing and Quality Assurance
142-
143-
### Testing Requirements:
144-
- Test with sample report data
145-
- Verify behavior with empty datasets
146-
- Test cross-filtering and highlighting functionality
147-
- Validate formatting options work correctly
148-
- Test in both Power BI Desktop and Service
149-
- Ensure no console errors or warnings
150-
151-
### Performance Considerations:
152-
- Optimize rendering for large datasets
153-
- Implement efficient data processing algorithms
154-
- Avoid memory leaks in event handlers
155-
- Use requestAnimationFrame for smooth animations
156-
- Profile and optimize critical code paths
157-
158-
## Repository Management for Certification
159-
160-
### Branch Structure:
161-
- Maintain a `certification` branch (lowercase required)
162-
- Source code in certification branch must match submitted package
163-
- Only update certification branch during resubmission process
164-
165-
### Git Best Practices:
166-
- Use meaningful commit messages
167-
- Keep commits atomic and focused
168-
- Include proper .gitignore for Node.js projects
169-
- Tag releases with version numbers
170-
- Document changes in commit history
171-
172-
## Code Review Guidelines
173-
174-
### Before Committing:
175-
- Run all build commands successfully
176-
- Execute eslint without errors
177-
- Test visual with various data scenarios
178-
- Verify no forbidden patterns are used
179-
- Check for proper error handling
180-
- Validate accessibility compliance
181-
182-
### Code Quality Checks:
183-
- Ensure TypeScript strict mode compliance
184-
- Verify proper type annotations
185-
- Check for unused imports or variables
186-
- Validate proper resource cleanup
187-
- Review security implications of all code changes
188-
189-
## Common Patterns to Watch For
190-
191-
### Replace These Unsafe Patterns:
192-
- `element.innerHTML = userData` → Use `element.textContent = userData`
193-
- `fetch(url)` → Remove external API calls entirely
194-
- `eval(code)` → Refactor to avoid dynamic code execution
195-
- `setTimeout(userFunction)` → Use fixed, safe timeout functions only
196-
197-
### Preferred Safe Alternatives:
198-
- Use D3's data binding instead of direct DOM manipulation
199-
- Use Power BI's built-in formatting instead of external libraries
200-
- Use capabilities.json objects for user customization
201-
- Use IVisualHost services for Power BI integration
202-
203-
Remember: Certification requires passing Microsoft's security review, code analysis, and functional testing. Every piece of code will be scrutinized for security vulnerabilities and compliance with Power BI standards.

0 commit comments

Comments
 (0)