Skip to content

Commit

Permalink
Add eslint-plugin-vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Jan 3, 2024
1 parent 176ac60 commit 80578aa
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 24 deletions.
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": [
"camelcase",
"eslintconfig",
"falsey",
"nonconstructor",
"plusplus",
"sonarjs",
"tailwindcss",
"viam",
"viamrobotics"
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-tailwindcss": "^3.13.1",
"eslint-plugin-unicorn": "^50.0.1",
"eslint-plugin-vitest": "^0.3.20",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"prettier-plugin-tailwindcss": "^0.5.10",
Expand Down
6 changes: 4 additions & 2 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pnpm add --save-dev \
eslint \
eslint-config-prettier \
eslint-plugin-sonarjs \
eslint-plugin-unicorn
eslint-plugin-unicorn \
eslint-plugin-vitest
```

```js
Expand Down Expand Up @@ -47,7 +48,8 @@ pnpm add --save-dev \
eslint-plugin-sonarjs \
eslint-plugin-svelte \
eslint-plugin-tailwindcss \
eslint-plugin-unicorn
eslint-plugin-unicorn \
eslint-plugin-vitest
```

```js
Expand Down
31 changes: 29 additions & 2 deletions packages/eslint-config/base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,40 @@ module.exports = {
'unicorn/prefer-module': 'off',
},
},
// Relax rules that don't make sense for testing
// Rules for tests
{
files: ['**/__tests__/**', '**/*.spec.ts'],
files: ['**/__tests__/**', '**/*.test.ts', '**/*.spec.ts'],
extends: ['plugin:vitest/recommended'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'sonarjs/no-duplicate-string': 'off',
'vitest/consistent-test-filename': [
'error',
{
pattern: '.*\\.spec\\.(ts|svelte)$',
},
],
'vitest/consistent-test-it': ['error', { fn: 'it' }],
'vitest/no-conditional-expect': 'error',
'vitest/no-conditional-in-test': 'error',
'vitest/no-conditional-tests': 'error',
'vitest/no-restricted-matchers': [
'error',
{
toBeFalsey: 'Prefer `toBe` or `toEqual`',
toBeTruthy: 'Prefer `toBe` or `toEqual`',
},
],
'vitest/no-restricted-vi-methods': [
'error',
{
spyOn: 'Do not partially mock objects',
},
],
'vitest/prefer-each': 'error',
'vitest/require-top-level-describe': 'error',
'vitest/valid-expect': ['error', { maxArgs: 2 }],
},
},
// Rules that don't make sense for ambient type files
Expand Down
8 changes: 6 additions & 2 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "0.3.1",
"version": "0.4.0",
"description": "Common ESLint configuration for Viam projects.",
"files": [
"**/*",
Expand Down Expand Up @@ -48,14 +48,18 @@
"eslint-plugin-sonarjs": ">=0.19 <0.24",
"eslint-plugin-svelte": ">=2 <3",
"eslint-plugin-tailwindcss": ">=3 <4",
"eslint-plugin-unicorn": ">=47 <51"
"eslint-plugin-unicorn": ">=47 <51",
"eslint-plugin-vitest": ">=0.3.0"
},
"peerDependenciesMeta": {
"eslint-plugin-svelte": {
"optional": true
},
"eslint-plugin-tailwindcss": {
"optional": true
},
"eslint-plugin-vitest": {
"optional": true
}
}
}
25 changes: 25 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 15 additions & 18 deletions tests/peers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import path from 'node:path';
import url from 'node:url';
import fs from 'node:fs';
import { describe, test, expect } from 'vitest';
import { describe, it, expect } from 'vitest';
import semver from 'semver';

interface PackageJSON {
Expand All @@ -21,25 +21,22 @@ const getManifest = (pkgPath: string) =>
describe('peer dependency specifications', () => {
const { devDependencies } = getManifest('');

packages.forEach((packageName) => {
describe(packageName, () => {
const { peerDependencies } = getManifest(
path.join('packages', packageName)
);
describe.each(packages)(`Package %s`, (packageName) => {
const { peerDependencies } = getManifest(
path.join('packages', packageName)
);
const cases = Object.entries(peerDependencies).map(
([dependencyName, peerRange]) => ({ dependencyName, peerRange })
);

Object.entries(peerDependencies).forEach(
([dependencyName, peerRange]) => {
test(dependencyName, () => {
const devVersion = devDependencies[dependencyName];
it.each(cases)('$dependency name', ({ dependencyName, peerRange }) => {
const devVersion = devDependencies[dependencyName];

expect(devVersion).toBeDefined();
expect(
semver.subset(devVersion!, peerRange),
`"${devVersion!}" should be within peer range "${peerRange}"`
).toBe(true);
});
}
);
expect(devVersion).toBeDefined();
expect(
semver.subset(devVersion!, peerRange),
`"${devVersion!}" should be within peer range "${peerRange}"`
).toBe(true);
});
});
});

0 comments on commit 80578aa

Please sign in to comment.