Skip to content

Commit 18c6f38

Browse files
authored
chore: various cleanups (#797)
* chore: various cleanups * chore: ignore no-unsafe-optional-chaining for now
1 parent 75af0fb commit 18c6f38

14 files changed

+213
-199
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
node_modules/
22
dist/
33
eslint-remote-tester-results/
4-
fixtures/node_modules
54
.idea/
65
.vscode/

.npmignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 78 additions & 78 deletions
Large diffs are not rendered by default.

eslint-remote-tester.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
getPathIgnorePattern,
55
getRepositories,
66
} from 'eslint-remote-tester-repositories'
7-
import vitest from './dist/index.mjs'
7+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8+
// @ts-ignore available once package is built
9+
import vitest from '@vitest/eslint-plugin'
810

911
export default {
1012
repositories: getRepositories(),

eslint.config.ts

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
import eslint from '@eslint/js'
12
import { defineConfig } from 'eslint/config'
3+
import tseslint from 'typescript-eslint'
4+
import gitignore from 'eslint-config-flat-gitignore'
25
import vitest from './src/index.js'
36
import eslintPlugin from 'eslint-plugin-eslint-plugin'
47
import eslintConfigPrettier from 'eslint-config-prettier/flat'
5-
import tseslint from 'typescript-eslint'
68

79
export default defineConfig(
8-
eslintPlugin.configs.recommended,
9-
vitest.configs.recommended,
10+
gitignore(),
11+
eslint.configs.recommended,
1012
tseslint.configs.recommended,
11-
eslintConfigPrettier,
13+
// @ts-expect-error see https://github.com/vitest-dev/eslint-plugin-vitest/issues/771
14+
vitest.configs.recommended,
15+
eslintPlugin.configs.recommended,
1216
{
1317
languageOptions: {
1418
parserOptions: {
1519
projectService: {
16-
allowDefaultProject: [
17-
'eslint.config.ts',
18-
'.eslint-doc-generatorrc.js',
19-
'vitest.config.mts',
20-
'unbuild.config.ts',
21-
'eslint-remote-tester.config.ts',
22-
'scripts/chain-permutations.ts',
23-
],
20+
allowDefaultProject: ['*.js'],
2421
},
25-
tsconfigRootDir: import.meta.dirname,
22+
},
23+
},
24+
settings: {
25+
vitest: {
26+
typecheck: true,
2627
},
2728
},
2829
rules: {
@@ -37,28 +38,9 @@ export default defineConfig(
3738
'eslint-plugin/require-meta-default-options': 'warn',
3839
'eslint-plugin/require-meta-schema-description': 'warn',
3940
'eslint-plugin/no-meta-schema-default': 'warn',
41+
'no-prototype-builtins': 'warn',
42+
'no-unsafe-optional-chaining': 'warn',
4043
},
4144
},
42-
{
43-
files: ['**/*.test.*'],
44-
plugins: {
45-
vitest,
46-
},
47-
rules: {
48-
'eslint-plugin/require-meta-docs-description': 'error',
49-
},
50-
settings: {
51-
vitest: {
52-
typecheck: true,
53-
},
54-
},
55-
},
56-
{
57-
ignores: ['**/dist/**'],
58-
},
59-
{
60-
linterOptions: {
61-
reportUnusedDisableDirectives: 'error',
62-
},
63-
},
45+
eslintConfigPrettier,
6446
)

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"name": "@vitest/eslint-plugin",
33
"version": "1.3.23",
44
"license": "MIT",
5-
"description": "Eslint plugin for vitest",
5+
"description": "ESLint plugin for Vitest",
66
"repository": "vitest-dev/eslint-plugin-vitest",
77
"keywords": [
88
"eslint",
99
"eslintplugin",
1010
"eslint-plugin",
11-
"vitest eslint plugin",
11+
"eslint plugin",
1212
"vitest",
13-
"eslint plugin"
13+
"vitest eslint plugin"
1414
],
1515
"author": "Verite Mugabo <https://veritemugabo.com/>",
1616
"type": "module",
@@ -30,26 +30,29 @@
3030
"scripts": {
3131
"build": "tsdown --format esm --format cjs",
3232
"typecheck": "tsc --noEmit",
33+
"lint": "concurrently --prefixColors auto \"pnpm:lint:*\"",
3334
"lint:eslint-docs": "pnpm build && eslint-doc-generator --check",
3435
"lint:js": "eslint",
35-
"lint": "concurrently --prefixColors auto \"pnpm:lint:*\"",
36-
"release": "bumpp package.json --commit --push --tag && pnpm build && pnpm publish",
37-
"stub": "unbuild --stub",
36+
"release": "bumpp && pnpm build && pnpm publish",
3837
"format": "prettier 'src/**/*.{ts,js}' --check",
3938
"test": "vitest",
39+
"update:chains": "node scripts/chain-permutations.ts",
4040
"update:eslint-docs": "pnpm build && eslint-doc-generator"
4141
},
4242
"dependencies": {
4343
"@typescript-eslint/scope-manager": "^8.46.1",
4444
"@typescript-eslint/utils": "^8.46.1"
4545
},
4646
"devDependencies": {
47+
"@eslint/js": "^9.38.0",
4748
"@types/eslint": "^9.6.1",
4849
"@types/node": "^22.18.10",
50+
"@typescript-eslint/parser": "^8.46.1",
4951
"@typescript-eslint/rule-tester": "^8.46.1",
5052
"bumpp": "^10.3.1",
5153
"concurrently": "^9.2.1",
5254
"eslint": "^9.37.0",
55+
"eslint-config-flat-gitignore": "^2.1.0",
5356
"eslint-config-prettier": "^10.1.8",
5457
"eslint-doc-generator": "^2.3.0",
5558
"eslint-plugin-eslint-plugin": "^7.0.0",
@@ -64,8 +67,8 @@
6467
"vitest": "^3.2.4"
6568
},
6669
"peerDependencies": {
67-
"eslint": ">= 8.57.0",
68-
"typescript": ">= 5.0.0",
70+
"eslint": ">=8.57.0",
71+
"typescript": ">=5.0.0",
6972
"vitest": "*"
7073
},
7174
"peerDependenciesMeta": {

pnpm-lock.yaml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
savePrefix: ^
12
injectWorkspacePackages: true
23
onlyBuiltDependencies:
34
- esbuild

scripts/chain-permutations.ts

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
// imported from https://github.com/veritem/eslint-plugin-vitest/pull/293
2-
// This script generates all possible permutations for vitest methods
1+
/*
2+
* This script generates all possible permutations for Vitest methods.
3+
*
4+
* Run it with `pnpm update:chains`.
5+
*
6+
* Originally imported from https://github.com/veritem/eslint-plugin-vitest/pull/293.
7+
*/
38
import fs from 'node:fs'
49
import path from 'node:path'
5-
import { per } from 'percom'
610

711
const data = [
812
{
@@ -114,7 +118,7 @@ data.forEach((q) => {
114118
})
115119
})
116120

117-
const extra_rules = [
121+
const extraRules = [
118122
'xtest',
119123
'xtest.each',
120124
'xit',
@@ -125,18 +129,49 @@ const extra_rules = [
125129
'fdescribe',
126130
]
127131

128-
const output = `export const ValidVitestFnCallChains = new Set([${allPermutations.concat(extra_rules).map((item) => `'${item}'`)}])`
132+
const output = `export const ValidVitestFnCallChains = new Set([${allPermutations.concat(extraRules).map((item) => `'${item}'`)}])`
129133

130-
const new_path = path.resolve(
131-
__dirname,
134+
const newPath = path.resolve(
135+
import.meta.dirname,
132136
'../src/utils/valid-vitest-fn-call-chains.ts',
133137
)
134138

135-
try {
136-
fs.writeFileSync(new_path, output)
137-
console.log(
138-
`done writing to ${new_path.split('/')[new_path.split('/').length - 1]}`,
139-
)
140-
} catch (err) {
141-
console.log(`err: ${err.message}`)
139+
fs.writeFileSync(newPath, output)
140+
console.log(
141+
`done writing to ${newPath.split('/')[newPath.split('/').length - 1]}`,
142+
)
143+
144+
// Based on https://github.com/kota-yata/Percom/blob/master/src/permutation.js (MIT licensed)
145+
function calcPer<T>(
146+
array: T[],
147+
num: number,
148+
current: T[] = [],
149+
result: T[][] = [],
150+
) {
151+
if (current.length >= num) return null
152+
let tempCurrent = current.slice(0, current.length)
153+
for (let i = 0; i < array.length; i++) {
154+
tempCurrent.push(array[i])
155+
const slicedArray = array.filter((_, index) => index !== i)
156+
const returned = calcPer(slicedArray, num, tempCurrent, result)
157+
if (returned === null) result.push(tempCurrent)
158+
tempCurrent = current.slice(0, current.length)
159+
}
160+
return result
161+
}
162+
/**
163+
* Permutation
164+
* @param array - Target array
165+
* @param num - Number of elements in a permutation
166+
* @return Return all permutations
167+
* @example
168+
* const result = per([1, 2, 3], 2);
169+
* //result = [ [ 1, 2 ], [ 1, 3 ], [ 2, 1 ], [ 2, 3 ], [ 3, 1 ], [ 3, 2 ] ]
170+
*/
171+
function per<T>(array: T[], num: number) {
172+
if (array.length < num)
173+
throw new Error(
174+
'Number of elements of array must be greater than number to choose',
175+
)
176+
return calcPer(array, num) as T[][]
142177
}

scripts/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)