Skip to content

Commit

Permalink
chore(pkg): update eslint-plugin-shuunen
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuunen committed Dec 7, 2024
1 parent ee0776e commit 647d33c
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 363 deletions.
3 changes: 0 additions & 3 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// @ts-expect-error missing types
// eslint-disable-next-line @typescript-eslint/no-require-imports
const shuunen = require('eslint-plugin-shuunen')
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@vitest/coverage-v8": "2.1",
"dependency-cruiser": "16.7",
"esbuild": "0.24",
"eslint": "9.14",
"eslint-plugin-shuunen": "0.3",
"eslint": "*",
"eslint-plugin-shuunen": "0.4",
"typescript": "5.7",
"vitest": "2.1",
"watchlist": "0.3"
Expand Down Expand Up @@ -66,4 +66,4 @@
"test:watch": "vitest --coverage"
},
"version": "1.40.0"
}
}
474 changes: 159 additions & 315 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { cleanIndicatorsForSnap, mocksProjectsFolder, tsProjectFolder } from './

it('check A repo-checker folder fails with low max size', async () => {
const data = new ProjectData({ isPublishedPackage: true, isQuiet: true, maxSizeKo: 2 })
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-type-assertion
const message = await check({ data, folderPath: repoCheckerPath }).catch((error: unknown) => (error as Error).message)
expect(message).toMatchSnapshot()
})
Expand All @@ -24,7 +24,7 @@ it('check C ts-project folder', async () => {

it('check D mocks-projects folders and throw', async () => {
const data = new ProjectData({ isQuiet: true })
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-type-assertion
const message = await check({ canFailStop: true, data, folderPath: mocksProjectsFolder }).catch((error: unknown) => (error as Error).message)
expect(message).toMatchSnapshot()
})
Expand Down
55 changes: 28 additions & 27 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const defaultAmount = 99

// eslint-disable-next-line no-restricted-syntax, jsdoc/require-jsdoc
export class FileBase {
private originalFileContent = ''

/** The file can be fixed and written to the disk */
public canFix = false

public canForce = false
Expand All @@ -23,6 +22,8 @@ export class FileBase {

public folderPath = ''

private originalFileContent = ''

public passed: string[] = []

public warnings: string[] = []
Expand All @@ -42,30 +43,6 @@ export class FileBase {
this.canForce = canForce
}

/**
* Check if a file has at least one issue
*/
private async checkIssues() {
if (this.failed.length > 0 && this.canFix) {
if (this.canForce) {
await this.initFile(this.fileName)
return
}
log.info('this file has at least one issue, if you want repo-checker to overwrite this file use --force')
}
}

/**
* Create a file with a given content
* @param fileName the file name
* @param fileContent the file content
*/
private async createFile(fileName: string, fileContent: string) {
void writeFile(join(this.folderPath, fileName), fileContent)
await sleep(1)
log.fix('created', fileName)
}

/**
* Check if a file contains a regex
* @param regex the regex to check
Expand Down Expand Up @@ -96,6 +73,19 @@ export class FileBase {
return hasFile
}

/**
* Check if a file has at least one issue
*/
private async checkIssues() {
if (this.failed.length > 0 && this.canFix) {
if (this.canForce) {
await this.initFile(this.fileName)
return
}
log.info('this file has at least one issue, if you want repo-checker to overwrite this file use --force')
}
}

/**
* Check if there is no file
* @param fileName the file name to check
Expand Down Expand Up @@ -135,6 +125,17 @@ export class FileBase {
return true
}

/**
* Create a file with a given content
* @param fileName the file name
* @param fileContent the file content
*/
private async createFile(fileName: string, fileContent: string) {
void writeFile(join(this.folderPath, fileName), fileContent)
await sleep(1)
log.fix('created', fileName)
}

/**
*
*/
Expand Down Expand Up @@ -172,7 +173,7 @@ export class FileBase {
log.debug(`found no template ${fileName}, using a empty string instead`)
return ''
}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-type-assertion
const fileContent = fillTemplate(template, this.data as unknown as Record<string, unknown>)
if (fileContent.includes('{{')) log.warn(`please provide a data file to be able to fix a "${fileName}" file`)
else void this.createFile(fileName, fileContent)
Expand Down
18 changes: 9 additions & 9 deletions src/files/package.file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,6 @@ export class PackageJsonFile extends FileBase {
return new RegExp(`"${name}": "${value}"`, 'u')
}

private suggestAlternatives() {
this.couldContains('no fat color dependency, use shuutils or nanocolors', /"(?:chalk|colorette|colors)"/u, 0)
this.couldContains('no fat fs-extra dependency, use native fs', /"fs-extra"/u, 0)
this.couldContains('no utopian shuunen-stack dependency', /"shuunen-stack"/u, 0)
this.couldContains('no fat & slow jsdom dependency, use happy-dom instead', /jsdom/u, 0)
this.couldContains('no fat task runner, use pnpm xyz && pnpm abc for sequential or zero-deps package : npm-parallel', /"npm-run-all"/u, 0)
if (this.fileContent.includes('esbuild-plugin-run')) this.couldContains('not fat ts runner, use "typescript-run" like "dev": "ts-run src --watch" or "ts-run src -w src another-folder"')
}

public async start() {
const hasFile = await this.checkFileExists('package.json')
if (!hasFile) return
Expand All @@ -217,4 +208,13 @@ export class PackageJsonFile extends FileBase {
this.suggestAlternatives()
this.checkExports()
}

private suggestAlternatives() {
this.couldContains('no fat color dependency, use shuutils or nanocolors', /"(?:chalk|colorette|colors)"/u, 0)
this.couldContains('no fat fs-extra dependency, use native fs', /"fs-extra"/u, 0)
this.couldContains('no utopian shuunen-stack dependency', /"shuunen-stack"/u, 0)
this.couldContains('no fat & slow jsdom dependency, use happy-dom instead', /jsdom/u, 0)
this.couldContains('no fat task runner, use pnpm xyz && pnpm abc for sequential or zero-deps package : npm-parallel', /"npm-run-all"/u, 0)
if (this.fileContent.includes('esbuild-plugin-run')) this.couldContains('not fat ts runner, use "typescript-run" like "dev": "ts-run src --watch" or "ts-run src -w src another-folder"')
}
}
4 changes: 2 additions & 2 deletions src/files/ts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export class TsConfigFile extends FileBase {
if (this.canFix && json.compilerOptions === undefined) json.compilerOptions = clone(recommended)
// eslint-disable-next-line guard-for-in
for (const inputKey in recommended) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-type-assertion
const key = inputKey as keyof typeof recommended
// eslint-disable-next-line @typescript-eslint/naming-convention
const value = recommended[key]
const regex = new RegExp(`"${key}": ${String(value)}`, 'u')
isOk = this.couldContains(`a ${key} compiler option`, regex, 1, undefined, true)
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-type-assertion
if (!isOk && this.canFix && json.compilerOptions !== undefined) json.compilerOptions[key] = value as never
}
isOk = this.couldContains('a outDir compiler option', /"outDir": "/u, 1, 'ex : "outDir": "./dist",', true)
Expand Down
4 changes: 2 additions & 2 deletions src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ function cleanStringForSnap(input: string) {
// eslint-disable-next-line no-restricted-syntax
function cleanUnknownValueForSnap<Type>(input: Type): Type {
/* c8 ignore next 7 */
/* eslint-disable @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-type-assertion */
if (typeof input === 'string') return cleanStringForSnap(input) as Type
if (Array.isArray(input)) return input.map(item => cleanUnknownValueForSnap(item)) as Type
if (typeof input === 'object') return JSON.parse(cleanStringForSnap(JSON.stringify(input))) as Type
throw new Error(`cleanInstanceValueForSnap: unknown type ${typeof input}`)
/* eslint-enable @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-return */
/* eslint-enable @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-type-assertion */
}

export async function promiseValue<Type>(value: Type) {
Expand Down

0 comments on commit 647d33c

Please sign in to comment.