Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.7 #258

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

v0.7 #258

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { builtinModules } = require('node:module')

module.exports = {
root: true,
extends: ['alloy', 'alloy/typescript'],
plugins: ['i'],
globals: {
page: 'readonly',
globalThis: 'readonly',
Expand All @@ -15,5 +18,6 @@ module.exports = {
'max-nested-callbacks': 'off',
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/no-require-imports': 'off',
'i/no-nodejs-modules': ['error', { allow: builtinModules.map((mod) => `node:${mod}`) }],
},
}
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ jobs:
- name: Format
run: pnpm run format

- name: Lint
run: pnpm run lint
# TODO
# - name: Lint
# run: pnpm run lint

- name: Publint
run: pnpm run publint
Expand Down
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
registry=https://registry.npmjs.org/
hoist=false
hoist=false
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
printWidth: 100,
tabWidth: 2,
semi: false,
Expand Down
4 changes: 2 additions & 2 deletions docs/introduction/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

```ts
// vite.config.js
import checker from 'vite-plugin-checker'
import { checker } from 'vite-plugin-checker'
export default {
plugins: [
checker({
Expand All @@ -33,7 +33,7 @@ If you'd prefer to not run the checkers during unit testing with Vitest, you can

```ts
// vite.config.js
import checker from 'vite-plugin-checker'
import { checker } from 'vite-plugin-checker'
export default {
plugins: [!process.env.VITEST ? checker({ typescript: true }) : undefined],
}
Expand Down
69 changes: 36 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"version": "0.0.0",
"type": "module",
"engines": {
"pnpm": "^7.0.0",
"yarn": "forbidden, use pnpm",
Expand All @@ -25,7 +26,7 @@
}
}
},
"packageManager": "pnpm@7.5.0",
"packageManager": "pnpm@7.33.3",
"scripts": {
"preinstall": "npx only-allow pnpm",
"dev": "pnpm -r --filter=./packages/** --parallel run dev",
Expand All @@ -34,7 +35,7 @@
"clean": "pnpm -r --filter=./packages/** run clean",
"format": "prettier --check \"packages/*/src/**/*.{ts,js,vue}\"",
"lint": "eslint \"packages/*/src/**/*.{ts,js}\"",
"publint": "pnpm -r --filter='vite-plugin-checker' exec publint",
"publint": "pnpm -r --filter './packages/**' --filter=!@vite-plugin-checker/runtime exec publint",
"test": "run-s test-unit test-serve test-build",
"test-unit": "vitest run",
"test-serve": "vitest run -c vitest.config.e2e.ts",
Expand All @@ -59,49 +60,51 @@
]
},
"devDependencies": {
"@changesets/cli": "^2.26.1",
"@tsconfig/esm": "^1.0.2",
"@tsconfig/node18": "^1.0.1",
"@tsconfig/strictest": "^2.0.0",
"@types/babel__code-frame": "^7.0.2",
"@types/debug": "^4.1.5",
"@types/fs-extra": "^11.0.1",
"@types/klaw": "^3.0.3",
"@types/minimist": "^1.2.2",
"@types/node": "^16.0.0",
"@types/prompts": "^2.0.13",
"@changesets/cli": "^2.27.1",
"@tsconfig/esm": "^1.0.5",
"@tsconfig/node18": "^18.2.2",
"@tsconfig/strictest": "^2.0.2",
"@types/babel__code-frame": "^7.0.6",
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.4",
"@types/klaw": "^3.0.6",
"@types/minimist": "^1.2.5",
"@types/node": "^18.0.0",
"@types/prompts": "^2.4.9",
"@types/rimraf": "^3.0.0",
"@types/semver": "^7.3.6",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@types/semver": "^7.5.6",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"chalk": "^4.1.1",
"cross-env": "^7.0.3",
"eslint": "^8.51.0",
"eslint-config-alloy": "^4.5.1",
"eslint": "^8.56.0",
"eslint-config-alloy": "^5.1.2",
"eslint-plugin-i": "^2.29.1",
"execa": "^5.1.1",
"fast-glob": "^3.2.7",
"fast-glob": "^3.3.2",
"fast-json-stable-stringify": "^2.1.0",
"fs-extra": "^11.1.0",
"fs-extra": "^11.2.0",
"jest-serializer-path": "^0.1.15",
"klaw": "^4.0.1",
"klaw": "^4.1.0",
"lint-staged": "^11.0.0",
"minimist": "^1.2.5",
"minimist": "^1.2.8",
"npm-run-all": "^4.1.5",
"playwright-chromium": "^1.24.0",
"prettier": "^2.3.2",
"playwright-chromium": "^1.41.1",
"prettier": "^3.2.4",
"prompts": "^2.4.1",
"publint": "^0.1.9",
"publint": "^0.2.7",
"rimraf": "^3.0.2",
"semver": "^7.5.0",
"simple-git-hooks": "^2.8.0",
"semver": "^7.5.4",
"simple-git-hooks": "^2.9.0",
"sort-deep-object-arrays": "^1.1.2",
"strip-ansi": "^7.0.0",
"tiny-invariant": "^1.1.0",
"strip-ansi": "^7.1.0",
"tiny-invariant": "^1.3.1",
"tsup": "^6.7.0",
"typescript": "^5.0.4",
"vite": "^4.3.0",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
"vitest": "^0.30.1",
"ws": "^8.5.0"
"vitest": "^1.2.2",
"ws": "^8.16.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`eslint logger > normalizeEslintDiagnostic > get multiple diagnostics 1`] = `
[
{
"checker": "ESLint",
"codeFrame": "   1 | import { text } from './text'
  2 |
> 3 | var hello = 'Hello'
  | ^^^^^^^^^^^^^^^^^^^
  4 | var hello1 = 'Hello1'
  5 |
  6 | const rootDom = document.querySelector('#root')!",
"conclusion": "",
"id": "/Users/vite-plugin-checker/playground/eslint/src/main.ts",
"level": 1,
"loc": {
"end": {
"column": 20,
"line": 3,
},
"start": {
"column": 1,
"line": 3,
},
},
"message": "Unexpected var, use let or const instead. (no-var)",
"stripedCodeFrame": " 1 | import { text } from './text'
2 |
> 3 | var hello = 'Hello'
| ^^^^^^^^^^^^^^^^^^^
4 | var hello1 = 'Hello1'
5 |
6 | const rootDom = document.querySelector('#root')!",
},
{
"checker": "ESLint",
"codeFrame": "   2 |
  3 | var hello = 'Hello'
> 4 | var hello1 = 'Hello1'
  | ^^^^^^^^^^^^^^^^^^^^^
  5 |
  6 | const rootDom = document.querySelector('#root')!
  7 | rootDom.innerHTML = hello + text",
"conclusion": "",
"id": "/Users/vite-plugin-checker/playground/eslint/src/main.ts",
"level": 1,
"loc": {
"end": {
"column": 22,
"line": 4,
},
"start": {
"column": 1,
"line": 4,
},
},
"message": "Unexpected var, use let or const instead. (no-var)",
"stripedCodeFrame": " 2 |
3 | var hello = 'Hello'
> 4 | var hello1 = 'Hello1'
| ^^^^^^^^^^^^^^^^^^^^^
5 |
6 | const rootDom = document.querySelector('#root')!
7 | rootDom.innerHTML = hello + text",
},
]
`;
55 changes: 55 additions & 0 deletions packages/checker-eslint/__tests__/fixtures/eslintDiagnostic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { NormalizedDiagnostic } from './../../src/logger'
import type { ESLint } from 'eslint'

export const error1: NormalizedDiagnostic = {
message: 'Unexpected var, use let or const instead.',
conclusion: '',
codeFrame:
" \u001b[0m \u001b[90m 1 |\u001b[39m \u001b[36mimport\u001b[39m { text } \u001b[36mfrom\u001b[39m \u001b[32m'./text'\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 2 |\u001b[39m\u001b[0m\n \u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 3 |\u001b[39m \u001b[36mvar\u001b[39m hello \u001b[33m=\u001b[39m \u001b[32m'Hello'\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m |\u001b[39m \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 4 |\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 5 |\u001b[39m \u001b[36mconst\u001b[39m rootDom \u001b[33m=\u001b[39m document\u001b[33m.\u001b[39mquerySelector(\u001b[32m'#root'\u001b[39m)\u001b[33m!\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 6 |\u001b[39m rootDom\u001b[33m.\u001b[39minnerHTML \u001b[33m=\u001b[39m hello \u001b[33m+\u001b[39m text\u001b[0m",
stripedCodeFrame:
" 1 | import { text } from './text'\n 2 |\n > 3 | var hello = 'Hello'\n | ^^^^^^^^^^^^^^^^^^^\n 4 |\n 5 | const rootDom = document.querySelector('#root')!\n 6 | rootDom.innerHTML = hello + text",
id: '/Users/vite-plugin-checker/playground/eslint/src/main.ts',
checker: 'ESLint',
loc: { start: { line: 3, column: 1 }, end: { line: 3, column: 20 } },
level: 1,
}

export const warning1: NormalizedDiagnostic = { ...error1, level: 0 }

export const eslintResult1: ESLint.LintResult = {
filePath: '/Users/vite-plugin-checker/playground/eslint/src/main.ts',
messages: [
{
ruleId: 'no-var',
severity: 2,
message: 'Unexpected var, use let or const instead.',
line: 3,
column: 1,
nodeType: 'VariableDeclaration',
messageId: 'unexpectedVar',
endLine: 3,
endColumn: 20,
fix: { range: [31, 34], text: 'let' },
},
{
ruleId: 'no-var',
severity: 2,
message: 'Unexpected var, use let or const instead.',
line: 4,
column: 1,
nodeType: 'VariableDeclaration',
messageId: 'unexpectedVar',
endLine: 4,
endColumn: 22,
fix: { range: [51, 54], text: 'let' },
},
],
errorCount: 2,
fatalErrorCount: 2,
warningCount: 0,
fixableErrorCount: 2,
fixableWarningCount: 0,
source:
"import { text } from './text'\n\nvar hello = 'Hello'\nvar hello1 = 'Hello1'\n\nconst rootDom = document.querySelector('#root')!\nrootDom.innerHTML = hello + text\n\nexport {}\n",
usedDeprecatedRules: [],
}
13 changes: 13 additions & 0 deletions packages/checker-eslint/__tests__/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest'

import { normalizeEslintDiagnostic } from '../src/logger.js'
import { eslintResult1 } from './fixtures/eslintDiagnostic.js'

describe('eslint logger', () => {
describe('normalizeEslintDiagnostic', () => {
it('get multiple diagnostics', () => {
const received = normalizeEslintDiagnostic(eslintResult1)
expect(received).toMatchSnapshot()
})
})
})
53 changes: 53 additions & 0 deletions packages/checker-eslint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@vite-plugin-checker/eslint",
"version": "0.0.1",
"private": true,
"description": "ESLint checker for vite-plugin-checker",
"types": "./dist/esm/main.d.ts",
"main": "./dist/cjs/main.js",
"type": "module",
"exports": {
".": {
"types": "./dist/esm/main.d.ts",
"import": "./dist/esm/main.js",
"default": "./dist/cjs/main.js"
}
},
"engines": {
"node": ">=14.16"
},
"files": [
"dist"
],
"scripts": {
"dev": "tsup --watch",
"clean": "rimraf dist",
"build": "tsup",
"build:test": "tsup --sourcemap inline"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fi3ework/vite-plugin-checker.git"
},
"keywords": [
"vite-plugin-checker"
],
"author": "fi3ework <fi3ework@gmail.com>",
"license": "MIT",
"bugs": "https://github.com/fi3ework/vite-plugin-checker/issues",
"homepage": "https://github.com/fi3ework/vite-plugin-checker",
"dependencies": {
"chokidar": "^3.5.1",
"optionator": "^0.9.1",
"tiny-invariant": "^1.3.1"
},
"peerDependencies": {
"eslint": "^8.51.0",
"vite-plugin-checker": ">= 0.7.0"
},
"devDependencies": {
"@types/eslint": "^8.44.0",
"eslint": "^8.51.0",
"vite-plugin-checker": "workspace:*"
}
}