vite-plugin-eslint
Advanced tools
Comparing version 1.7.0 to 1.8.0
import { Plugin } from 'vite'; | ||
import { ESLint } from 'eslint'; | ||
import { FilterPattern } from '@rollup/pluginutils'; | ||
/** Plugin options, extending from ESlint options */ | ||
interface Options extends ESLint.Options { | ||
/** Path to ESLint instance that will be used for linting */ | ||
eslintPath?: string; | ||
/** Check all matching files on project startup */ | ||
lintOnStart?: boolean; | ||
/** A single file, or array of files, to include when linting */ | ||
include?: FilterPattern; | ||
include?: string | string[]; | ||
/** A single file, or array of files, to exclude when linting */ | ||
exclude?: FilterPattern; | ||
exclude?: string | string[]; | ||
/** Custom error formatter or the name of a built-in formatter */ | ||
@@ -21,12 +24,2 @@ formatter?: string | ESLint.Formatter['format']; | ||
failOnError?: boolean; | ||
/** | ||
* The warings found will be emitted | ||
* @deprecated | ||
*/ | ||
throwOnWarning?: boolean; | ||
/** | ||
* The errors found will be emitted | ||
* @deprecated | ||
*/ | ||
throwOnError?: boolean; | ||
} | ||
@@ -33,0 +26,0 @@ |
@@ -1,124 +0,1 @@ | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name2 in all) | ||
__defProp(target, name2, { get: all[name2], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
default: () => eslintPlugin | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var import_path = require("path"); | ||
var import_eslint = require("eslint"); | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
// package.json | ||
var name = "vite-plugin-eslint"; | ||
// src/utils.ts | ||
function parseRequest(id) { | ||
return id.split("?", 2)[0]; | ||
} | ||
function pickESLintOptions(options) { | ||
const { | ||
include, | ||
exclude, | ||
formatter, | ||
emitWarning, | ||
emitError, | ||
failOnWarning, | ||
failOnError, | ||
throwOnError, | ||
throwOnWarning, | ||
...eslintOptions | ||
} = options; | ||
return eslintOptions; | ||
} | ||
// src/index.ts | ||
function eslintPlugin(rawOptions = {}) { | ||
let eslint; | ||
let filter; | ||
let formatter; | ||
let options; | ||
const pathCache = /* @__PURE__ */ new Set(); | ||
return { | ||
name, | ||
async configResolved(config) { | ||
options = Object.assign({ | ||
include: /\.(jsx?|tsx?|vue|svelte)$/, | ||
exclude: /node_modules/, | ||
cacheLocation: (0, import_path.resolve)(config.cacheDir, ".eslintcache"), | ||
formatter: "stylish", | ||
emitWarning: true, | ||
emitError: true, | ||
failOnWarning: false, | ||
failOnError: true, | ||
throwOnWarning: false, | ||
throwOnError: false | ||
}, rawOptions); | ||
const eslintOptions = pickESLintOptions(options); | ||
filter = (0, import_pluginutils.createFilter)(options.include, options.exclude); | ||
eslint = new import_eslint.ESLint(eslintOptions); | ||
switch (typeof options.formatter) { | ||
case "string": | ||
formatter = (await eslint.loadFormatter(options.formatter)).format; | ||
break; | ||
case "function": | ||
formatter = options.formatter; | ||
default: | ||
break; | ||
} | ||
}, | ||
async transform(_, id) { | ||
const filePath = parseRequest(id); | ||
if (!filter(filePath) || await eslint.isPathIgnored(filePath)) { | ||
return null; | ||
} | ||
if (options.cache) { | ||
pathCache.add(filePath); | ||
} | ||
const report = await eslint.lintFiles(options.cache ? Array.from(pathCache) : filePath); | ||
const hasWarning = report.some((item) => item.warningCount > 0); | ||
const hasError = report.some((item) => item.errorCount > 0); | ||
const result = formatter(report); | ||
if (options.fix && report) { | ||
import_eslint.ESLint.outputFixes(report); | ||
} | ||
if (hasWarning && (options.emitWarning || options.throwOnWarning)) { | ||
const warning = typeof result === "string" ? result : await result; | ||
if (options.failOnWarning) { | ||
this.error(warning); | ||
} else { | ||
this.warn(warning); | ||
} | ||
} | ||
if (hasError && (options.emitError || options.throwOnError)) { | ||
const error = typeof result === "string" ? result : await result; | ||
if (options.failOnError) { | ||
this.error(error); | ||
} else { | ||
console.log(error); | ||
} | ||
} | ||
return null; | ||
} | ||
}; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = {}); | ||
"use strict";var m=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var F=(i,e)=>{for(var a in e)m(i,a,{get:e[a],enumerable:!0})},b=(i,e,a,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of L(e))!P.call(i,t)&&t!==a&&m(i,t,{get:()=>e[t],enumerable:!(n=w(e,t))||n.enumerable});return i};var j=i=>b(m({},"__esModule",{value:!0}),i);var R={};F(R,{default:()=>S});module.exports=j(R);var E=require("path"),v=require("@rollup/pluginutils");var g="vite-plugin-eslint";var h=require("fs");function y(i){return i.split("?",2)[0]}function O(i){return!(0,h.existsSync)(i)}function x(i){let{eslintPath:e,lintOnStart:a,include:n,exclude:t,formatter:c,emitWarning:u,emitError:l,failOnWarning:p,failOnError:o,...s}=i;return s}async function f(i){return i.then(e=>[null,e]).catch(e=>[e,void 0])}async function d(i,e,a,n,t,c){let[u,l]=await f(e.lintFiles(a));if(u)return Promise.reject(u);let p=l.some(r=>r.warningCount>0),o=l.some(r=>r.errorCount>0),s=t(l);if(n.fix&&l){let[r]=await f(c(l));if(r)return Promise.reject(r)}if(p&&n.emitWarning){let r=typeof s=="string"?s:await s;n.failOnWarning?i.error(r):i.warn(r)}if(o&&n.emitError){let r=typeof s=="string"?s:await s;n.failOnError?i.error(r):console.log(r)}return Promise.resolve()}function S(i={}){let e,a,n,t,c,u=new Set;return{name:g,async configResolved(l){t=Object.assign({lintOnStart:!1,include:["**/*.js","**/*.jsx","**/*.ts","**/*.tsx","**/*.vue","**/*.svelte"],exclude:["node_modules"],cacheLocation:(0,E.resolve)(l.cacheDir,".eslintcache"),formatter:"stylish",emitWarning:!0,emitError:!0,failOnWarning:!1,failOnError:!0,errorOnUnmatchedPattern:!1},i)},async buildStart(){let[l,p]=await f(import(t.eslintPath??"eslint"));if(l)this.error("Failed to import ESLint, do you install or configure eslintPath?");else{let o=x(t);switch(e=new p.ESLint(o),c=p.ESLint.outputFixes,a=(0,v.createFilter)(t.include,t.exclude),typeof t.formatter){case"string":n=(await e.loadFormatter(t.formatter)).format;break;case"function":n=t.formatter;default:break}if(t.lintOnStart&&t.include){this.warn("LintOnStart is turned on, and it will check for all matching files.");let[s]=await f(d(this,e,t.include,t,n,c));s&&this.error(s.message)}}},async transform(l,p){let o=y(p),s=O(o);if(s&&u.has(o)&&u.delete(o),!a(o)||await e.isPathIgnored(o)||s)return null;t.cache&&u.add(o);let[r]=await f(d(this,e,t.cache?Array.from(u):o,t,n,c));return r&&this.error(r.message),null}}}0&&(module.exports={}); |
{ | ||
"name": "vite-plugin-eslint", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "ESLint plugin for vite.", | ||
@@ -43,3 +43,3 @@ "author": "Xiang Gao", | ||
"@types/eslint": "^8.4.5", | ||
"rollup": "^2.77.0" | ||
"rollup": "^2.77.2" | ||
}, | ||
@@ -51,3 +51,3 @@ "devDependencies": { | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^8.20.0", | ||
"eslint": "^8.21.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
@@ -57,5 +57,5 @@ "eslint-plugin-prettier": "^4.2.1", | ||
"standard-version": "^9.5.0", | ||
"tsup": "^6.1.3", | ||
"tsup": "^6.2.1", | ||
"typescript": "^4.7.4", | ||
"vite": "^3.0.2" | ||
"vite": "^3.0.5" | ||
}, | ||
@@ -62,0 +62,0 @@ "peerDependencies": { |
@@ -47,5 +47,19 @@ # vite-plugin-eslint | ||
### `eslintPath` | ||
- Type: `string` | ||
- Default: `eslint` | ||
Path to `eslint` instance that will be used for linting. | ||
### `lintOnStart` | ||
- Type: `boolean` | ||
- Default: `false` | ||
Check all matching files on project startup, too slow, turn on discreetly. | ||
### `include` | ||
- Type: `string | RegExp | ReadonlyArray<string | RegExp>` | ||
- Type: `string | string[]` | ||
- Default: `/\.(jsx?|tsx?|vue|svelte)$/` | ||
@@ -57,4 +71,4 @@ | ||
- Type: `string | RegExp | ReadonlyArray<string | RegExp>` | ||
- Default: `/node_modules/` | ||
- Type: `string | string[]` | ||
- Default: `[node_modules]` | ||
@@ -98,20 +112,4 @@ A single file, or array of files, to exclude when linting. | ||
### `throwOnWarning` | ||
- Type: `boolean` | ||
- Default: `false` | ||
- Deprecated: use `emitWarning` | ||
The warings found will be emitted. | ||
### `throwOnError` | ||
- Type: `boolean` | ||
- Default: `false` | ||
- Deprecated: use `emitError` | ||
The errors found will be emitted. | ||
## License | ||
MIT |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
10620
43
1
113
3
1
Updatedrollup@^2.77.2