-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
130 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }], | ||
// })), | ||
// }) | ||
}) |
2 changes: 1 addition & 1 deletion
2
src/rules/lower-case-title.test.ts → tests/lower-case-title.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/rules/no-conditional-in-tests.test.ts → tests/no-conditional-in-tests.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/rules/no-skipped-tests.test.ts → tests/no-skipped-tests.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters