Skip to content

Commit

Permalink
fix: added ci
Browse files Browse the repository at this point in the history
  • Loading branch information
veritem committed Apr 4, 2022
1 parent 2dce284 commit 79003dd
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 12 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: ci
on:
push:
jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [17]
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2.0.1
with:
version: 7.0.0-rc.2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: install
run: pnpm install
- name: test
run: pnpm test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## eslint-plugin-vitest

> Disclaimer: This package is very experimental
![npm](https://img.shields.io/npm/v/eslint-plugin-vitest)

Eslint plugin for vitest
Expand Down
26 changes: 17 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import lowerCaseTitle from "./rules/lower-case-title";
import noSkippedTests from "./rules/no-skipped-tests";

export default {
rules: {
'no-skip-test': noSkippedTests,
'lower-case-title': lowerCaseTitle
}
}
import { readdirSync } from "fs";
import { dirname, join, parse } from "path";
import { fileURLToPath } from "url";

const rulesDir = dirname(fileURLToPath(import.meta.url));

console.log({ rulesDir })

const values = readdirSync(rulesDir)
.map(rule => parse(rule).name)
.reduce((allRules, ruleName) => ({
...allRules,
[ruleName]: import(join(rulesDir, ruleName)),
}), {})


console.log({ values })
62 changes: 62 additions & 0 deletions src/rules/assertion-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { createEslintRule } from "../utils";

export const RULE_NAME = 'assertion-type';
export type MessageIds = 'assertionType';
export type Options = [
{
type: "jest" | "chai",
}
];
export default createEslintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: "problem",
docs: {
description: "Enforce assertion type",
recommended: "error",
},
fixable: 'code',
schema: [
{
type: 'object',
properties: {
type: {
type: 'string',
enum: ['jest', 'chai'],
},
},
additionalProperties: false,
},
],
messages: {
assertionType: "Assertion type should be {{type}}.",
},
},
defaultOptions: [
{
type: "jest",
},
],
create(context) {
const { type } = context.options[0];
const assertionType = type === "jest" ? "expect" : "assert";
return {
ExpressionStatement(node) {
if (node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier") {
if (node.expression.callee.name === assertionType) {
const { arguments: args } = node.expression
if (args[0].type === "Identifier" && args[0].name !== "t") {
context.report({
node,
messageId: 'assertionType',
data: {
type,
},
})
}
}
}
}
}
}
});
23 changes: 23 additions & 0 deletions tests/assertion-type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { RuleTester } from "@typescript-eslint/utils/dist/ts-eslint"
import { it } from "vitest"
import { RULE_NAME } from "../src/rules/assertion-type"


const valid = [`it.each()`]
const invalids = []


it(RULE_NAME, () => {
const rule_tester: RuleTester = new RuleTester({
parser: require.resolve("@typescript-eslint/parser")
})

// rule_tester.run(RULE_NAME, rule, {
// valid,
// invalid: invalids.map(i => ({
// code: i,
// output: i,
// errors: [{ messageId: "lowerCaseTitle" }],
// })),
// })
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RuleTester } from "@typescript-eslint/utils/dist/ts-eslint"
import { it } from "vitest"
import rule, { RULE_NAME } from "./lower-case-title"
import rule, { RULE_NAME } from "../src/rules/lower-case-title"



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RuleTester } from "@typescript-eslint/utils/dist/ts-eslint"
import { it } from "vitest"
import rule, { RULE_NAME } from "./no-conditional-in-tests"
import rule, { RULE_NAME } from "../src/rules/no-conditional-in-tests"

const invalids = [
`describe('my tests', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RuleTester } from "@typescript-eslint/utils/dist/ts-eslint"
import { it } from "vitest"
import rule, { RULE_NAME } from "./no-skipped-tests"
import rule, { RULE_NAME } from "../src/rules/no-skipped-tests"

const valids = [
`it("test", () => {});`,
Expand Down

0 comments on commit 79003dd

Please sign in to comment.