Skip to content

Commit 340a766

Browse files
committed
feat: init
0 parents  commit 340a766

22 files changed

+6473
-0
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [antfu]

.github/workflows/ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Install pnpm
19+
uses: pnpm/action-setup@v2
20+
21+
- name: Set node
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: lts/*
25+
26+
- name: Setup
27+
run: npm i -g @antfu/ni
28+
29+
- name: Install
30+
run: nci
31+
32+
- name: Lint
33+
run: nr lint
34+
35+
typecheck:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v3
39+
40+
- name: Install pnpm
41+
uses: pnpm/action-setup@v2
42+
43+
- name: Set node
44+
uses: actions/setup-node@v3
45+
with:
46+
node-version: lts/*
47+
48+
- name: Setup
49+
run: npm i -g @antfu/ni
50+
51+
- name: Install
52+
run: nci
53+
54+
- name: Typecheck
55+
run: nr typecheck
56+
57+
test:
58+
runs-on: ${{ matrix.os }}
59+
60+
strategy:
61+
matrix:
62+
node: [lts/*]
63+
os: [ubuntu-latest, windows-latest, macos-latest]
64+
fail-fast: false
65+
66+
steps:
67+
- uses: actions/checkout@v3
68+
69+
- name: Install pnpm
70+
uses: pnpm/action-setup@v2
71+
72+
- name: Set node ${{ matrix.node }}
73+
uses: actions/setup-node@v3
74+
with:
75+
node-version: ${{ matrix.node }}
76+
77+
- name: Setup
78+
run: npm i -g @antfu/ni
79+
80+
- name: Install
81+
run: nci
82+
83+
- name: Build
84+
run: nr build
85+
86+
- name: Test
87+
run: nr test

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install pnpm
20+
uses: pnpm/action-setup@v2
21+
22+
- name: Set node
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: lts/*
26+
27+
- run: npx changelogithub
28+
env:
29+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.cache
2+
.DS_Store
3+
.idea
4+
*.log
5+
*.tgz
6+
coverage
7+
dist
8+
lib-cov
9+
logs
10+
node_modules
11+
temp

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore-workspace-root-check=true
2+
shell-emulator=true

.vscode/settings.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
// Enable the ESlint flat config support
3+
"eslint.experimental.useFlatConfig": true,
4+
5+
// Disable the default formatter, use eslint instead
6+
"prettier.enable": false,
7+
"editor.formatOnSave": false,
8+
9+
// Auto fix
10+
"editor.codeActionsOnSave": {
11+
"source.fixAll": "explicit",
12+
"source.organizeImports": "never"
13+
},
14+
15+
// Silent the stylistic rules in you IDE, but still auto fix them
16+
"eslint.rules.customizations": [
17+
{ "rule": "style/*", "severity": "off" },
18+
{ "rule": "*-indent", "severity": "off" },
19+
{ "rule": "*-spacing", "severity": "off" },
20+
{ "rule": "*-spaces", "severity": "off" },
21+
{ "rule": "*-order", "severity": "off" },
22+
{ "rule": "*-dangle", "severity": "off" },
23+
{ "rule": "*-newline", "severity": "off" },
24+
{ "rule": "*quotes", "severity": "off" },
25+
{ "rule": "*semi", "severity": "off" }
26+
],
27+
28+
// Enable eslint for all supported languages
29+
"eslint.validate": [
30+
"javascript",
31+
"javascriptreact",
32+
"typescript",
33+
"typescriptreact",
34+
"vue",
35+
"html",
36+
"markdown",
37+
"json",
38+
"jsonc",
39+
"yaml"
40+
]
41+
}

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please refer to https://github.com/antfu/contribute

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) 2022 Anthony Fu <https://github.com/antfu>
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.

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# eslint-vitest-rule-tester
2+
3+
[![npm version][npm-version-src]][npm-version-href]
4+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
5+
[![bundle][bundle-src]][bundle-href]
6+
[![JSDocs][jsdocs-src]][jsdocs-href]
7+
[![License][license-src]][license-href]
8+
9+
ESLint rule tester with Vitest.
10+
11+
This module requires ESLint v9.0+.
12+
13+
## Install
14+
15+
```bash
16+
npm i -D eslint-vitest-rule-tester
17+
```
18+
19+
## Usage
20+
21+
### Classical Usage
22+
23+
Simliar style to ESLint's `TestRunner` (test cases with implicit test suites)
24+
25+
```ts
26+
import { run } from 'eslint-vitest-rule-tester'
27+
28+
run('rule-name', rule, {
29+
valid: [
30+
// test cases
31+
],
32+
invalid: [
33+
// test cases
34+
],
35+
}, {
36+
// the default flat configs
37+
configs: {
38+
languageOptions: {
39+
parserOptions: {
40+
ecmaVersion: 2020,
41+
sourceType: 'module',
42+
},
43+
},
44+
}
45+
})
46+
```
47+
48+
### Explicit Test Suites
49+
50+
```ts
51+
import { createRuleTester } from 'eslint-vitest-rule-tester'
52+
import { describe, expect, it } from 'vitest'
53+
54+
describe('rule-name', () => {
55+
const { valid, invalid } = createRuleTester({
56+
name: 'rule-name',
57+
rule,
58+
configs: {
59+
// flat config options
60+
languageOptions: {
61+
parserOptions: {
62+
ecmaVersion: 2020,
63+
sourceType: 'module',
64+
},
65+
},
66+
}
67+
})
68+
69+
it('valid case 1', () => {
70+
valid('const foo = 1')
71+
})
72+
73+
it('invalid case 1 with snapshot', () => {
74+
const result = invalid({
75+
input: 'const foo = 1',
76+
errors: ['error-message-id'],
77+
})
78+
79+
expect(result.output).toMatchSnapshot()
80+
})
81+
})
82+
```
83+
84+
## Sponsors
85+
86+
<p align="center">
87+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
88+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
89+
</a>
90+
</p>
91+
92+
## License
93+
94+
[MIT](./LICENSE) License © 2024-PRESENT [Anthony Fu](https://github.com/antfu)
95+
96+
<!-- Badges -->
97+
98+
[npm-version-src]: https://img.shields.io/npm/v/eslint-vitest-rule-tester?style=flat&colorA=080f12&colorB=1fa669
99+
[npm-version-href]: https://npmjs.com/package/eslint-vitest-rule-tester
100+
[npm-downloads-src]: https://img.shields.io/npm/dm/eslint-vitest-rule-tester?style=flat&colorA=080f12&colorB=1fa669
101+
[npm-downloads-href]: https://npmjs.com/package/eslint-vitest-rule-tester
102+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/eslint-vitest-rule-tester?style=flat&colorA=080f12&colorB=1fa669&label=minzip
103+
[bundle-href]: https://bundlephobia.com/result?p=eslint-vitest-rule-tester
104+
[license-src]: https://img.shields.io/github/license/antfu/eslint-vitest-rule-tester.svg?style=flat&colorA=080f12&colorB=1fa669
105+
[license-href]: https://github.com/antfu/eslint-vitest-rule-tester/blob/main/LICENSE
106+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
107+
[jsdocs-href]: https://www.jsdocs.io/package/eslint-vitest-rule-tester

build.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineBuildConfig } from 'unbuild'
2+
3+
export default defineBuildConfig({
4+
entries: [
5+
'src/index',
6+
],
7+
declaration: true,
8+
clean: true,
9+
})

0 commit comments

Comments
 (0)