@nabla/vite-plugin-eslint
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -7,4 +7,5 @@ import { ESLint } from "eslint"; | ||
shouldLint?: (path: string) => boolean; | ||
formatter?: string; | ||
}) => Plugin; | ||
export default eslintPlugin; |
33
index.js
@@ -8,6 +8,9 @@ const chalk = require("chalk"); | ||
eslintOptions = {}, | ||
shouldLint = (path) => path.match(/\.[jt]sx?$/), | ||
shouldLint = (path) => path.match(/\/src\/.*\.[jt]sx?$/), | ||
formatter: format, | ||
} = options; | ||
const eslint = new ESLint({ cache: true, ...eslintOptions }); | ||
const formatterPromise = format ? eslint.loadFormatter(format) : undefined; | ||
return { | ||
@@ -18,16 +21,22 @@ name: "eslint", | ||
const path = normalizePath(id); | ||
if (path.includes("/src/") && shouldLint(path)) { | ||
if (shouldLint(path)) { | ||
eslint.isPathIgnored(path).then(async (ignored) => { | ||
if (ignored) return; | ||
const [report] = await eslint.lintFiles(path); | ||
report.messages.forEach((m) => { | ||
const prettyPath = path.slice(path.indexOf("/src/") + 1); | ||
const location = `${prettyPath}(${m.line},${m.column})`; | ||
const rule = m.ruleId ? ` ${m.ruleId}` : ""; | ||
console.log( | ||
`${location}: ${chalk[m.severity === 2 ? "red" : "yellow"]( | ||
`${m.message}` | ||
)}${rule}` | ||
); | ||
}); | ||
if (report.messages.length === 0) return; | ||
if (formatterPromise) { | ||
const formatter = await formatterPromise; | ||
console.log(formatter.format([report])); | ||
} else { | ||
report.messages.forEach((m) => { | ||
const prettyPath = path.slice(path.indexOf("/src/") + 1); | ||
const location = `${prettyPath}(${m.line},${m.column})`; | ||
const rule = m.ruleId ? ` ${m.ruleId}` : ""; | ||
console.log( | ||
`${location}: ${chalk[m.severity === 2 ? "red" : "yellow"]( | ||
`${m.message}` | ||
)}${rule}` | ||
); | ||
}); | ||
} | ||
}); | ||
@@ -34,0 +43,0 @@ } |
{ | ||
"name": "@nabla/vite-plugin-eslint", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Plugs ESLint into Vite dev server", |
@@ -1,4 +0,4 @@ | ||
# @nabla/vite-plugin-eslint | ||
# @nabla/vite-plugin-eslint [![npm](https://img.shields.io/npm/v/@nabla/vite-plugin-eslint)](https://www.npmjs.com/package/@nabla/vite-plugin-eslint) | ||
Plugs ESLint into Vite dev server. | ||
Plugs ESLint into Vite dev server. | ||
@@ -39,2 +39,8 @@ ## Differences with [vite-plugin-eslint](https://github.com/gxmari007/vite-plugin-eslint) | ||
- Type: `(path: string) => boolean` | ||
- Default: `(path) => path.match(/\.[jt]sx?$/)` | ||
- Default: `(path) => path.match(/\/src\/.*\.[jt]sx?$/)` | ||
### formatter | ||
- Type: `string` | ||
If provided, the value is passed to `eslint.loadFormatter`. Default to a custom format with one line per warning/error. Use `stylish` to get a CRA like output. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65755
50
46