Socket
Socket
Sign inDemoInstall

eslint-loader

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-loader - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 1.5.0 - 2016-07-28
- Added: `cache` options
([#93](https://github.com/MoOx/eslint-loader/pull/93) - @genintho)
# 1.4.1 - 2016-06-07

@@ -2,0 +7,0 @@

61

index.js
var eslint = require("eslint")
var assign = require("object-assign")
var loaderUtils = require("loader-utils")
var crypto = require("crypto")
var fs = require("fs")
var findCacheDir = require("find-cache-dir")
var engine = null
var cache = null
var cachePath = null
/**

@@ -14,4 +21,2 @@ * linter

function lint(input, config, webpack) {
var engine = new eslint.CLIEngine(config)
var resourcePath = webpack.resourcePath

@@ -26,3 +31,26 @@ var cwd = process.cwd()

var res = engine.executeOnText(input, resourcePath, true)
var res
// If cache is enable and the data are the same as in the cache, just
// use them
if (config.cache) {
var inputMD5 = crypto.createHash("md5").update(input).digest("hex")
if (cache[resourcePath] && cache[resourcePath].hash === inputMD5) {
res = cache[resourcePath].res
}
}
// Re-lint the text if the cache off or miss
if (!res) {
res = engine.executeOnText(input, resourcePath, true)
// Save new results in the cache
if (config.cache) {
cache[resourcePath] = {
hash: inputMD5,
res: res,
}
fs.writeFileSync(cachePath, JSON.stringify(cache))
}
}
// executeOnText ensure we will have res.results[0] only

@@ -113,4 +141,31 @@

this.cacheable()
// Create the engine only once
if (engine === null) {
engine = new eslint.CLIEngine(config)
}
// Read the cached information only once and if enable
if (cache === null) {
if (config.cache) {
var thunk = findCacheDir({
name: "eslint-loader",
thunk: true,
create: true,
})
cachePath = thunk("data.json")
try {
cache = require(cachePath)
}
catch (e) {
cache = {}
}
}
else {
cache = false
}
}
lint(input, config, this)
this.callback(null, input, map)
}

3

package.json
{
"name": "eslint-loader",
"version": "1.4.1",
"version": "1.5.0",
"description": "eslint loader (for webpack)",

@@ -22,2 +22,3 @@ "keywords": [

"dependencies": {
"find-cache-dir": "^0.1.1",
"loader-utils": "^0.2.7",

@@ -24,0 +25,0 @@ "object-assign": "^4.0.1"

@@ -97,2 +97,10 @@ # eslint-loader [![Build Status](http://img.shields.io/travis/MoOx/eslint-loader.svg)](https://travis-ci.org/MoOx/eslint-loader)

#### `cache` (default: false)
This option will enable caching of the linting results into a file.
This is particullarly usefull to reduce linting time when doing full build.
The cache is writting inside the `./node_modules/.cache` directory, thanks to the usage
of the [find-cache-dir](https://www.npmjs.com/package/find-cache-dir) module.
#### `formatter` (default: eslint stylish formatter)

@@ -99,0 +107,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc