Skip to content

Commit f737e41

Browse files
committed
chore: initial release v1.0.0
0 parents  commit f737e41

41 files changed

Lines changed: 7657 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint"],
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/recommended"
8+
],
9+
"parserOptions": {
10+
"ecmaVersion": 2020,
11+
"sourceType": "module"
12+
},
13+
"rules": {
14+
"@typescript-eslint/no-explicit-any": "warn",
15+
"@typescript-eslint/explicit-function-return-type": "off",
16+
"no-console": "off"
17+
},
18+
"ignorePatterns": ["dist/", "node_modules/", "*.js"]
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Bug report
3+
about: Something isn't working correctly
4+
title: '[bug] '
5+
labels: bug
6+
---
7+
8+
**Describe the bug**
9+
A clear description of what the bug is.
10+
11+
**To reproduce**
12+
Steps to reproduce the behaviour, including the test file content that triggers the issue.
13+
14+
**Expected behaviour**
15+
What you expected to happen.
16+
17+
**Environment**
18+
- assert-guard version:
19+
- Node.js version:
20+
- OS:
21+
22+
**Config (ag.config.json)**
23+
```json
24+
25+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Rule request
3+
about: Suggest a new quality rule
4+
title: '[rule] '
5+
labels: enhancement
6+
---
7+
8+
**What anti-pattern should this rule catch?**
9+
Describe the bad practice with a code example.
10+
11+
**Why is this harmful in a test suite?**
12+
Explain the real-world consequences (flakiness, maintenance burden, CI failures, etc.)
13+
14+
**What should the fix hint say?**
15+
What guidance should assert-guard give to the developer?
16+
17+
**Suggested severity**
18+
- [ ] error (blocks merge)
19+
- [ ] warn (advisory)
20+
- [ ] info (informational)

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Test & Build
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
node-version: [18.x, 20.x]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Lint
30+
run: npm run lint
31+
32+
- name: Build
33+
run: npm run build
34+
35+
- name: Test
36+
run: npm run test:coverage
37+
38+
- name: Upload coverage
39+
uses: actions/upload-artifact@v4
40+
if: matrix.node-version == '20.x'
41+
with:
42+
name: coverage-report
43+
path: coverage/
44+
45+
self-scan:
46+
name: Self Quality Gate
47+
runs-on: ubuntu-latest
48+
needs: test
49+
steps:
50+
- uses: actions/checkout@v4
51+
- uses: actions/setup-node@v4
52+
with:
53+
node-version: '20.x'
54+
cache: 'npm'
55+
- run: npm ci
56+
- run: npm run build
57+
- name: Run assert-guard on test fixtures
58+
run: node bin/assert-guard.js scan --dir ./tests --format cli || true

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: '20.x'
20+
registry-url: 'https://registry.npmjs.org'
21+
cache: 'npm'
22+
23+
- run: npm ci
24+
- run: npm run build
25+
- run: npm test
26+
27+
- name: Publish
28+
run: npm publish --provenance --access public
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
dist/
3+
coverage/
4+
assert-guard-reports/
5+
*.tsbuildinfo
6+
.DS_Store
7+
.env
8+
.env.local

CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Changelog
2+
3+
All notable changes to assert-guard are documented here.
4+
5+
This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6+
and [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
---
9+
10+
## [Unreleased]
11+
12+
_Nothing yet._
13+
14+
---
15+
16+
## [1.0.0] — 2026-04-15
17+
18+
### Added
19+
20+
- **Core rule engine** — AST-based scanner using `@babel/parser` with TypeScript and JSX support
21+
- **7 built-in rules** covering the most common test anti-patterns:
22+
- `no-hard-waits` (error) — flags `cy.wait(N)`, `Thread.sleep()`, `page.waitForTimeout()`
23+
- `no-logic-in-tests` (error) — detects `if/else`, `for` loops, and `try/catch` inside test blocks
24+
- `no-focused-tests` (error) — catches `it.only()`, `test.only()`, `fit()`, `fdescribe()`
25+
- `no-hardcoded-credentials` (error) — detects hardcoded passwords, tokens, and API keys
26+
- `no-flaky-selectors` (warn) — flags `nth-child()`, absolute XPath, and generated CSS class selectors
27+
- `single-assertion-focus` (warn) — warns when a test block exceeds the configured assertion limit
28+
- `test-isolation-check` (info) — detects shared `let` state declared at describe scope
29+
- **CLI commands**: `scan`, `init`, `rules`
30+
- **Three report formats**: `cli` (coloured terminal), `json`, `html` (self-contained single file)
31+
- **Quality gate exit codes**: exits `1` on errors (or warnings when `failOnWarnings: true`), `0` on pass
32+
- **`ag.config.json` config file** — customise rules, include/exclude globs, assertion limits, output directory
33+
- **`assert-guard init`** — scaffolds a default config file
34+
- **`assert-guard rules`** — lists all available rules with their default severity
35+
- **GitHub Actions workflows** — CI (test + build on Node 18/20) and npm publish on release
36+
- **Full TypeScript** — ships with `.d.ts` declarations for use as a library
37+
- **Programmatic API** — all core functions exported from the main entry point
38+
39+
### Rules detail
40+
41+
| Rule | Default | Catches |
42+
|------|---------|---------|
43+
| `no-hard-waits` | error | `cy.wait(N)`, `Thread.sleep()`, `waitForTimeout()` |
44+
| `no-logic-in-tests` | error | `if`, `for`, `for..of`, `try/catch` inside `it()`/`test()` |
45+
| `no-focused-tests` | error | `it.only`, `test.only`, `describe.only`, `fit`, `fdescribe` |
46+
| `no-hardcoded-credentials` | error | hardcoded passwords, tokens, API keys in test files |
47+
| `no-flaky-selectors` | warn | positional CSS, absolute XPath, generated class names |
48+
| `single-assertion-focus` | warn | more than N assertions per test (default N=5) |
49+
| `test-isolation-check` | info | shared `let` state in `describe` scope |
50+
51+
---
52+
53+
[Unreleased]: https://github.com/qa-ashutosh/assert-guard/compare/v1.0.0...HEAD
54+
[1.0.0]: https://github.com/qa-ashutosh/assert-guard/releases/tag/v1.0.0

CONTRIBUTING.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Contributing to assert-guard
2+
3+
Thank you for your interest in contributing! assert-guard is open source and welcomes community contributions — especially new rules.
4+
5+
## Getting started
6+
7+
```bash
8+
git clone https://github.com/qa-ashutosh/assert-guard.git
9+
cd assert-guard
10+
npm install
11+
npm run build
12+
npm test
13+
```
14+
15+
## Adding a new rule
16+
17+
Each rule lives in `src/rules/` as its own TypeScript file. Here is the minimum shape:
18+
19+
```typescript
20+
import traverse from '@babel/traverse';
21+
import * as t from '@babel/types';
22+
import type { Rule, Violation } from '../types';
23+
24+
const rule: Rule = {
25+
name: 'your-rule-name', // kebab-case, unique
26+
description: 'One sentence.',
27+
severity: 'warn', // 'error' | 'warn' | 'info'
28+
hint: 'What the developer should do instead.',
29+
30+
check(ast, filePath): Violation[] {
31+
const violations: Violation[] = [];
32+
traverse(ast, {
33+
// visit AST nodes here
34+
});
35+
return violations;
36+
},
37+
};
38+
39+
export default rule;
40+
```
41+
42+
Then register it in `src/rules/index.ts` and add a default severity to `DEFAULT_CONFIG`.
43+
44+
Every rule must have a corresponding test file in `tests/rules/`.
45+
46+
## Running tests
47+
48+
```bash
49+
npm test # run all tests
50+
npm run test:coverage # with coverage report
51+
```
52+
53+
## Code style
54+
55+
- TypeScript strict mode is enforced
56+
- Run `npm run lint` before opening a PR
57+
- Keep dependencies minimal — if the standard library can do it, prefer that
58+
59+
## Pull request checklist
60+
61+
- [ ] New rule has unit tests covering at least: one positive case, one negative (no false positive), and one edge case
62+
- [ ] Rule is registered in `src/rules/index.ts`
63+
- [ ] `CHANGELOG.md` entry added under `[Unreleased]`
64+
- [ ] `npm test` passes locally
65+
66+
## Reporting bugs
67+
68+
Use the GitHub issue tracker with the bug report template.
69+
70+
## Suggesting rules
71+
72+
Open an issue using the rule request template. Include a code example of the anti-pattern and explain why it's harmful.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Ashutosh Parihar
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)