Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dicko2 committed Nov 14, 2024
1 parent 6606aa3 commit 76a7a0c
Show file tree
Hide file tree
Showing 22 changed files with 4,073 additions and 1 deletion.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI
on:
push:
branches: [ "main", "master" ]
pull_request:
branches: [ "main", "master" ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8.12.1

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Type Check
run: pnpm run typecheck

- name: Lint
run: pnpm run lint

- name: Test
run: pnpm run test

- name: Build
run: pnpm run build
58 changes: 58 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Documentation
on:
push:
branches: [ "main", "master" ]
release:
types: [created]
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8.12.1

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build documentation
run: pnpm run docs

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './docs'

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
34 changes: 34 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PR Checks
on:
pull_request:
branches: [ "main", "master" ]

jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8.12.1

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check formatting
run: pnpm prettier --check .

- name: Type check
run: pnpm run typecheck

- name: Lint
run: pnpm run lint

- name: Test
run: pnpm run test
56 changes: 56 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

name: Publish Package
on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8.12.1

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Test
run: pnpm test

- name: Build
run: pnpm run build

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8.12.1

- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm run build

- name: Publish to NPM
run: pnpm publish --no-git-checks --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
strict-peer-dependencies=false
auto-install-peers=false
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
node_modules
coverage
pnpm-lock.yaml
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 80,
"tabWidth": 2,
"semi": true
}
Empty file added CONTRIBUTING.md
Empty file.
155 changes: 154 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,154 @@
# code-compass-js
# CodeCompass 🧭

> Because finding your way through tech debt shouldn't require a real compass
[![CI](https://github.com/agoda-com/code-compass/actions/workflows/ci.yml/badge.svg)](https://github.com/agoda-com/code-compass/actions/workflows/ci.yml)
[![npm version](https://badge.fury.io/js/%40agoda%2Fcode-compass.svg)](https://badge.fury.io/js/%40agoda%2Fcode-compass)
[![Documentation](https://img.shields.io/badge/docs-TypeDoc-blue.svg)](https://agoda-com.github.io/code-compass/)

CodeCompass is your trusty guide through the treacherous waters of technical debt and framework migrations. Think of it as a GPS for your codebase, but without the annoying "recalculating..." messages.

## Features

- 🎯 Technical debt estimation (because "it'll take 5 minutes" is never true)
- 🗺️ Migration path tracking (no more "are we there yet?")
- 📊 SARIF report enrichment (make your reports as rich as a tech exec's portfolio)
- 🔄 Framework migration helpers (farewell Enzyme, hello RTL!)
- 📝 Detailed metadata for static analysis rules (because context is king 👑)

## Installation

Choose your weapon:

```bash
# Using pnpm (the cool kids' choice)
pnpm add -D @agoda/code-compass

# Using npm (old reliable)
npm install --save-dev @agoda/code-compass

# Using yarn (if you're feeling classic)
yarn add -D @agoda/code-compass
```

## Quick Start

1. **Basic Setup with ESLint** (easier than setting up your morning coffee)

```javascript
// eslint.config.js
import { RuleRegistry, registerEnzymeToRTLRules } from '@agoda/code-compass';

// Register migration rules (no compass required)
registerEnzymeToRTLRules();

export default {
// Your existing ESLint config (we promise not to judge)
plugins: ['@typescript-eslint'],
rules: {
// Your rules (the more the merrier)
}
};
```

2. **Generate SARIF with Metadata** (where the magic happens)

```bash
# Run ESLint with SARIF output (warning: may reveal uncomfortable truths)
eslint . -f @agoda/code-compass/sarif -o eslint-results.sarif
```

## Adding Custom Metadata

### For Existing Rules (because your rules deserve better)

```typescript
import { RuleRegistry } from '@agoda/code-compass';

const registry = RuleRegistry.getInstance();

registry.registerRule({
ruleId: 'no-console',
type: 'technical-debt',
estimatedMinutes: 15, // Optimist, aren't we?
category: 'cleanup',
priority: 'low',
rationale: 'Console logs should be removed in production code',
impacts: [
{
area: 'production-quality',
severity: 'medium'
}
]
});
```

### For Migration Rules (your pathway to modernization)

```typescript
registry.registerRule({
ruleId: 'enzyme-to-rtl/no-shallow',
type: 'migration',
estimatedMinutes: 30, // Time to say goodbye to shallow rendering
category: 'testing',
priority: 'high',
migrationPath: 'enzyme-to-rtl',
rationale: 'Shallow rendering is discouraged in RTL',
resources: [
'https://testing-library.com/docs/react-testing-library/migrate-from-enzyme'
],
impacts: [
{
area: 'test-reliability',
severity: 'high'
}
]
});
```

## Analyzing Results (Moment of Truth Time)

```typescript
import { analyzeTechDebt } from '@agoda/code-compass';

// Parse SARIF file (brace yourself)
const sarifContent = fs.readFileSync('eslint-results.sarif', 'utf8');
const sarifReport = JSON.parse(sarifContent);

// Analyze tech debt (hope you're sitting down)
const analysis = analyzeTechDebt(sarifReport);

console.log('Total estimated minutes:', analysis.totalMinutes);
console.log('By category:', analysis.byCategory);
```

## API Documentation

Lost? Our docs will help you find your way: [https://agoda-com.github.io/code-compass/](https://agoda-com.github.io/code-compass/)

## Contributing

Got ideas? We'd love to hear them! (Unless it's about adding more console.logs)

1. Fork the repository (yes, that button up there)
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Install dependencies (`pnpm install`)
4. Make your changes (the fun part)
5. Run tests (`pnpm test`)
6. Push to the branch (`git push origin feature/amazing-feature`)
7. Open a Pull Request (and cross your fingers)

## License

Apache 2.0 (as free as your next migration should be)

## Acknowledgments

Heartfelt thanks to:
- ESLint team (for catching our mistakes before users do)
- SARIF working group (for making reports readable by humans and machines alike)
- Coffee (for obvious reasons) ☕

---

Remember: Technical debt is like your laundry - it doesn't go away by ignoring it. Let CodeCompass help you sort it out! 🧺
Loading

0 comments on commit 76a7a0c

Please sign in to comment.